mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-19 01:00:20 -07:00
color in string instead of tcell.Color
This commit is contained in:
parent
cc3db4bb69
commit
e3f67f4454
93
color.go
93
color.go
@ -34,38 +34,73 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Colors struct {
|
type WindowStyle struct {
|
||||||
backgroundColor tcell.Color
|
borderColor string
|
||||||
foregroundColor tcell.Color
|
|
||||||
borderColor tcell.Color
|
|
||||||
textColor tcell.Color
|
|
||||||
selectedColor tcell.Color
|
|
||||||
prefixColor tcell.Color
|
|
||||||
labelColor tcell.Color
|
|
||||||
pressColor tcell.Color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Window struct {
|
type Style struct {
|
||||||
src Colors
|
src WindowStyle
|
||||||
dst Colors
|
dst WindowStyle
|
||||||
|
backgroundColor string
|
||||||
|
foregroundColor string
|
||||||
|
selectedColor string
|
||||||
|
prefixColor string
|
||||||
|
labelColor string
|
||||||
|
pressColor string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) colorInit() {
|
func NewStyle() *Style {
|
||||||
if transparent {
|
return &Style{
|
||||||
w.src.backgroundColor = Transparent
|
backgroundColor: "bg",
|
||||||
w.dst.backgroundColor = Transparent
|
foregroundColor: "fg",
|
||||||
} else {
|
selectedColor: "gray",
|
||||||
w.src.backgroundColor = Themes[theme]["bg"]
|
prefixColor: "cyan",
|
||||||
w.dst.backgroundColor = Themes[theme]["bg"]
|
labelColor: "yellow",
|
||||||
|
pressColor: "cyan",
|
||||||
}
|
}
|
||||||
w.src.borderColor = Themes[theme]["red"]
|
}
|
||||||
w.src.foregroundColor = Themes[theme]["fg"]
|
|
||||||
w.src.selectedColor = Themes[theme]["gray"]
|
func (s Style) BackgroundColor() tcell.Color {
|
||||||
w.src.prefixColor = Themes[theme]["cyan"]
|
if transparent {
|
||||||
w.src.pressColor = Themes[theme]["purple"]
|
return Transparent
|
||||||
w.src.labelColor = Themes[theme]["yellow"]
|
}
|
||||||
w.dst.foregroundColor = Themes[theme]["fg"]
|
return Themes[theme][s.backgroundColor]
|
||||||
w.dst.selectedColor = Themes[theme]["gray"]
|
}
|
||||||
w.dst.borderColor = Themes[theme]["blue"]
|
|
||||||
w.dst.prefixColor = Themes[theme]["cyan"]
|
func (s Style) ForegroundColor() tcell.Color {
|
||||||
|
return Themes[theme][s.foregroundColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) SelectedColor() tcell.Color {
|
||||||
|
return Themes[theme][s.selectedColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) PrefixColor() tcell.Color {
|
||||||
|
return Themes[theme][s.prefixColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) LabelColor() tcell.Color {
|
||||||
|
return Themes[theme][s.labelColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) PressColor() tcell.Color {
|
||||||
|
return Themes[theme][s.pressColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) SrcBorderColor() tcell.Color {
|
||||||
|
return Themes[theme][s.src.borderColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) DstBorderColor() tcell.Color {
|
||||||
|
return Themes[theme][s.dst.borderColor]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Style) SetSrcBorderColor(color string) *Style {
|
||||||
|
s.src.borderColor = color
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Style) SetDstBorderColor(color string) *Style {
|
||||||
|
s.dst.borderColor = color
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ func configInit() {
|
|||||||
config.Set("theme", "Gruvbox")
|
config.Set("theme", "Gruvbox")
|
||||||
config.Set("source.language", "English")
|
config.Set("source.language", "English")
|
||||||
config.Set("destination.language", "Chinese (Traditional)")
|
config.Set("destination.language", "Chinese (Traditional)")
|
||||||
|
config.Set("source.borderColor", "red")
|
||||||
|
config.Set("destination.borderColor", "blue")
|
||||||
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
||||||
os.Mkdir(defaultConfigPath, os.ModePerm)
|
os.Mkdir(defaultConfigPath, os.ModePerm)
|
||||||
}
|
}
|
||||||
@ -35,6 +37,8 @@ func configInit() {
|
|||||||
transparent = config.GetBool("transparent")
|
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.SetSrcBorderColor(config.GetString("source.borderColor"))
|
||||||
|
style.SetDstBorderColor(config.GetString("destination.borderColor"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if need to modify config file when quit program
|
// Check if need to modify config file when quit program
|
||||||
|
3
main.go
3
main.go
@ -27,7 +27,7 @@ var (
|
|||||||
langWindow = tview.NewFlex()
|
langWindow = tview.NewFlex()
|
||||||
styleWindow = tview.NewFlex()
|
styleWindow = tview.NewFlex()
|
||||||
mainPage = tview.NewPages()
|
mainPage = tview.NewPages()
|
||||||
window Window
|
style = NewStyle()
|
||||||
// config
|
// config
|
||||||
config = viper.New()
|
config = viper.New()
|
||||||
theme string
|
theme string
|
||||||
@ -37,7 +37,6 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
SetTermTitle("GTT")
|
SetTermTitle("GTT")
|
||||||
configInit()
|
configInit()
|
||||||
window.colorInit()
|
|
||||||
uiInit()
|
uiInit()
|
||||||
|
|
||||||
mainPage.AddPage("translatePage", translateWindow, true, true)
|
mainPage.AddPage("translatePage", translateWindow, true, true)
|
||||||
|
183
ui.go
183
ui.go
@ -36,119 +36,119 @@ func (ui *UICycle) GetCurrentUI() tview.Primitive {
|
|||||||
|
|
||||||
func updateBackgroundColor() {
|
func updateBackgroundColor() {
|
||||||
// box
|
// box
|
||||||
srcBox.SetBackgroundColor(window.src.backgroundColor)
|
srcBox.SetBackgroundColor(style.BackgroundColor())
|
||||||
srcBox.SetTextStyle(tcell.StyleDefault.
|
srcBox.SetTextStyle(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor))
|
Foreground(style.ForegroundColor()))
|
||||||
dstBox.SetBackgroundColor(window.dst.backgroundColor)
|
dstBox.SetBackgroundColor(style.BackgroundColor())
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
srcLangDropDown.SetBackgroundColor(window.src.backgroundColor)
|
srcLangDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
srcLangDropDown.SetListStyles(tcell.StyleDefault.
|
srcLangDropDown.SetListStyles(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor),
|
Foreground(style.ForegroundColor()),
|
||||||
tcell.StyleDefault.
|
tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.prefixColor))
|
Foreground(style.PrefixColor()))
|
||||||
dstLangDropDown.SetBackgroundColor(window.dst.backgroundColor)
|
dstLangDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
dstLangDropDown.SetListStyles(tcell.StyleDefault.
|
dstLangDropDown.SetListStyles(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor),
|
Foreground(style.ForegroundColor()),
|
||||||
tcell.StyleDefault.
|
tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.prefixColor))
|
Foreground(style.PrefixColor()))
|
||||||
themeDropDown.SetBackgroundColor(window.src.backgroundColor)
|
themeDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
themeDropDown.SetListStyles(tcell.StyleDefault.
|
themeDropDown.SetListStyles(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor),
|
Foreground(style.ForegroundColor()),
|
||||||
tcell.StyleDefault.
|
tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.prefixColor))
|
Foreground(style.PrefixColor()))
|
||||||
transparentDropDown.SetBackgroundColor(window.src.backgroundColor)
|
transparentDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
transparentDropDown.SetListStyles(tcell.StyleDefault.
|
transparentDropDown.SetListStyles(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor),
|
Foreground(style.ForegroundColor()),
|
||||||
tcell.StyleDefault.
|
tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.prefixColor))
|
Foreground(style.PrefixColor()))
|
||||||
srcBorderDropDown.SetBackgroundColor(window.src.backgroundColor)
|
srcBorderDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
srcBorderDropDown.SetListStyles(tcell.StyleDefault.
|
srcBorderDropDown.SetListStyles(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor),
|
Foreground(style.ForegroundColor()),
|
||||||
tcell.StyleDefault.
|
tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.prefixColor))
|
Foreground(style.PrefixColor()))
|
||||||
dstBorderDropDown.SetBackgroundColor(window.dst.backgroundColor)
|
dstBorderDropDown.SetBackgroundColor(style.BackgroundColor())
|
||||||
dstBorderDropDown.SetListStyles(tcell.StyleDefault.
|
dstBorderDropDown.SetListStyles(tcell.StyleDefault.
|
||||||
Background(window.src.backgroundColor).
|
Background(style.BackgroundColor()).
|
||||||
Foreground(window.src.foregroundColor),
|
Foreground(style.ForegroundColor()),
|
||||||
tcell.StyleDefault.
|
tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.prefixColor))
|
Foreground(style.PrefixColor()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateBorderColor() {
|
func updateBorderColor() {
|
||||||
// box
|
// box
|
||||||
srcBox.SetBorderColor(window.src.borderColor).
|
srcBox.SetBorderColor(style.SrcBorderColor()).
|
||||||
SetTitleColor(window.src.borderColor)
|
SetTitleColor(style.SrcBorderColor())
|
||||||
dstBox.SetBorderColor(window.dst.borderColor).
|
dstBox.SetBorderColor(style.DstBorderColor()).
|
||||||
SetTitleColor(window.dst.borderColor)
|
SetTitleColor(style.DstBorderColor())
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
srcLangDropDown.SetBorderColor(window.src.borderColor).
|
srcLangDropDown.SetBorderColor(style.SrcBorderColor()).
|
||||||
SetTitleColor(window.src.borderColor)
|
SetTitleColor(style.SrcBorderColor())
|
||||||
dstLangDropDown.SetBorderColor(window.dst.borderColor).
|
dstLangDropDown.SetBorderColor(style.DstBorderColor()).
|
||||||
SetTitleColor(window.dst.borderColor)
|
SetTitleColor(style.DstBorderColor())
|
||||||
srcBorderDropDown.SetBorderColor(window.src.borderColor).
|
srcBorderDropDown.SetBorderColor(style.SrcBorderColor()).
|
||||||
SetTitleColor(window.src.borderColor)
|
SetTitleColor(style.SrcBorderColor())
|
||||||
dstBorderDropDown.SetBorderColor(window.dst.borderColor).
|
dstBorderDropDown.SetBorderColor(style.DstBorderColor()).
|
||||||
SetTitleColor(window.dst.borderColor)
|
SetTitleColor(style.DstBorderColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateNonConfigColor() {
|
func updateNonConfigColor() {
|
||||||
// box
|
// box
|
||||||
srcBox.SetSelectedStyle(tcell.StyleDefault.
|
srcBox.SetSelectedStyle(tcell.StyleDefault.
|
||||||
Background(window.src.selectedColor).
|
Background(style.SelectedColor()).
|
||||||
Foreground(window.src.foregroundColor))
|
Foreground(style.ForegroundColor()))
|
||||||
dstBox.SetTextColor(window.dst.foregroundColor)
|
dstBox.SetTextColor(style.ForegroundColor())
|
||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
srcLangDropDown.SetFieldBackgroundColor(window.src.selectedColor).
|
srcLangDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
SetFieldTextColor(window.src.foregroundColor).
|
SetFieldTextColor(style.ForegroundColor()).
|
||||||
SetPrefixTextColor(window.src.prefixColor)
|
SetPrefixTextColor(style.PrefixColor())
|
||||||
dstLangDropDown.SetFieldBackgroundColor(window.dst.selectedColor).
|
dstLangDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
SetFieldTextColor(window.dst.foregroundColor).
|
SetFieldTextColor(style.ForegroundColor()).
|
||||||
SetPrefixTextColor(window.dst.prefixColor)
|
SetPrefixTextColor(style.PrefixColor())
|
||||||
themeDropDown.SetLabelColor(window.src.labelColor)
|
themeDropDown.SetLabelColor(style.LabelColor())
|
||||||
themeDropDown.SetFieldBackgroundColor(window.src.selectedColor).
|
themeDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
SetFieldTextColor(window.src.foregroundColor).
|
SetFieldTextColor(style.ForegroundColor()).
|
||||||
SetPrefixTextColor(window.src.prefixColor)
|
SetPrefixTextColor(style.PrefixColor())
|
||||||
transparentDropDown.SetLabelColor(window.src.labelColor)
|
transparentDropDown.SetLabelColor(style.LabelColor())
|
||||||
transparentDropDown.SetFieldBackgroundColor(window.src.selectedColor).
|
transparentDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
SetFieldTextColor(window.src.foregroundColor).
|
SetFieldTextColor(style.ForegroundColor()).
|
||||||
SetPrefixTextColor(window.src.prefixColor)
|
SetPrefixTextColor(style.PrefixColor())
|
||||||
srcBorderDropDown.SetLabelColor(window.src.labelColor)
|
srcBorderDropDown.SetLabelColor(style.LabelColor())
|
||||||
srcBorderDropDown.SetFieldBackgroundColor(window.src.selectedColor).
|
srcBorderDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
SetFieldTextColor(window.src.foregroundColor).
|
SetFieldTextColor(style.ForegroundColor()).
|
||||||
SetPrefixTextColor(window.src.prefixColor)
|
SetPrefixTextColor(style.PrefixColor())
|
||||||
dstBorderDropDown.SetLabelColor(window.src.labelColor)
|
dstBorderDropDown.SetLabelColor(style.LabelColor())
|
||||||
dstBorderDropDown.SetFieldBackgroundColor(window.src.selectedColor).
|
dstBorderDropDown.SetFieldBackgroundColor(style.SelectedColor()).
|
||||||
SetFieldTextColor(window.src.foregroundColor).
|
SetFieldTextColor(style.ForegroundColor()).
|
||||||
SetPrefixTextColor(window.src.prefixColor)
|
SetPrefixTextColor(style.PrefixColor())
|
||||||
|
|
||||||
// button
|
// button
|
||||||
langButton.SetLabelColor(window.src.foregroundColor).
|
langButton.SetLabelColor(style.ForegroundColor()).
|
||||||
SetBackgroundColorActivated(window.src.pressColor).
|
SetBackgroundColorActivated(style.PressColor()).
|
||||||
SetLabelColorActivated(window.src.foregroundColor).
|
SetLabelColorActivated(style.ForegroundColor()).
|
||||||
SetBackgroundColor(window.src.selectedColor)
|
SetBackgroundColor(style.SelectedColor())
|
||||||
styleButton.SetLabelColor(window.src.foregroundColor).
|
styleButton.SetLabelColor(style.ForegroundColor()).
|
||||||
SetBackgroundColorActivated(window.src.pressColor).
|
SetBackgroundColorActivated(style.PressColor()).
|
||||||
SetLabelColorActivated(window.src.foregroundColor).
|
SetLabelColorActivated(style.ForegroundColor()).
|
||||||
SetBackgroundColor(window.src.selectedColor)
|
SetBackgroundColor(style.SelectedColor())
|
||||||
menuButton.SetLabelColor(window.src.foregroundColor).
|
menuButton.SetLabelColor(style.ForegroundColor()).
|
||||||
SetBackgroundColorActivated(window.src.pressColor).
|
SetBackgroundColorActivated(style.PressColor()).
|
||||||
SetLabelColorActivated(window.src.foregroundColor).
|
SetLabelColorActivated(style.ForegroundColor()).
|
||||||
SetBackgroundColor(window.src.selectedColor)
|
SetBackgroundColor(style.SelectedColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateAllColor() {
|
func updateAllColor() {
|
||||||
@ -277,15 +277,8 @@ func pagesHandler(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case tcell.KeyCtrlT:
|
case tcell.KeyCtrlT:
|
||||||
if transparent {
|
|
||||||
window.src.backgroundColor = Themes[theme]["bg"]
|
|
||||||
window.dst.backgroundColor = Themes[theme]["bg"]
|
|
||||||
} else {
|
|
||||||
window.src.backgroundColor = Transparent
|
|
||||||
window.dst.backgroundColor = Transparent
|
|
||||||
}
|
|
||||||
updateBackgroundColor()
|
|
||||||
transparent = !transparent
|
transparent = !transparent
|
||||||
|
updateBackgroundColor()
|
||||||
transparentDropDown.SetCurrentOption(
|
transparentDropDown.SetCurrentOption(
|
||||||
IndexOf(strconv.FormatBool(transparent),
|
IndexOf(strconv.FormatBool(transparent),
|
||||||
[]string{"true", "false"}))
|
[]string{"true", "false"}))
|
||||||
@ -422,18 +415,10 @@ func styleDropDownHandler(key tcell.Key) {
|
|||||||
|
|
||||||
func themeSelected(text string, index int) {
|
func themeSelected(text string, index int) {
|
||||||
theme = text
|
theme = text
|
||||||
window.colorInit()
|
|
||||||
updateAllColor()
|
updateAllColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
func transparentSelected(text string, index int) {
|
func transparentSelected(text string, index int) {
|
||||||
transparent, _ = strconv.ParseBool(text)
|
transparent, _ = strconv.ParseBool(text)
|
||||||
if transparent {
|
|
||||||
window.src.backgroundColor = Transparent
|
|
||||||
window.dst.backgroundColor = Transparent
|
|
||||||
} else {
|
|
||||||
window.src.backgroundColor = Themes[theme]["bg"]
|
|
||||||
window.dst.backgroundColor = Themes[theme]["bg"]
|
|
||||||
}
|
|
||||||
updateBackgroundColor()
|
updateBackgroundColor()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user