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