mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-19 01:00:20 -07:00
feat: support function key
This commit is contained in:
parent
7fae960ce2
commit
91ee46933a
@ -1,44 +1,63 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type keyData struct {
|
||||
ch rune
|
||||
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 {
|
||||
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
|
||||
key = tcell.KeyCtrlA + tcell.Key(ch-'a')
|
||||
name = "C-" + chStr
|
||||
key = tcell.KeyCtrlA + tcell.Key(chStr[0]-'a')
|
||||
}
|
||||
}
|
||||
|
||||
return keyData{
|
||||
ch: ch,
|
||||
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 {
|
||||
|
22
ui.go
22
ui.go
@ -17,27 +17,27 @@ const (
|
||||
Exit program.
|
||||
[#%[1]s]<Esc>[-]
|
||||
Toggle pop out window.
|
||||
[#%[1]s]<C-%[2]c>[-]
|
||||
[#%[1]s]<%[2]s>[-]
|
||||
Translate from source to destination window.
|
||||
[#%[1]s]<C-%[3]c>[-]
|
||||
[#%[1]s]<%[3]s>[-]
|
||||
Swap language.
|
||||
[#%[1]s]<C-%[4]c>[-]
|
||||
[#%[1]s]<%[4]s>[-]
|
||||
Clear all text in source of translation window.
|
||||
[#%[1]s]<C-%[5]c>[-]
|
||||
[#%[1]s]<%[5]s>[-]
|
||||
Copy selected text.
|
||||
[#%[1]s]<C-%[6]c>[-]
|
||||
[#%[1]s]<%[6]s>[-]
|
||||
Copy all text in source of translation window.
|
||||
[#%[1]s]<C-%[7]c>[-]
|
||||
[#%[1]s]<%[7]s>[-]
|
||||
Copy all text in destination of translation window.
|
||||
[#%[1]s]<C-%[8]c>[-]
|
||||
[#%[1]s]<%[8]s>[-]
|
||||
Play text to speech on source of translation window.
|
||||
[#%[1]s]<C-%[9]c>[-]
|
||||
[#%[1]s]<%[9]s>[-]
|
||||
Play text to speech on destination of translation window.
|
||||
[#%[1]s]<C-%[10]c>[-]
|
||||
[#%[1]s]<%[10]s>[-]
|
||||
Stop playing text to speech.
|
||||
[#%[1]s]<C-%[11]c>[-]
|
||||
[#%[1]s]<%[11]s>[-]
|
||||
Toggle transparent.
|
||||
[#%[1]s]<C-%[12]c>[-]
|
||||
[#%[1]s]<%[12]s>[-]
|
||||
Toggle Definition/Example & Part of speech.
|
||||
[#%[1]s]<Tab>, <S-Tab>[-]
|
||||
Cycle through the pop out widget.
|
||||
|
Loading…
x
Reference in New Issue
Block a user