From 14a5059ca1dd78ea6e9f7a8454631dc3fa139411 Mon Sep 17 00:00:00 2001 From: Mateusz Drewniak Date: Wed, 12 Jul 2023 10:14:56 +0200 Subject: [PATCH] Change KeyBindMode to a numeric type --- key_bind.go | 6 +++--- prompt.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/key_bind.go b/key_bind.go index 42669e7f..0332e27d 100644 --- a/key_bind.go +++ b/key_bind.go @@ -16,13 +16,13 @@ type ASCIICodeBind struct { } // KeyBindMode to switch a key binding flexibly. -type KeyBindMode string +type KeyBindMode uint8 const ( // CommonKeyBind is a mode without any keyboard shortcut - CommonKeyBind KeyBindMode = "common" + CommonKeyBind KeyBindMode = iota // EmacsKeyBind is a mode to use emacs-like keyboard shortcut - EmacsKeyBind KeyBindMode = "emacs" + EmacsKeyBind ) var commonKeyBindings = []KeyBind{ diff --git a/prompt.go b/prompt.go index 31a76ea8..5d6d50c8 100644 --- a/prompt.go +++ b/prompt.go @@ -247,7 +247,8 @@ func (p *Prompt) handleKeyBinding(key Key) bool { } } - if p.keyBindMode == EmacsKeyBind { + switch p.keyBindMode { + case EmacsKeyBind: for i := range emacsKeyBindings { kb := emacsKeyBindings[i] if kb.Key == key {