From b8eb3863605f34ea4ed0a7a278a99ca78f0205e9 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Wed, 8 Mar 2017 10:40:03 +1100 Subject: [PATCH] add global default ColorMap --- README.md | 2 +- colors.go | 43 +++++++++++++++++++++++++++++++++++++ cwidgets/compact/gauge.go | 1 - cwidgets/compact/setters.go | 4 ++-- cwidgets/compact/text.go | 2 +- cwidgets/expanded/cpu.go | 2 -- cwidgets/expanded/info.go | 2 +- cwidgets/expanded/mem.go | 4 ---- cwidgets/expanded/net.go | 2 -- main.go | 1 + menus.go | 6 ------ widgets/header.go | 10 ++++----- widgets/input.go | 6 ++++-- widgets/menu/main.go | 8 ++++--- 14 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 colors.go diff --git a/README.md b/README.md index f237274..6b86c68 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

cTop

+

cTop

# Top-like interface for container metrics diff --git a/colors.go b/colors.go new file mode 100644 index 0000000..85f52a9 --- /dev/null +++ b/colors.go @@ -0,0 +1,43 @@ +package main + +import ui "github.com/gizak/termui" + +/* +Valid colors: + ui.ColorDefault + ui.ColorBlack + ui.ColorRed + ui.ColorGreen + ui.ColorYellow + ui.ColorBlue + ui.ColorMagenta + ui.ColorCyan + ui.ColorWhite +*/ + +var ColorMap = map[string]ui.Attribute{ + "fg": ui.ColorWhite, + "bg": ui.ColorDefault, + "block.bg": ui.ColorDefault, + "border.bg": ui.ColorDefault, + "border.fg": ui.ColorWhite, + "label.bg": ui.ColorDefault, + "label.fg": ui.ColorGreen, + "menu.text.fg": ui.ColorWhite, + "menu.text.bg": ui.ColorDefault, + "menu.border.fg": ui.ColorCyan, + "menu.label.fg": ui.ColorGreen, + "header.fg": ui.ColorBlack, + "header.bg": ui.ColorWhite, + "gauge.bar.bg": ui.ColorGreen, + "gauge.percent.fg": ui.ColorWhite, + "linechart.axes.fg": ui.ColorDefault, + "linechart.line.fg": ui.ColorGreen, + "mbarchart.bar.bg": ui.ColorGreen, + "mbarchart.num.fg": ui.ColorWhite, + "mbarchart.text.fg": ui.ColorWhite, + "par.text.fg": ui.ColorWhite, + "par.text.bg": ui.ColorDefault, + "sparkline.line.fg": ui.ColorGreen, + "sparkline.title.fg": ui.ColorWhite, +} diff --git a/cwidgets/compact/gauge.go b/cwidgets/compact/gauge.go index 42d1650..8d34b73 100644 --- a/cwidgets/compact/gauge.go +++ b/cwidgets/compact/gauge.go @@ -14,7 +14,6 @@ func NewGaugeCol() *GaugeCol { g.Border = false g.Percent = 0 g.PaddingBottom = 0 - g.BarColor = ui.ColorGreen g.Label = "-" return &GaugeCol{g} } diff --git a/cwidgets/compact/setters.go b/cwidgets/compact/setters.go index cc2eb0e..9db58e0 100644 --- a/cwidgets/compact/setters.go +++ b/cwidgets/compact/setters.go @@ -18,7 +18,7 @@ func (row *Compact) SetCPU(val int) { row.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val)) if val < 5 { val = 5 - row.Cpu.BarColor = ui.ColorBlack + row.Cpu.BarColor = ui.ThemeAttr("gauge.bar.bg") } row.Cpu.Percent = val } @@ -29,7 +29,7 @@ func (row *Compact) SetMem(val int64, limit int64, percent int) { percent = 5 row.Memory.BarColor = ui.ColorBlack } else { - row.Memory.BarColor = ui.ColorGreen + row.Memory.BarColor = ui.ThemeAttr("gauge.bar.bg") } row.Memory.Percent = percent } diff --git a/cwidgets/compact/text.go b/cwidgets/compact/text.go index 4f4c651..7f83da5 100644 --- a/cwidgets/compact/text.go +++ b/cwidgets/compact/text.go @@ -17,7 +17,7 @@ func NewTextCol(s string) *TextCol { } func (w *TextCol) Highlight() { - w.TextFgColor = ui.ThemeAttr("par.text.bg") + w.TextFgColor = ui.ColorBlack w.TextBgColor = ui.ThemeAttr("par.text.fg") } diff --git a/cwidgets/expanded/cpu.go b/cwidgets/expanded/cpu.go index 370971d..689969b 100644 --- a/cwidgets/expanded/cpu.go +++ b/cwidgets/expanded/cpu.go @@ -17,8 +17,6 @@ func NewCpu() *Cpu { cpu.Width = colWidth[0] cpu.X = 0 cpu.DataLabels = cpu.hist.Labels - cpu.AxesColor = ui.ColorDefault - cpu.LineColor = ui.ColorGreen // hack to force the default minY scale to 0 tmpData := []float64{20} diff --git a/cwidgets/expanded/info.go b/cwidgets/expanded/info.go index 98ae6a3..66b98b6 100644 --- a/cwidgets/expanded/info.go +++ b/cwidgets/expanded/info.go @@ -15,7 +15,7 @@ func NewInfo(id string) *Info { p := ui.NewTable() p.Height = 4 p.Width = colWidth[0] - p.FgColor = ui.ColorWhite + p.FgColor = ui.ThemeAttr("par.text.fg") p.Seperator = false i := &Info{p, make(map[string]string)} i.Set("id", id) diff --git a/cwidgets/expanded/mem.go b/cwidgets/expanded/mem.go index 80eeba0..2648018 100644 --- a/cwidgets/expanded/mem.go +++ b/cwidgets/expanded/mem.go @@ -57,7 +57,6 @@ func newMemLabel() *ui.Par { p.Border = false p.Height = 1 p.Width = 20 - p.TextFgColor = ui.ColorDefault return p } @@ -67,9 +66,6 @@ func newMemChart() *ui.MBarChart { mbar.Border = false mbar.BarGap = 1 mbar.BarWidth = 6 - mbar.TextColor = ui.ColorDefault - - mbar.BarColor[0] = ui.ColorGreen mbar.BarColor[1] = ui.ColorBlack mbar.NumColor[1] = ui.ColorBlack diff --git a/cwidgets/expanded/net.go b/cwidgets/expanded/net.go index 259d3aa..3a419ec 100644 --- a/cwidgets/expanded/net.go +++ b/cwidgets/expanded/net.go @@ -26,14 +26,12 @@ func NewNet() *Net { rx.Title = "RX" rx.Height = 1 rx.Data = net.rxHist.Data - rx.TitleColor = ui.ColorDefault rx.LineColor = ui.ColorGreen tx := ui.NewSparkline() tx.Title = "TX" tx.Height = 1 tx.Data = net.txHist.Data - tx.TitleColor = ui.ColorDefault tx.LineColor = ui.ColorYellow net.Lines = []ui.Sparkline{rx, tx} diff --git a/main.go b/main.go index 3879b64..46ea11d 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ func main() { defer panicExit() // init ui + ui.ColorMap = ColorMap // override default colormap if err := ui.Init(); err != nil { panic(err) } diff --git a/menus.go b/menus.go index 13b03fe..e400fda 100644 --- a/menus.go +++ b/menus.go @@ -23,9 +23,7 @@ func HelpMenu() { defer ui.DefaultEvtStream.ResetHandlers() m := menu.NewMenu() - m.TextFgColor = ui.ColorWhite m.BorderLabel = "Help" - m.BorderFg = ui.ColorCyan m.AddItems(helpDialog...) ui.Render(m) ui.Handle("/sys/kbd/", func(ui.Event) { @@ -39,9 +37,7 @@ func FilterMenu() { defer ui.DefaultEvtStream.ResetHandlers() i := widgets.NewInput() - i.TextFgColor = ui.ColorWhite i.BorderLabel = "Filter" - i.BorderFg = ui.ColorCyan i.SetY(ui.TermHeight() - i.Height) ui.Render(i) @@ -72,9 +68,7 @@ func SortMenu() { m := menu.NewMenu() m.Selectable = true m.SortItems = true - m.TextFgColor = ui.ColorWhite m.BorderLabel = "Sort Field" - m.BorderFg = ui.ColorCyan for _, field := range SortFields() { m.AddItems(menu.Item{field, ""}) diff --git a/widgets/header.go b/widgets/header.go index d178339..76822a0 100644 --- a/widgets/header.go +++ b/widgets/header.go @@ -41,7 +41,7 @@ func headerBgBordered() *ui.Par { bg := ui.NewPar("") bg.X = 1 bg.Height = 3 - bg.Bg = ui.ColorWhite + bg.Bg = ui.ThemeAttr("header.bg") return bg } @@ -50,7 +50,7 @@ func headerBg() *ui.Par { bg.X = 1 bg.Height = 1 bg.Border = false - bg.Bg = ui.ColorWhite + bg.Bg = ui.ThemeAttr("header.bg") return bg } @@ -77,8 +77,8 @@ func headerPar(x int, s string) *ui.Par { p.Border = false p.Height = 1 p.Width = 20 - p.TextFgColor = ui.ColorDefault - p.TextBgColor = ui.ColorWhite - p.Bg = ui.ColorWhite + p.Bg = ui.ThemeAttr("header.bg") + p.TextFgColor = ui.ThemeAttr("header.fg") + p.TextBgColor = ui.ThemeAttr("header.bg") return p } diff --git a/widgets/input.go b/widgets/input.go index 2a8f76b..506038f 100644 --- a/widgets/input.go +++ b/widgets/input.go @@ -28,10 +28,12 @@ func NewInput() *Input { Block: *ui.NewBlock(), Label: "input", MaxLen: 20, - TextFgColor: ui.ThemeAttr("par.text.fg"), - TextBgColor: ui.ThemeAttr("par.text.bg"), + TextFgColor: ui.ThemeAttr("menu.text.fg"), + TextBgColor: ui.ThemeAttr("menu.text.bg"), padding: Padding{4, 2}, } + i.BorderFg = ui.ThemeAttr("menu.border.fg") + i.BorderLabelFg = ui.ThemeAttr("menu.label.fg") i.calcSize() return i } diff --git a/widgets/menu/main.go b/widgets/menu/main.go index 8e192e9..95157ee 100644 --- a/widgets/menu/main.go +++ b/widgets/menu/main.go @@ -22,11 +22,13 @@ type Menu struct { func NewMenu() *Menu { m := &Menu{ Block: *ui.NewBlock(), - TextFgColor: ui.ThemeAttr("par.text.fg"), - TextBgColor: ui.ThemeAttr("par.text.bg"), + TextFgColor: ui.ThemeAttr("menu.text.fg"), + TextBgColor: ui.ThemeAttr("menu.text.bg"), cursorPos: 0, padding: Padding{4, 2}, } + m.BorderFg = ui.ThemeAttr("menu.border.fg") + m.BorderLabelFg = ui.ThemeAttr("menu.label.fg") m.X = 1 return m } @@ -86,7 +88,7 @@ func (m *Menu) Buffer() ui.Buffer { for _, ch := range item.Text() { // invert bg/fg colors on currently selected row if m.Selectable && n == m.cursorPos { - cell = ui.Cell{Ch: ch, Fg: m.TextBgColor, Bg: m.TextFgColor} + cell = ui.Cell{Ch: ch, Fg: ui.ColorBlack, Bg: m.TextFgColor} } else { cell = ui.Cell{Ch: ch, Fg: m.TextFgColor, Bg: m.TextBgColor} }