v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 00:00:16 -07:00

refactor: Theme & Transparent to style

This commit is contained in:
eeeXun 2022-10-24 17:40:32 +08:00
parent 457d94ed9f
commit 7eaee14787
4 changed files with 26 additions and 26 deletions

View File

@ -47,6 +47,8 @@ type Style struct {
prefixColor string prefixColor string
labelColor string labelColor string
pressColor string pressColor string
Theme string
Transparent bool
} }
func NewStyle() *Style { func NewStyle() *Style {
@ -61,38 +63,38 @@ func NewStyle() *Style {
} }
func (s Style) BackgroundColor() tcell.Color { func (s Style) BackgroundColor() tcell.Color {
if transparent { if s.Transparent {
return Transparent return Transparent
} }
return Themes[theme][s.backgroundColor] return Themes[s.Theme][s.backgroundColor]
} }
func (s Style) ForegroundColor() tcell.Color { func (s Style) ForegroundColor() tcell.Color {
return Themes[theme][s.foregroundColor] return Themes[s.Theme][s.foregroundColor]
} }
func (s Style) SelectedColor() tcell.Color { func (s Style) SelectedColor() tcell.Color {
return Themes[theme][s.selectedColor] return Themes[s.Theme][s.selectedColor]
} }
func (s Style) PrefixColor() tcell.Color { func (s Style) PrefixColor() tcell.Color {
return Themes[theme][s.prefixColor] return Themes[s.Theme][s.prefixColor]
} }
func (s Style) LabelColor() tcell.Color { func (s Style) LabelColor() tcell.Color {
return Themes[theme][s.labelColor] return Themes[s.Theme][s.labelColor]
} }
func (s Style) PressColor() tcell.Color { func (s Style) PressColor() tcell.Color {
return Themes[theme][s.pressColor] return Themes[s.Theme][s.pressColor]
} }
func (s Style) SrcBorderColor() tcell.Color { func (s Style) SrcBorderColor() tcell.Color {
return Themes[theme][s.src.borderColor] return Themes[s.Theme][s.src.borderColor]
} }
func (s Style) DstBorderColor() tcell.Color { func (s Style) DstBorderColor() tcell.Color {
return Themes[theme][s.dst.borderColor] return Themes[s.Theme][s.dst.borderColor]
} }
func (s Style) SrcBorderStr() string { func (s Style) SrcBorderStr() string {

View File

@ -33,10 +33,10 @@ func configInit() {
} }
// setup // setup
theme = config.GetString("theme")
transparent = config.GetBool("transparent")
translator.srcLang = config.GetString("source.language") translator.srcLang = config.GetString("source.language")
translator.dstLang = config.GetString("destination.language") translator.dstLang = config.GetString("destination.language")
style.Theme = config.GetString("theme")
style.Transparent = config.GetBool("transparent")
style.SetSrcBorderColor(config.GetString("source.borderColor")). style.SetSrcBorderColor(config.GetString("source.borderColor")).
SetDstBorderColor(config.GetString("destination.borderColor")) SetDstBorderColor(config.GetString("destination.borderColor"))
} }
@ -45,13 +45,13 @@ func configInit() {
func updateConfig() { func updateConfig() {
changed := false changed := false
if config.GetString("theme") != theme { if config.GetString("theme") != style.Theme {
changed = true changed = true
config.Set("theme", theme) config.Set("theme", style.Theme)
} }
if config.GetBool("transparent") != transparent { if config.GetBool("transparent") != style.Transparent {
changed = true changed = true
config.Set("transparent", transparent) config.Set("transparent", style.Transparent)
} }
if config.GetString("source.language") != translator.srcLang { if config.GetString("source.language") != translator.srcLang {
changed = true changed = true

View File

@ -27,11 +27,9 @@ var (
langWindow = tview.NewFlex() langWindow = tview.NewFlex()
styleWindow = tview.NewFlex() styleWindow = tview.NewFlex()
mainPage = tview.NewPages() mainPage = tview.NewPages()
style = NewStyle() // settings
// config config = viper.New()
config = viper.New() style = NewStyle()
theme string
transparent bool
) )
func main() { func main() {

12
ui.go
View File

@ -194,11 +194,11 @@ func uiInit() {
dstLangDropDown.SetOptions(Lang, nil) dstLangDropDown.SetOptions(Lang, nil)
themeDropDown.SetLabel("Theme: "). themeDropDown.SetLabel("Theme: ").
SetOptions(ThemesName, nil). SetOptions(ThemesName, nil).
SetCurrentOption(IndexOf(theme, ThemesName)) SetCurrentOption(IndexOf(style.Theme, ThemesName))
transparentDropDown.SetLabel("Transparent: "). transparentDropDown.SetLabel("Transparent: ").
SetOptions([]string{"true", "false"}, nil). SetOptions([]string{"true", "false"}, nil).
SetCurrentOption( SetCurrentOption(
IndexOf(strconv.FormatBool(transparent), IndexOf(strconv.FormatBool(style.Transparent),
[]string{"true", "false"})) []string{"true", "false"}))
srcBorderDropDown.SetLabel("Border Color: "). srcBorderDropDown.SetLabel("Border Color: ").
SetOptions(Palette, nil). SetOptions(Palette, nil).
@ -270,12 +270,12 @@ func uiInit() {
}) })
themeDropDown.SetDoneFunc(styleDropDownHandler). themeDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
theme = text style.Theme = text
updateAllColor() updateAllColor()
}) })
transparentDropDown.SetDoneFunc(styleDropDownHandler). transparentDropDown.SetDoneFunc(styleDropDownHandler).
SetSelectedFunc(func(text string, index int) { SetSelectedFunc(func(text string, index int) {
transparent, _ = strconv.ParseBool(text) style.Transparent, _ = strconv.ParseBool(text)
updateBackgroundColor() updateBackgroundColor()
}) })
srcBorderDropDown.SetDoneFunc(styleDropDownHandler). srcBorderDropDown.SetDoneFunc(styleDropDownHandler).
@ -305,10 +305,10 @@ func pagesHandler(event *tcell.EventKey) *tcell.EventKey {
switch key { switch key {
case tcell.KeyCtrlT: case tcell.KeyCtrlT:
transparent = !transparent style.Transparent = !style.Transparent
updateBackgroundColor() updateBackgroundColor()
transparentDropDown.SetCurrentOption( transparentDropDown.SetCurrentOption(
IndexOf(strconv.FormatBool(transparent), IndexOf(strconv.FormatBool(style.Transparent),
[]string{"true", "false"})) []string{"true", "false"}))
} }