Convert some tcell.Color into tcell.Style. Less calls, and can include bold etc

pull/232/head
Simon Roberts 3 years ago
parent 0a3073295d
commit d213906281
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -490,8 +490,7 @@ func (ct *Cointop) Run() error {
return err
}
ui.SetFgColor(ct.colorscheme.BaseFg())
ui.SetBgColor(ct.colorscheme.BaseBg())
ui.SetStyle(ct.colorscheme.BaseStyle())
ct.ui = ui
ct.g = ui.GetGocui()
defer ui.Close()

@ -72,14 +72,8 @@ func NewColorscheme(colors ColorschemeColors) *Colorscheme {
}
}
// BaseFg ...
func (c *Colorscheme) BaseFg() tcell.Color {
return c.FgColor("base")
}
// BaseBg ...
func (c *Colorscheme) BaseBg() tcell.Color {
return c.BgColor("base")
func (c *Colorscheme) BaseStyle() tcell.Style {
return c.Style("base")
}
// Chart ...
@ -277,26 +271,18 @@ func (c *Colorscheme) Color(name string, a ...interface{}) string {
return c.ToSprintf(name)(a...)
}
func (c *Colorscheme) FgColor(name string) tcell.Color {
fg := c.tcellColor(name + "_fg")
// TODO: fixme
// if v, ok := c.colors[name+"_bold"].(bool); ok {
// if v {
// attrs = append(attrs, gocui.AttrBold)
// }
// }
// if v, ok := c.colors[name+"_underline"].(bool); ok {
// if v {
// attrs = append(attrs, gocui.AttrUnderline)
// }
// }
return fg
}
func (c *Colorscheme) BgColor(name string) tcell.Color {
return c.tcellColor(name + "_bg")
func (c *Colorscheme) Style(name string) tcell.Style {
st := tcell.StyleDefault
st = st.Foreground(c.tcellColor(name + "_fg"))
st = st.Foreground(c.tcellColor(name + "_bg"))
if v, ok := c.colors[name+"_bold"].(bool); ok {
st = st.Bold(v)
}
if v, ok := c.colors[name+"_underline"].(bool); ok {
st = st.Underline(v)
}
// TODO: Blink Dim Italic Reverse Strikethrough
return st
}
// tcellColor can supply for types of color name: specific mapped name, tcell color name, hex

@ -58,8 +58,7 @@ 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.FgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetBgColor(ct.colorscheme.BgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetStyle(ct.colorscheme.Style(ct.Views.Marketbar.Name()))
go func() {
ct.UpdateMarketbar()
_, found := ct.cache.Get(ct.Views.Marketbar.Name())
@ -92,8 +91,7 @@ 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.FgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetBgColor(ct.colorscheme.BgColor(ct.Views.Chart.Name()))
ct.Views.Chart.SetStyle(ct.colorscheme.Style(ct.Views.Chart.Name()))
go func() {
ct.UpdateChart()
cachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
@ -124,8 +122,7 @@ 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.FgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetBgColor(ct.colorscheme.BgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetStyle(ct.colorscheme.Style(ct.Views.TableHeader.Name()))
go ct.UpdateTableHeader()
}
@ -133,8 +130,7 @@ 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.FgColor("table_row_active"))
ct.Views.Table.SetSelBgColor(ct.colorscheme.BgColor("table_row_active"))
ct.Views.Table.SetSelStyle(ct.colorscheme.Style("table_row_active"))
_, found := ct.cache.Get("allCoinsSlugMap")
if found {
ct.cache.Delete("allCoinsSlugMap")
@ -149,8 +145,7 @@ 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.FgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetBgColor(ct.colorscheme.BgColor(ct.Views.Statusbar.Name()))
ct.Views.Statusbar.SetStyle(ct.colorscheme.Style(ct.Views.Statusbar.Name()))
go ct.UpdateStatusbar("")
}
} else {
@ -166,22 +161,19 @@ 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.FgColor("searchbar"))
ct.Views.SearchField.SetBgColor(ct.colorscheme.BgColor("searchbar"))
ct.Views.SearchField.SetStyle(ct.colorscheme.Style("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.FgColor("menu"))
ct.Views.Menu.SetBgColor(ct.colorscheme.BgColor("menu"))
ct.Views.Menu.SetStyle(ct.colorscheme.Style("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.FgColor("menu"))
ct.Views.Input.SetBgColor(ct.colorscheme.BgColor("menu"))
ct.Views.Input.SetStyle(ct.colorscheme.Style("menu"))
// run only once on init.
// this bit of code should be at the bottom

@ -27,14 +27,9 @@ func (ui *UI) GetGocui() *gocui.Gui {
return ui.g
}
// SetFgColor sets the foreground color
func (ui *UI) SetFgColor(fgColor tcell.Color) {
ui.g.Style = ui.g.Style.Foreground(fgColor)
}
// SetBgColor sets the background color
func (ui *UI) SetBgColor(bgColor tcell.Color) {
ui.g.Style = ui.g.Style.Background(bgColor)
// SetFgColor sets the default style
func (ui *UI) SetStyle(st tcell.Style) {
ui.g.Style = st
}
// SetInputEsc enables the escape key

@ -214,33 +214,14 @@ func (view *View) SetWrap(enabled bool) error {
return nil
}
// SetFgColor sets the foreground color
func (view *View) SetFgColor(color tcell.Color) {
if view.HasBacking() {
view.backing.Style = view.backing.Style.Foreground(color)
}
}
// SetBgColor sets the background color
func (view *View) SetBgColor(color tcell.Color) {
if view.HasBacking() {
// view.backing.BgColor = color
view.backing.Style = view.backing.Style.Background(color)
}
// SetStyle sets the text style for the view
func (view *View) SetStyle(st tcell.Style) {
view.backing.Style = st
}
// SetSelFgColor sets the foreground color for selection
func (view *View) SetSelFgColor(color tcell.Color) {
if view.HasBacking() {
view.backing.SelStyle = view.backing.SelStyle.Foreground(color)
}
}
// SetSelBgColor sets the background color for selection
func (view *View) SetSelBgColor(color tcell.Color) {
if view.HasBacking() {
view.backing.SelStyle = view.backing.SelStyle.Background(color)
}
// SetStyle sets the selection text style for the view
func (view *View) SetSelStyle(st tcell.Style) {
view.backing.SelStyle = st
}
// Read reads data in bytes buffer

Loading…
Cancel
Save