v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-16 07:40:44 -07:00

feat: let exit be configurable

This commit is contained in:
eeeXun 2023-06-24 10:57:11 +08:00
parent 7109c19814
commit c20c8b67db
4 changed files with 14 additions and 5 deletions

View File

@ -163,6 +163,7 @@ Switch pop out window.
You can overwrite the following key
- `exit`: Exit program.
- `translate`: Translate from source to destination window.
- `swap_language`: Swap language.
- `clear`: Clear all text in source of translation window.
@ -177,8 +178,6 @@ You can overwrite the following key
For key to combine with `Ctrl`, the value can be `"C-space"`, `"C-\\"`, `"C-]"`, `"C-^"`, `"C-_"` or `"C-a"` to `"C-z"`.
⚠️ Note, don't use `"C-c"`, `<C-c>` is for exit program.
For key to combine with `Alt`, the value can be `"A-space"` or `"A-"` + the character you want.
Or you can use function key, the value can be `"F1"` to `"F64"`.

View File

@ -16,6 +16,7 @@ func configInit() {
themeConfig = config.New()
keyMapConfig = config.New()
defaultKeyMaps = map[string]string{
"exit": "C-c",
"translate": "C-j",
"swap_language": "C-s",
"clear": "C-q",

View File

@ -1,7 +1,6 @@
# This file should be located at $XDG_CONFIG_HOME/gtt/keymap.yaml or $HOME/.config/gtt/keymap.yaml.
# For key to combine with Ctrl, the value can be "C-space", "C-\\", "C-]", "C-^", "C-_" or "C-a" to "C-z".
# ⚠️ Note, don't use "C-c", <C-c> is for exit program.
# For key to combine with Alt, the value can be "A-space" or "A-" + the character you want.
@ -10,6 +9,8 @@
# The following is the default key map
# Exit program, <C-c>
exit: "C-c"
# Translate from source to destination window, <C-j>
translate: "C-j"
# Swap language, <C-s>

12
ui.go
View File

@ -366,7 +366,7 @@ func uiInit() {
updateCurrentLang()
// handler
mainPage.SetInputCapture(mainPageHandler)
app.SetInputCapture(appHandler)
translateWindow.SetInputCapture(translateWindowHandler)
for _, widget := range []*tview.TextArea{srcInput, defOutput, posOutput} {
// fix for loop problem
@ -441,7 +441,7 @@ func uiInit() {
keyMapButton.SetSelectedFunc(showKeyMapPopout)
}
func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
func appHandler(event *tcell.EventKey) *tcell.EventKey {
keyName := getKeyName(event)
if len(keyName) == 0 {
@ -449,6 +449,9 @@ func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
}
switch keyName {
case keyMaps["exit"]:
app.Stop()
return nil
case keyMaps["toggle_transparent"]:
// Toggle transparent
uiStyle.Transparent = !uiStyle.Transparent
@ -467,6 +470,11 @@ func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
return nil
}
// Force C-c not to exit program
if event.Key() == tcell.KeyCtrlC {
return tcell.NewEventKey(tcell.KeyCtrlC, 0, tcell.ModNone)
}
return event
}