mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-21 10:00:59 -07:00
feat: toggle below
This commit is contained in:
parent
40179f17e2
commit
90f77ecc65
@ -60,6 +60,9 @@ Stop play sound.
|
|||||||
`<C-t>`
|
`<C-t>`
|
||||||
Toggle transparent.
|
Toggle transparent.
|
||||||
|
|
||||||
|
`<C-\>`
|
||||||
|
Toggle definition & Part of speech
|
||||||
|
|
||||||
`<Tab>`, `<S-Tab>`
|
`<Tab>`, `<S-Tab>`
|
||||||
Cycle through the pop out widget.
|
Cycle through the pop out widget.
|
||||||
|
|
||||||
|
14
config.go
14
config.go
@ -2,12 +2,20 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"gtt/internal/color"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// argument
|
||||||
srcLangArg *string = flag.String("src", "", "Source Language")
|
srcLangArg *string = flag.String("src", "", "Source Language")
|
||||||
dstLangArg *string = flag.String("dst", "", "Destination Language")
|
dstLangArg *string = flag.String("dst", "", "Destination Language")
|
||||||
|
// settings
|
||||||
|
config = viper.New()
|
||||||
|
style = color.NewStyle()
|
||||||
|
hideBelow bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// Search XDG_CONFIG_HOME or $HOME/.config
|
// Search XDG_CONFIG_HOME or $HOME/.config
|
||||||
@ -32,6 +40,7 @@ func configInit() {
|
|||||||
config.Set("source.borderColor", "red")
|
config.Set("source.borderColor", "red")
|
||||||
config.Set("destination.language", "Chinese (Traditional)")
|
config.Set("destination.language", "Chinese (Traditional)")
|
||||||
config.Set("destination.borderColor", "blue")
|
config.Set("destination.borderColor", "blue")
|
||||||
|
config.Set("hide_below", false)
|
||||||
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(defaultConfigPath, os.ModePerm)
|
os.MkdirAll(defaultConfigPath, os.ModePerm)
|
||||||
}
|
}
|
||||||
@ -50,6 +59,7 @@ func configInit() {
|
|||||||
} else {
|
} else {
|
||||||
translator.DstLang = config.GetString("destination.language")
|
translator.DstLang = config.GetString("destination.language")
|
||||||
}
|
}
|
||||||
|
hideBelow = config.GetBool("hide_below")
|
||||||
style.Theme = config.GetString("theme")
|
style.Theme = config.GetString("theme")
|
||||||
style.Transparent = config.GetBool("transparent")
|
style.Transparent = config.GetBool("transparent")
|
||||||
style.SetSrcBorderColor(config.GetString("source.borderColor")).
|
style.SetSrcBorderColor(config.GetString("source.borderColor")).
|
||||||
@ -72,6 +82,10 @@ func updateConfig() {
|
|||||||
changed = true
|
changed = true
|
||||||
config.Set("destination.language", translator.DstLang)
|
config.Set("destination.language", translator.DstLang)
|
||||||
}
|
}
|
||||||
|
if config.GetBool("hide_below") != hideBelow {
|
||||||
|
changed = true
|
||||||
|
config.Set("hide_below", hideBelow)
|
||||||
|
}
|
||||||
if config.GetString("theme") != style.Theme {
|
if config.GetString("theme") != style.Theme {
|
||||||
changed = true
|
changed = true
|
||||||
config.Set("theme", style.Theme)
|
config.Set("theme", style.Theme)
|
||||||
|
51
main.go
51
main.go
@ -1,43 +1,40 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gtt/internal/color"
|
|
||||||
"gtt/internal/translate"
|
"gtt/internal/translate"
|
||||||
"gtt/internal/ui"
|
"gtt/internal/ui"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Translate
|
// Translate
|
||||||
translator = translate.NewTranslator()
|
translator = translate.NewTranslator()
|
||||||
// UI
|
// UI
|
||||||
app = tview.NewApplication()
|
app = tview.NewApplication()
|
||||||
srcInput = tview.NewTextArea()
|
srcInput = tview.NewTextArea()
|
||||||
dstOutput = tview.NewTextView()
|
dstOutput = tview.NewTextView()
|
||||||
defOutput = tview.NewTextArea()
|
defOutput = tview.NewTextArea()
|
||||||
posOutput = tview.NewTextArea()
|
posOutput = tview.NewTextArea()
|
||||||
srcLangDropDown = tview.NewDropDown()
|
srcLangDropDown = tview.NewDropDown()
|
||||||
dstLangDropDown = tview.NewDropDown()
|
dstLangDropDown = tview.NewDropDown()
|
||||||
langCycle = ui.NewUICycle(srcLangDropDown, dstLangDropDown)
|
langCycle = ui.NewUICycle(srcLangDropDown, dstLangDropDown)
|
||||||
themeDropDown = tview.NewDropDown()
|
themeDropDown = tview.NewDropDown()
|
||||||
transparentDropDown = tview.NewDropDown()
|
transparentDropDown = tview.NewDropDown()
|
||||||
srcBorderDropDown = tview.NewDropDown()
|
srcBorderDropDown = tview.NewDropDown()
|
||||||
dstBorderDropDown = tview.NewDropDown()
|
dstBorderDropDown = tview.NewDropDown()
|
||||||
styleCycle = ui.NewUICycle(themeDropDown, transparentDropDown, srcBorderDropDown, dstBorderDropDown)
|
styleCycle = ui.NewUICycle(themeDropDown, transparentDropDown, srcBorderDropDown, dstBorderDropDown)
|
||||||
keyMapMenu = tview.NewTextView()
|
keyMapMenu = tview.NewTextView()
|
||||||
langButton = tview.NewButton("(1)Language")
|
langButton = tview.NewButton("(1)Language")
|
||||||
styleButton = tview.NewButton("(2)Style")
|
styleButton = tview.NewButton("(2)Style")
|
||||||
keyMapButton = tview.NewButton("(3)KeyMap")
|
keyMapButton = tview.NewButton("(3)KeyMap")
|
||||||
translateWindow = tview.NewFlex()
|
translateWindow = tview.NewFlex()
|
||||||
langWindow = tview.NewFlex()
|
translateAboveWidget = tview.NewFlex()
|
||||||
styleWindow = tview.NewFlex()
|
translateBelowWidget = tview.NewFlex()
|
||||||
keyMapWindow = tview.NewFlex()
|
langWindow = tview.NewFlex()
|
||||||
mainPage = tview.NewPages()
|
styleWindow = tview.NewFlex()
|
||||||
// settings
|
keyMapWindow = tview.NewFlex()
|
||||||
config = viper.New()
|
mainPage = tview.NewPages()
|
||||||
style = color.NewStyle()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
32
ui.go
32
ui.go
@ -35,12 +35,25 @@ const (
|
|||||||
Stop play sound.
|
Stop play sound.
|
||||||
[#%[1]s]<C-t>[-]
|
[#%[1]s]<C-t>[-]
|
||||||
Toggle transparent.
|
Toggle transparent.
|
||||||
|
[#%[1]s]<C-\>[-]
|
||||||
|
Toggle definition & 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.
|
||||||
[#%[1]s]<1>, <2>, <3>[-]
|
[#%[1]s]<1>, <2>, <3>[-]
|
||||||
Switch pop out window.`
|
Switch pop out window.`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func updateTranslateWindow() {
|
||||||
|
translateWindow.Clear()
|
||||||
|
if hideBelow {
|
||||||
|
translateWindow.AddItem(translateAboveWidget, 0, 1, true)
|
||||||
|
} else {
|
||||||
|
translateWindow.SetDirection(tview.FlexRow).
|
||||||
|
AddItem(translateAboveWidget, 0, 1, true).
|
||||||
|
AddItem(translateBelowWidget, 0, 1, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func updateBackgroundColor() {
|
func updateBackgroundColor() {
|
||||||
// input/output
|
// input/output
|
||||||
srcInput.SetTextStyle(tcell.StyleDefault.
|
srcInput.SetTextStyle(tcell.StyleDefault.
|
||||||
@ -263,15 +276,13 @@ func uiInit() {
|
|||||||
SetTitle("Key Map")
|
SetTitle("Key Map")
|
||||||
|
|
||||||
// window
|
// window
|
||||||
translateWindow.SetDirection(tview.FlexColumn).
|
translateAboveWidget.SetDirection(tview.FlexColumn).
|
||||||
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
|
AddItem(srcInput, 0, 1, true).
|
||||||
AddItem(srcInput, 0, 1, true).
|
AddItem(dstOutput, 0, 1, false)
|
||||||
AddItem(defOutput, 0, 1, false),
|
translateBelowWidget.SetDirection(tview.FlexColumn).
|
||||||
0, 1, true).
|
AddItem(defOutput, 0, 1, false).
|
||||||
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
|
AddItem(posOutput, 0, 1, false)
|
||||||
AddItem(dstOutput, 0, 1, false).
|
updateTranslateWindow()
|
||||||
AddItem(posOutput, 0, 1, false),
|
|
||||||
0, 1, false)
|
|
||||||
langWindow.SetDirection(tview.FlexRow).
|
langWindow.SetDirection(tview.FlexRow).
|
||||||
AddItem(nil, 0, 1, false).
|
AddItem(nil, 0, 1, false).
|
||||||
AddItem(tview.NewFlex().SetDirection(tview.FlexColumn).
|
AddItem(tview.NewFlex().SetDirection(tview.FlexColumn).
|
||||||
@ -391,6 +402,9 @@ func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
transparentDropDown.SetCurrentOption(
|
transparentDropDown.SetCurrentOption(
|
||||||
IndexOf(strconv.FormatBool(style.Transparent),
|
IndexOf(strconv.FormatBool(style.Transparent),
|
||||||
[]string{"true", "false"}))
|
[]string{"true", "false"}))
|
||||||
|
case tcell.KeyCtrlBackslash:
|
||||||
|
hideBelow = !hideBelow
|
||||||
|
updateTranslateWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
return event
|
return event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user