mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-20 09:30:21 -07:00
parent
98ff16df38
commit
7523cec0ce
15
README.md
15
README.md
@ -29,6 +29,15 @@ Swap language.
|
|||||||
`<C-q>`
|
`<C-q>`
|
||||||
Clear all text in left window.
|
Clear all text in left window.
|
||||||
|
|
||||||
|
`<C-y>`
|
||||||
|
Copy selected text in left window.
|
||||||
|
|
||||||
|
`<C-g>`
|
||||||
|
Copy all text in left window.
|
||||||
|
|
||||||
|
`<C-r>`
|
||||||
|
Copy all text in right window.
|
||||||
|
|
||||||
`<C-o>`
|
`<C-o>`
|
||||||
Play sound on left window.
|
Play sound on left window.
|
||||||
|
|
||||||
@ -47,6 +56,12 @@ Cycle through the pop out widget.
|
|||||||
`<1>`, `<2>`, `<3>`
|
`<1>`, `<2>`, `<3>`
|
||||||
Switch pop out window.
|
Switch pop out window.
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
`xclip` For Linux to copy text.
|
||||||
|
|
||||||
|
`pbcopy` For macOS to copy text.
|
||||||
|
|
||||||
## Credit
|
## Credit
|
||||||
|
|
||||||
[snsd0805/GoogleTranslate-TUI](https://github.com/snsd0805/GoogleTranslate-TUI) For inspiration.
|
[snsd0805/GoogleTranslate-TUI](https://github.com/snsd0805/GoogleTranslate-TUI) For inspiration.
|
||||||
|
30
ui.go
30
ui.go
@ -20,6 +20,12 @@ const (
|
|||||||
Swap language.
|
Swap language.
|
||||||
[#%[1]s]<C-q>[-]
|
[#%[1]s]<C-q>[-]
|
||||||
Clear all text in left window.
|
Clear all text in left window.
|
||||||
|
[#%[1]s]<C-y>[-]
|
||||||
|
Copy selected text in left window.
|
||||||
|
[#%[1]s]<C-g>[-]
|
||||||
|
Copy all text in left window.
|
||||||
|
[#%[1]s]<C-r>[-]
|
||||||
|
Copy all text in right window.
|
||||||
[#%[1]s]<C-o>[-]
|
[#%[1]s]<C-o>[-]
|
||||||
Play sound on left window.
|
Play sound on left window.
|
||||||
[#%[1]s]<C-p>[-]
|
[#%[1]s]<C-p>[-]
|
||||||
@ -370,6 +376,30 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
}
|
}
|
||||||
case tcell.KeyCtrlQ:
|
case tcell.KeyCtrlQ:
|
||||||
srcInput.SetText("", true)
|
srcInput.SetText("", true)
|
||||||
|
case tcell.KeyCtrlY:
|
||||||
|
// copy selected text
|
||||||
|
text, _, _ := srcInput.GetSelection()
|
||||||
|
|
||||||
|
// only copy when text selected
|
||||||
|
if len(text) > 0 {
|
||||||
|
CopyToClipboard(text)
|
||||||
|
}
|
||||||
|
case tcell.KeyCtrlG:
|
||||||
|
// copy all text in Input
|
||||||
|
text := srcInput.GetText()
|
||||||
|
|
||||||
|
// only copy when text exist
|
||||||
|
if len(text) > 0 {
|
||||||
|
CopyToClipboard(text)
|
||||||
|
}
|
||||||
|
case tcell.KeyCtrlR:
|
||||||
|
// copy all text in Output
|
||||||
|
text := dstOutput.GetText(false)
|
||||||
|
|
||||||
|
// only copy when text exist
|
||||||
|
if len(text) > 0 {
|
||||||
|
CopyToClipboard(text[:len(text)-1])
|
||||||
|
}
|
||||||
case tcell.KeyCtrlS:
|
case tcell.KeyCtrlS:
|
||||||
translator.SrcLang, translator.DstLang = translator.DstLang, translator.SrcLang
|
translator.SrcLang, translator.DstLang = translator.DstLang, translator.SrcLang
|
||||||
updateTitle()
|
updateTitle()
|
||||||
|
19
utils.go
19
utils.go
@ -1,5 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
func IndexOf(candidate string, arr []string) int {
|
func IndexOf(candidate string, arr []string) int {
|
||||||
for index, element := range arr {
|
for index, element := range arr {
|
||||||
if element == candidate {
|
if element == candidate {
|
||||||
@ -12,3 +18,16 @@ func IndexOf(candidate string, arr []string) int {
|
|||||||
func SetTermTitle(title string) {
|
func SetTermTitle(title string) {
|
||||||
print("\033]0;", title, "\007")
|
print("\033]0;", title, "\007")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyToClipboard(text string) {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
exec.Command("sh", "-c",
|
||||||
|
fmt.Sprintf("echo -n '%s' | xclip -selection clipboard", text)).
|
||||||
|
Start()
|
||||||
|
case "darwin":
|
||||||
|
exec.Command("sh", "-c",
|
||||||
|
fmt.Sprintf("echo -n '%s' | pbcopy", text)).
|
||||||
|
Start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user