v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 00:00:16 -07:00
GTT/internal/ui/key.go
2023-06-18 23:16:08 +08:00

47 lines
669 B
Go

package ui
import (
"github.com/gdamore/tcell/v2"
)
type keyData struct {
ch rune
key tcell.Key
}
type KeyMaps map[string]keyData
func NewKeyData(chStr string) keyData {
var key tcell.Key
ch := rune(chStr[0])
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')
}
return keyData{
ch: ch,
key: key,
}
}
func (k keyData) GetName() rune {
return k.ch
}
func (k keyData) GetKey() tcell.Key {
return k.key
}