diff --git a/internal/ui/key.go b/internal/ui/key.go index 154297c..608362a 100644 --- a/internal/ui/key.go +++ b/internal/ui/key.go @@ -1,44 +1,63 @@ package ui import ( + "strconv" + "github.com/gdamore/tcell/v2" ) type keyData struct { - ch rune - key tcell.Key + name string + key tcell.Key } type KeyMaps map[string]keyData func NewKeyData(chStr string) keyData { - var key tcell.Key - ch := rune(chStr[0]) + var ( + name string + key tcell.Key + ) - switch ch { - case ' ': - key = tcell.KeyCtrlSpace - case '\\': - key = tcell.KeyCtrlBackslash - case ']': - key = tcell.KeyCtrlRightSq - case '^': - key = tcell.KeyCtrlCarat - case '_': - key = tcell.KeyCtrlUnderscore - default: - // This should be a to z - key = tcell.KeyCtrlA + tcell.Key(ch-'a') + if len(chStr) > 1 && chStr[0] == 'F' { + name = chStr + fNum, err := strconv.Atoi(chStr[1:]) + if err != nil { + panic(err) + } + key = tcell.KeyF1 + tcell.Key(fNum-1) + } else { + switch chStr[0] { + case ' ': + name = "C-Space" + key = tcell.KeyCtrlSpace + case '\\': + name = "C-\\" + key = tcell.KeyCtrlBackslash + case ']': + name = "C-]" + key = tcell.KeyCtrlRightSq + case '^': + name = "C-^" + key = tcell.KeyCtrlCarat + case '_': + name = "C-_" + key = tcell.KeyCtrlUnderscore + default: + // This should be a to z + name = "C-" + chStr + key = tcell.KeyCtrlA + tcell.Key(chStr[0]-'a') + } } return keyData{ - ch: ch, - key: key, + name: name, + key: key, } } -func (k keyData) GetName() rune { - return k.ch +func (k keyData) GetName() string { + return k.name } func (k keyData) GetKey() tcell.Key { diff --git a/ui.go b/ui.go index fc51d31..5b4bfa0 100644 --- a/ui.go +++ b/ui.go @@ -17,27 +17,27 @@ const ( Exit program. [#%[1]s][-] Toggle pop out window. -[#%[1]s][-] +[#%[1]s]<%[2]s>[-] Translate from source to destination window. -[#%[1]s][-] +[#%[1]s]<%[3]s>[-] Swap language. -[#%[1]s][-] +[#%[1]s]<%[4]s>[-] Clear all text in source of translation window. -[#%[1]s][-] +[#%[1]s]<%[5]s>[-] Copy selected text. -[#%[1]s][-] +[#%[1]s]<%[6]s>[-] Copy all text in source of translation window. -[#%[1]s][-] +[#%[1]s]<%[7]s>[-] Copy all text in destination of translation window. -[#%[1]s][-] +[#%[1]s]<%[8]s>[-] Play text to speech on source of translation window. -[#%[1]s][-] +[#%[1]s]<%[9]s>[-] Play text to speech on destination of translation window. -[#%[1]s][-] +[#%[1]s]<%[10]s>[-] Stop playing text to speech. -[#%[1]s][-] +[#%[1]s]<%[11]s>[-] Toggle transparent. -[#%[1]s][-] +[#%[1]s]<%[12]s>[-] Toggle Definition/Example & Part of speech. [#%[1]s], [-] Cycle through the pop out widget.