Unify color loopkup

pull/232/head
ѵµσɳɠ 3 years ago
parent 7e4ede0ab8
commit 71552bf044

@ -72,12 +72,12 @@ func NewColorscheme(colors ColorschemeColors) *Colorscheme {
// BaseFg ...
func (c *Colorscheme) BaseFg() tcell.Color {
return c.TcellFgColor("base")
return c.FgColor("base")
}
// BaseBg ...
func (c *Colorscheme) BaseBg() tcell.Color {
return c.TcellBgColor("base")
return c.BgColor("base")
}
// Chart ...
@ -275,15 +275,8 @@ func (c *Colorscheme) Color(name string, a ...interface{}) string {
return c.ToSprintf(name)(a...)
}
func (c *Colorscheme) TcellFgColor(name string) tcell.Color {
color := tcell.ColorDefault
if v, ok := c.colors[name+"_fg"].(string); !ok {
color = c.ToTcellColor(v)
}
if color != tcell.ColorDefault {
return tcell.PaletteColor(int(color) & 0xff)
}
func (c *Colorscheme) FgColor(name string) tcell.Color {
fg := c.tcellColor(name + "_fg")
// TODO: fixme
// if v, ok := c.colors[name+"_bold"].(bool); ok {
@ -297,14 +290,24 @@ func (c *Colorscheme) TcellFgColor(name string) tcell.Color {
// }
// }
return color
return fg
}
func (c *Colorscheme) TcellBgColor(name string) tcell.Color {
// TODO: Parse config value to Tcell.Color and remove gocui.Attribute
func (c *Colorscheme) BgColor(name string) tcell.Color {
return c.tcellColor(name + "_bg")
}
func (c *Colorscheme) tcellColor(name string) tcell.Color {
color := tcell.ColorDefault
if v, ok := c.colors[name+"_bg"].(string); ok {
color = c.ToTcellColor(v)
v, ok := c.colors[name].(string)
if ok {
// TODO: if we already have refactor colorscheme to use tcell.Color values as a right way
// then we can just remove this mapping lookup
// and just use tcell.GetColor(v) only
color, ok = TcellColorschemeColorsMap[v]
if !ok {
color = tcell.GetColor(v)
}
}
if color != tcell.ColorDefault {
@ -348,15 +351,6 @@ func (c *Colorscheme) ToUnderlineAttr(v bool) (fcolor.Attribute, bool) {
return fcolor.Underline, v
}
// ToTcellColor converts a color string name to a gocui Attribute type
func (c *Colorscheme) ToTcellColor(v string) tcell.Color {
if attr, ok := TcellColorschemeColorsMap[v]; ok {
return attr
}
return tcell.GetColor(v)
}
// HexToAnsi converts a hex color string to a uint8 ansi code
func HexToAnsi(h string) (uint8, bool) {
if h == "" {

@ -58,8 +58,8 @@ func (ct *Cointop) layout() error {
} else {
if err := ct.ui.SetView(ct.Views.Marketbar, 0, topOffset-1, maxX, marketbarHeight+1); err != nil {
ct.Views.Marketbar.SetFrame(false)
ct.Views.Marketbar.SetFgColor(ct.colorscheme.TcellFgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetBgColor(ct.colorscheme.TcellBgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetFgColor(ct.colorscheme.FgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetBgColor(ct.colorscheme.BgColor(ct.Views.Marketbar.Name()))
go func() {
ct.UpdateMarketbar()
_, found := ct.cache.Get(ct.Views.Marketbar.Name())
@ -92,8 +92,8 @@ func (ct *Cointop) layout() error {
if err := ct.ui.SetView(ct.Views.Chart, 0, chartTopOffset, maxX, topOffset+chartHeight); err != nil {
ct.Views.Chart.Clear()
ct.Views.Chart.SetFrame(false)
ct.Views.Chart.SetFgColor(ct.colorscheme.TcellFgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetBgColor(ct.colorscheme.TcellBgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetFgColor(ct.colorscheme.FgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetBgColor(ct.colorscheme.BgColor(ct.Views.Chart.Name()))
go func() {
ct.UpdateChart()
cachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
@ -124,8 +124,8 @@ func (ct *Cointop) layout() error {
topOffset = topOffset + chartHeight
if err := ct.ui.SetView(ct.Views.TableHeader, tableOffsetX, topOffset-1, maxX, topOffset+1); err != nil {
ct.Views.TableHeader.SetFrame(false)
ct.Views.TableHeader.SetFgColor(ct.colorscheme.TcellFgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetBgColor(ct.colorscheme.TcellBgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetFgColor(ct.colorscheme.FgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetBgColor(ct.colorscheme.BgColor(ct.Views.TableHeader.Name()))
go ct.UpdateTableHeader()
}
@ -133,8 +133,8 @@ func (ct *Cointop) layout() error {
if err := ct.ui.SetView(ct.Views.Table, tableOffsetX, topOffset-1, maxX, maxY-statusbarHeight); err != nil {
ct.Views.Table.SetFrame(false)
ct.Views.Table.SetHighlight(true)
ct.Views.Table.SetSelFgColor(ct.colorscheme.TcellFgColor("table_row_active"))
ct.Views.Table.SetSelBgColor(ct.colorscheme.TcellBgColor("table_row_active"))
ct.Views.Table.SetSelFgColor(ct.colorscheme.FgColor("table_row_active"))
ct.Views.Table.SetSelBgColor(ct.colorscheme.BgColor("table_row_active"))
_, found := ct.cache.Get("allCoinsSlugMap")
if found {
ct.cache.Delete("allCoinsSlugMap")
@ -149,8 +149,8 @@ func (ct *Cointop) layout() error {
if !ct.State.hideStatusbar {
if err := ct.ui.SetView(ct.Views.Statusbar, 0, maxY-statusbarHeight-1, maxX, maxY); err != nil {
ct.Views.Statusbar.SetFrame(false)
ct.Views.Statusbar.SetFgColor(ct.colorscheme.TcellFgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetBgColor(ct.colorscheme.TcellBgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetFgColor(ct.colorscheme.FgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetBgColor(ct.colorscheme.BgColor(ct.Views.Statusbar.Name()))
go ct.UpdateStatusbar("")
}
} else {
@ -166,22 +166,22 @@ func (ct *Cointop) layout() error {
ct.Views.SearchField.SetEditable(true)
ct.Views.SearchField.SetWrap(true)
ct.Views.SearchField.SetFrame(false)
ct.Views.SearchField.SetFgColor(ct.colorscheme.TcellFgColor("searchbar"))
ct.Views.SearchField.SetBgColor(ct.colorscheme.TcellBgColor("searchbar"))
ct.Views.SearchField.SetFgColor(ct.colorscheme.FgColor("searchbar"))
ct.Views.SearchField.SetBgColor(ct.colorscheme.BgColor("searchbar"))
}
if err := ct.ui.SetView(ct.Views.Menu, 1, 1, maxX-1, maxY-1); err != nil {
ct.Views.Menu.SetFrame(false)
ct.Views.Menu.SetFgColor(ct.colorscheme.TcellFgColor("menu"))
ct.Views.Menu.SetBgColor(ct.colorscheme.TcellBgColor("menu"))
ct.Views.Menu.SetFgColor(ct.colorscheme.FgColor("menu"))
ct.Views.Menu.SetBgColor(ct.colorscheme.BgColor("menu"))
}
if err := ct.ui.SetView(ct.Views.Input, 3, 6, 30, 8); err != nil {
ct.Views.Input.SetFrame(true)
ct.Views.Input.SetEditable(true)
ct.Views.Input.SetWrap(true)
ct.Views.Input.SetFgColor(ct.colorscheme.TcellFgColor("menu"))
ct.Views.Input.SetBgColor(ct.colorscheme.TcellBgColor("menu"))
ct.Views.Input.SetFgColor(ct.colorscheme.FgColor("menu"))
ct.Views.Input.SetBgColor(ct.colorscheme.BgColor("menu"))
// run only once on init.
// this bit of code should be at the bottom

Loading…
Cancel
Save