mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-20 01:30:07 -07:00
parent
98ff16df38
commit
7523cec0ce
15
README.md
15
README.md
@ -29,6 +29,15 @@ Swap language.
|
||||
`<C-q>`
|
||||
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>`
|
||||
Play sound on left window.
|
||||
|
||||
@ -47,6 +56,12 @@ Cycle through the pop out widget.
|
||||
`<1>`, `<2>`, `<3>`
|
||||
Switch pop out window.
|
||||
|
||||
## Dependencies
|
||||
|
||||
`xclip` For Linux to copy text.
|
||||
|
||||
`pbcopy` For macOS to copy text.
|
||||
|
||||
## Credit
|
||||
|
||||
[snsd0805/GoogleTranslate-TUI](https://github.com/snsd0805/GoogleTranslate-TUI) For inspiration.
|
||||
|
30
ui.go
30
ui.go
@ -20,6 +20,12 @@ const (
|
||||
Swap language.
|
||||
[#%[1]s]<C-q>[-]
|
||||
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>[-]
|
||||
Play sound on left window.
|
||||
[#%[1]s]<C-p>[-]
|
||||
@ -370,6 +376,30 @@ func translatePageHandler(event *tcell.EventKey) *tcell.EventKey {
|
||||
}
|
||||
case tcell.KeyCtrlQ:
|
||||
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:
|
||||
translator.SrcLang, translator.DstLang = translator.DstLang, translator.SrcLang
|
||||
updateTitle()
|
||||
|
19
utils.go
19
utils.go
@ -1,5 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func IndexOf(candidate string, arr []string) int {
|
||||
for index, element := range arr {
|
||||
if element == candidate {
|
||||
@ -12,3 +18,16 @@ func IndexOf(candidate string, arr []string) int {
|
||||
func SetTermTitle(title string) {
|
||||
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