mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-17 08:10:22 -07:00
refactor: Theme & Transparent to style
This commit is contained in:
parent
457d94ed9f
commit
7eaee14787
20
color.go
20
color.go
@ -47,6 +47,8 @@ type Style struct {
|
||||
prefixColor string
|
||||
labelColor string
|
||||
pressColor string
|
||||
Theme string
|
||||
Transparent bool
|
||||
}
|
||||
|
||||
func NewStyle() *Style {
|
||||
@ -61,38 +63,38 @@ func NewStyle() *Style {
|
||||
}
|
||||
|
||||
func (s Style) BackgroundColor() tcell.Color {
|
||||
if transparent {
|
||||
if s.Transparent {
|
||||
return Transparent
|
||||
}
|
||||
return Themes[theme][s.backgroundColor]
|
||||
return Themes[s.Theme][s.backgroundColor]
|
||||
}
|
||||
|
||||
func (s Style) ForegroundColor() tcell.Color {
|
||||
return Themes[theme][s.foregroundColor]
|
||||
return Themes[s.Theme][s.foregroundColor]
|
||||
}
|
||||
|
||||
func (s Style) SelectedColor() tcell.Color {
|
||||
return Themes[theme][s.selectedColor]
|
||||
return Themes[s.Theme][s.selectedColor]
|
||||
}
|
||||
|
||||
func (s Style) PrefixColor() tcell.Color {
|
||||
return Themes[theme][s.prefixColor]
|
||||
return Themes[s.Theme][s.prefixColor]
|
||||
}
|
||||
|
||||
func (s Style) LabelColor() tcell.Color {
|
||||
return Themes[theme][s.labelColor]
|
||||
return Themes[s.Theme][s.labelColor]
|
||||
}
|
||||
|
||||
func (s Style) PressColor() tcell.Color {
|
||||
return Themes[theme][s.pressColor]
|
||||
return Themes[s.Theme][s.pressColor]
|
||||
}
|
||||
|
||||
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 {
|
||||
return Themes[theme][s.dst.borderColor]
|
||||
return Themes[s.Theme][s.dst.borderColor]
|
||||
}
|
||||
|
||||
func (s Style) SrcBorderStr() string {
|
||||
|
12
config.go
12
config.go
@ -33,10 +33,10 @@ func configInit() {
|
||||
}
|
||||
|
||||
// setup
|
||||
theme = config.GetString("theme")
|
||||
transparent = config.GetBool("transparent")
|
||||
translator.srcLang = config.GetString("source.language")
|
||||
translator.dstLang = config.GetString("destination.language")
|
||||
style.Theme = config.GetString("theme")
|
||||
style.Transparent = config.GetBool("transparent")
|
||||
style.SetSrcBorderColor(config.GetString("source.borderColor")).
|
||||
SetDstBorderColor(config.GetString("destination.borderColor"))
|
||||
}
|
||||
@ -45,13 +45,13 @@ func configInit() {
|
||||
func updateConfig() {
|
||||
changed := false
|
||||
|
||||
if config.GetString("theme") != theme {
|
||||
if config.GetString("theme") != style.Theme {
|
||||
changed = true
|
||||
config.Set("theme", theme)
|
||||
config.Set("theme", style.Theme)
|
||||
}
|
||||
if config.GetBool("transparent") != transparent {
|
||||
if config.GetBool("transparent") != style.Transparent {
|
||||
changed = true
|
||||
config.Set("transparent", transparent)
|
||||
config.Set("transparent", style.Transparent)
|
||||
}
|
||||
if config.GetString("source.language") != translator.srcLang {
|
||||
changed = true
|
||||
|
8
main.go
8
main.go
@ -27,11 +27,9 @@ var (
|
||||
langWindow = tview.NewFlex()
|
||||
styleWindow = tview.NewFlex()
|
||||
mainPage = tview.NewPages()
|
||||
style = NewStyle()
|
||||
// config
|
||||
config = viper.New()
|
||||
theme string
|
||||
transparent bool
|
||||
// settings
|
||||
config = viper.New()
|
||||
style = NewStyle()
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
12
ui.go
12
ui.go
@ -194,11 +194,11 @@ func uiInit() {
|
||||
dstLangDropDown.SetOptions(Lang, nil)
|
||||
themeDropDown.SetLabel("Theme: ").
|
||||
SetOptions(ThemesName, nil).
|
||||
SetCurrentOption(IndexOf(theme, ThemesName))
|
||||
SetCurrentOption(IndexOf(style.Theme, ThemesName))
|
||||
transparentDropDown.SetLabel("Transparent: ").
|
||||
SetOptions([]string{"true", "false"}, nil).
|
||||
SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(transparent),
|
||||
IndexOf(strconv.FormatBool(style.Transparent),
|
||||
[]string{"true", "false"}))
|
||||
srcBorderDropDown.SetLabel("Border Color: ").
|
||||
SetOptions(Palette, nil).
|
||||
@ -270,12 +270,12 @@ func uiInit() {
|
||||
})
|
||||
themeDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(func(text string, index int) {
|
||||
theme = text
|
||||
style.Theme = text
|
||||
updateAllColor()
|
||||
})
|
||||
transparentDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
SetSelectedFunc(func(text string, index int) {
|
||||
transparent, _ = strconv.ParseBool(text)
|
||||
style.Transparent, _ = strconv.ParseBool(text)
|
||||
updateBackgroundColor()
|
||||
})
|
||||
srcBorderDropDown.SetDoneFunc(styleDropDownHandler).
|
||||
@ -305,10 +305,10 @@ func pagesHandler(event *tcell.EventKey) *tcell.EventKey {
|
||||
|
||||
switch key {
|
||||
case tcell.KeyCtrlT:
|
||||
transparent = !transparent
|
||||
style.Transparent = !style.Transparent
|
||||
updateBackgroundColor()
|
||||
transparentDropDown.SetCurrentOption(
|
||||
IndexOf(strconv.FormatBool(transparent),
|
||||
IndexOf(strconv.FormatBool(style.Transparent),
|
||||
[]string{"true", "false"}))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user