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