mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-15 15:20:37 -07:00
feat: support OSC 52 (#32)
* feat: support OSC 52 * docs: note for OSC 52
This commit is contained in:
parent
06dafb5bf8
commit
f87b7b43ec
@ -64,6 +64,8 @@ For RedHat-based Linux, you need `alsa-lib-devel`.
|
||||
|
||||
[`wl-clipboard`](https://github.com/bugaevc/wl-clipboard) (optional) - for Linux/Wayland to copy text.
|
||||
|
||||
Or, if your terminal supports OSC 52, you can enable OSC 52 in page 2 of the pop out menu to copy text.
|
||||
|
||||
### Arch Linux ([AUR](https://aur.archlinux.org/packages/gtt-bin))
|
||||
|
||||
```sh
|
||||
@ -120,7 +122,7 @@ docker run -it eeexun/gtt:latest
|
||||
Exit program.
|
||||
|
||||
`<Esc>`
|
||||
Toggle pop out window.
|
||||
Toggle pop out menu.
|
||||
|
||||
`<C-j>`
|
||||
Translate from source to destination window.
|
||||
@ -159,7 +161,7 @@ Toggle Definition/Example & Part of speech.
|
||||
Cycle through the pop out widget.
|
||||
|
||||
`<1>`, `<2>`, `<3>`
|
||||
Switch pop out window.
|
||||
Switch pop out menu.
|
||||
|
||||
### Customize key map
|
||||
|
||||
|
14
config.go
14
config.go
@ -37,6 +37,7 @@ func configInit() {
|
||||
"toggle_below": "C-\\",
|
||||
}
|
||||
defaultConfig = map[string]interface{}{
|
||||
"osc52": false,
|
||||
"hide_below": false,
|
||||
"transparent": false,
|
||||
"theme": "gruvbox",
|
||||
@ -153,6 +154,7 @@ func configInit() {
|
||||
}
|
||||
translator = translators[config.GetString("translator")]
|
||||
uiStyle.Theme = config.GetString("theme")
|
||||
uiStyle.OSC52 = config.GetBool("osc52")
|
||||
uiStyle.HideBelow = config.GetBool("hide_below")
|
||||
uiStyle.Transparent = config.GetBool("transparent")
|
||||
uiStyle.SetSrcBorderColor(config.GetString("source.border_color")).
|
||||
@ -211,10 +213,6 @@ func updateConfig() {
|
||||
changed = true
|
||||
config.Set("translator", translator.GetEngineName())
|
||||
}
|
||||
if config.GetBool("hide_below") != uiStyle.HideBelow {
|
||||
changed = true
|
||||
config.Set("hide_below", uiStyle.HideBelow)
|
||||
}
|
||||
if config.GetString("theme") != uiStyle.Theme {
|
||||
changed = true
|
||||
config.Set("theme", uiStyle.Theme)
|
||||
@ -223,6 +221,14 @@ func updateConfig() {
|
||||
changed = true
|
||||
config.Set("transparent", uiStyle.Transparent)
|
||||
}
|
||||
if config.GetBool("hide_below") != uiStyle.HideBelow {
|
||||
changed = true
|
||||
config.Set("hide_below", uiStyle.HideBelow)
|
||||
}
|
||||
if config.GetBool("osc52") != uiStyle.OSC52 {
|
||||
changed = true
|
||||
config.Set("osc52", uiStyle.OSC52)
|
||||
}
|
||||
if config.GetString("source.border_color") != uiStyle.SrcBorderStr() {
|
||||
changed = true
|
||||
config.Set("source.border_color", uiStyle.SrcBorderStr())
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
type style struct {
|
||||
OSC52 bool
|
||||
HideBelow bool
|
||||
Transparent bool
|
||||
Theme string
|
||||
|
2
main.go
2
main.go
@ -35,12 +35,14 @@ var (
|
||||
themeDropDown = tview.NewDropDown()
|
||||
transparentDropDown = tview.NewDropDown()
|
||||
hideBelowDropDown = tview.NewDropDown()
|
||||
osc52DropDown = tview.NewDropDown()
|
||||
srcBorderDropDown = tview.NewDropDown()
|
||||
dstBorderDropDown = tview.NewDropDown()
|
||||
styleCycle = ui.NewUICycle(
|
||||
themeDropDown,
|
||||
transparentDropDown,
|
||||
hideBelowDropDown,
|
||||
osc52DropDown,
|
||||
srcBorderDropDown,
|
||||
dstBorderDropDown)
|
||||
keyMapMenu = tview.NewTextView()
|
||||
|
32
ui.go
32
ui.go
@ -18,12 +18,12 @@ type Item struct {
|
||||
}
|
||||
|
||||
const (
|
||||
popOutWindowHeight int = 20
|
||||
popOutMenuHeight int = 20
|
||||
langStrMaxLength int = 32
|
||||
keyMapText string = `[#%[1]s]<C-c>[-]
|
||||
Exit program.
|
||||
[#%[1]s]<Esc>[-]
|
||||
Toggle pop out window.
|
||||
Toggle pop out menu.
|
||||
[#%[1]s]<%[2]s>[-]
|
||||
Translate from source to destination window.
|
||||
[#%[1]s]<%[3]s>[-]
|
||||
@ -49,7 +49,7 @@ const (
|
||||
[#%[1]s]<Tab>, <S-Tab>[-]
|
||||
Cycle through the pop out widget.
|
||||
[#%[1]s]<1>, <2>, <3>[-]
|
||||
Switch pop out window.`
|
||||
Switch pop out menu.`
|
||||
)
|
||||
|
||||
func updateTranslateWindow() {
|
||||
@ -84,6 +84,7 @@ func updateBackgroundColor() {
|
||||
themeDropDown,
|
||||
transparentDropDown,
|
||||
hideBelowDropDown,
|
||||
osc52DropDown,
|
||||
srcBorderDropDown,
|
||||
dstBorderDropDown} {
|
||||
dropdown.SetListStyles(tcell.StyleDefault.
|
||||
@ -145,6 +146,7 @@ func updateNonConfigColor() {
|
||||
themeDropDown,
|
||||
transparentDropDown,
|
||||
hideBelowDropDown,
|
||||
osc52DropDown,
|
||||
srcBorderDropDown,
|
||||
dstBorderDropDown} {
|
||||
labelDropDown.SetLabelColor(uiStyle.LabelColor()).
|
||||
@ -286,15 +288,20 @@ func uiInit() {
|
||||
themeDropDown.SetLabel("Theme: ").
|
||||
SetOptions(style.AllTheme, nil).
|
||||
SetCurrentOption(IndexOf(uiStyle.Theme, style.AllTheme))
|
||||
transparentDropDown.SetLabel("Transparent: ").
|
||||
SetOptions([]string{"true", "false"}, nil).
|
||||
SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(uiStyle.Transparent),
|
||||
[]string{"true", "false"}))
|
||||
hideBelowDropDown.SetLabel("Hide below: ").
|
||||
SetOptions([]string{"true", "false"}, nil).
|
||||
SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(uiStyle.HideBelow),
|
||||
[]string{"true", "false"}))
|
||||
transparentDropDown.SetLabel("Transparent: ").
|
||||
osc52DropDown.SetLabel("OSC 52: ").
|
||||
SetOptions([]string{"true", "false"}, nil).
|
||||
SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(uiStyle.Transparent),
|
||||
IndexOf(strconv.FormatBool(uiStyle.OSC52),
|
||||
[]string{"true", "false"}))
|
||||
srcBorderDropDown.SetLabel("Border Color: ").
|
||||
SetOptions(style.Palette, nil).
|
||||
@ -340,7 +347,7 @@ func uiInit() {
|
||||
Item{item: dstLangDropDown, fixedSize: 0, proportion: 1, focus: false}),
|
||||
fixedSize: 0, proportion: 1, focus: true}),
|
||||
fixedSize: 2 * langStrMaxLength, proportion: 1, focus: true}),
|
||||
popOutWindowHeight, 1, true).
|
||||
popOutMenuHeight, 1, true).
|
||||
AddItem(attachButton(), 1, 1, false).
|
||||
AddItem(nil, 0, 1, false)
|
||||
stylePopOut.SetDirection(tview.FlexRow).
|
||||
@ -351,22 +358,23 @@ func uiInit() {
|
||||
Item{item: attachItems(false, tview.FlexRow,
|
||||
Item{item: themeDropDown, fixedSize: 0, proportion: 1, focus: true},
|
||||
Item{item: transparentDropDown, fixedSize: 0, proportion: 1, focus: false},
|
||||
Item{item: hideBelowDropDown, fixedSize: 0, proportion: 1, focus: false}),
|
||||
Item{item: hideBelowDropDown, fixedSize: 0, proportion: 1, focus: false},
|
||||
Item{item: osc52DropDown, fixedSize: 0, proportion: 1, focus: false}),
|
||||
fixedSize: 0, proportion: 1, focus: true}),
|
||||
fixedSize: 3, proportion: 1, focus: true},
|
||||
fixedSize: 4, proportion: 1, focus: true},
|
||||
Item{item: attachItems(false, tview.FlexColumn,
|
||||
Item{item: srcBorderDropDown, fixedSize: 0, proportion: 1, focus: false},
|
||||
Item{item: dstBorderDropDown, fixedSize: 0, proportion: 1, focus: false}),
|
||||
fixedSize: 0, proportion: 1, focus: false}),
|
||||
fixedSize: 2 * langStrMaxLength, proportion: 1, focus: true}),
|
||||
popOutWindowHeight, 1, true).
|
||||
popOutMenuHeight, 1, true).
|
||||
AddItem(attachButton(), 1, 1, false).
|
||||
AddItem(nil, 0, 1, false)
|
||||
keyMapPopOut.SetDirection(tview.FlexRow).
|
||||
AddItem(nil, 0, 1, false).
|
||||
AddItem(attachItems(true, tview.FlexColumn,
|
||||
Item{item: keyMapMenu, fixedSize: 2 * langStrMaxLength, proportion: 1, focus: true}),
|
||||
popOutWindowHeight, 1, true).
|
||||
popOutMenuHeight, 1, true).
|
||||
AddItem(attachButton(), 1, 1, false).
|
||||
AddItem(nil, 0, 1, false)
|
||||
|
||||
@ -429,6 +437,10 @@ func uiInit() {
|
||||
uiStyle.HideBelow, _ = strconv.ParseBool(text)
|
||||
updateTranslateWindow()
|
||||
})
|
||||
osc52DropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(func(text string, index int) {
|
||||
uiStyle.OSC52, _ = strconv.ParseBool(text)
|
||||
})
|
||||
srcBorderDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(func(text string, index int) {
|
||||
uiStyle.SetSrcBorderColor(text)
|
||||
|
6
utils.go
6
utils.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -22,6 +23,11 @@ func SetTermTitle(name string) {
|
||||
}
|
||||
|
||||
func CopyToClipboard(text string) {
|
||||
if uiStyle.OSC52 {
|
||||
fmt.Printf("\033]52;c;%s\a", base64.StdEncoding.EncodeToString([]byte(text)))
|
||||
return
|
||||
}
|
||||
|
||||
var cmd *exec.Cmd
|
||||
|
||||
switch runtime.GOOS {
|
||||
|
Loading…
x
Reference in New Issue
Block a user