mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-19 17:21:26 -07:00
refacotr: move hide_below to style struct
This commit is contained in:
parent
c5cdbcb99a
commit
303441125b
13
config.go
13
config.go
@ -4,17 +4,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/eeeXun/gtt/internal/style"
|
||||
"github.com/eeeXun/gtt/internal/translate"
|
||||
config "github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
// settings
|
||||
uiStyle = style.NewStyle()
|
||||
hideBelow bool
|
||||
)
|
||||
|
||||
// Search XDG_CONFIG_HOME or $HOME/.config
|
||||
func configInit() {
|
||||
var (
|
||||
@ -77,8 +70,8 @@ func configInit() {
|
||||
config.GetString(fmt.Sprintf("destination.language.%s", name)))
|
||||
}
|
||||
translator = translators[config.GetString("translator")]
|
||||
hideBelow = config.GetBool("hide_below")
|
||||
uiStyle.Theme = config.GetString("theme")
|
||||
uiStyle.HideBelow = config.GetBool("hide_below")
|
||||
uiStyle.Transparent = config.GetBool("transparent")
|
||||
uiStyle.SetSrcBorderColor(config.GetString("source.borderColor")).
|
||||
SetDstBorderColor(config.GetString("destination.borderColor"))
|
||||
@ -117,9 +110,9 @@ func updateConfig() {
|
||||
changed = true
|
||||
config.Set("translator", translator.GetEngineName())
|
||||
}
|
||||
if config.GetBool("hide_below") != hideBelow {
|
||||
if config.GetBool("hide_below") != uiStyle.HideBelow {
|
||||
changed = true
|
||||
config.Set("hide_below", hideBelow)
|
||||
config.Set("hide_below", uiStyle.HideBelow)
|
||||
}
|
||||
if config.GetString("theme") != uiStyle.Theme {
|
||||
changed = true
|
||||
|
@ -5,6 +5,9 @@ import (
|
||||
)
|
||||
|
||||
type style struct {
|
||||
HideBelow bool
|
||||
Transparent bool
|
||||
Theme string
|
||||
srcBorderColor string
|
||||
dstBorderColor string
|
||||
backgroundColor string
|
||||
@ -14,8 +17,6 @@ type style struct {
|
||||
labelColor string
|
||||
pressColor string
|
||||
highLightColor string
|
||||
Theme string
|
||||
Transparent bool
|
||||
}
|
||||
|
||||
func NewStyle() *style {
|
||||
|
3
main.go
3
main.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/eeeXun/gtt/internal/style"
|
||||
"github.com/eeeXun/gtt/internal/translate"
|
||||
"github.com/eeeXun/gtt/internal/ui"
|
||||
"github.com/rivo/tview"
|
||||
@ -17,6 +18,8 @@ var (
|
||||
// Translate
|
||||
translator translate.Translator
|
||||
translators = make(map[string]translate.Translator, len(translate.AllTranslator))
|
||||
// UI style
|
||||
uiStyle = style.NewStyle()
|
||||
// UI
|
||||
app = tview.NewApplication()
|
||||
srcInput = tview.NewTextArea()
|
||||
|
10
ui.go
10
ui.go
@ -54,7 +54,7 @@ type Item struct {
|
||||
|
||||
func updateTranslateWindow() {
|
||||
translateWindow.Clear()
|
||||
if hideBelow {
|
||||
if uiStyle.HideBelow {
|
||||
translateWindow.AddItem(translateAboveWidget, 0, 1, true)
|
||||
} else {
|
||||
translateWindow.SetDirection(tview.FlexRow).
|
||||
@ -252,7 +252,7 @@ func uiInit() {
|
||||
hideBelowDropDown.SetLabel("Hide below: ").
|
||||
SetOptions([]string{"true", "false"}, nil).
|
||||
SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(hideBelow),
|
||||
IndexOf(strconv.FormatBool(uiStyle.HideBelow),
|
||||
[]string{"true", "false"}))
|
||||
transparentDropDown.SetLabel("Transparent: ").
|
||||
SetOptions([]string{"true", "false"}, nil).
|
||||
@ -382,7 +382,7 @@ func uiInit() {
|
||||
})
|
||||
hideBelowDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(func(text string, index int) {
|
||||
hideBelow, _ = strconv.ParseBool(text)
|
||||
uiStyle.HideBelow, _ = strconv.ParseBool(text)
|
||||
updateTranslateWindow()
|
||||
})
|
||||
srcBorderDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
@ -432,10 +432,10 @@ func mainPageHandler(event *tcell.EventKey) *tcell.EventKey {
|
||||
IndexOf(strconv.FormatBool(uiStyle.Transparent),
|
||||
[]string{"true", "false"}))
|
||||
case tcell.KeyCtrlBackslash:
|
||||
hideBelow = !hideBelow
|
||||
uiStyle.HideBelow = !uiStyle.HideBelow
|
||||
updateTranslateWindow()
|
||||
hideBelowDropDown.SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(hideBelow),
|
||||
IndexOf(strconv.FormatBool(uiStyle.HideBelow),
|
||||
[]string{"true", "false"}))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user