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