From 6a92c31be6666c0f3dc9554d78bac46417a963b6 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Wed, 21 Feb 2018 00:46:11 -0800 Subject: [PATCH] Changed termui colors --- termui/block.go | 12 +++++------ termui/buffer.go | 8 +++---- termui/colors.go | 52 ++++++++++++++++++++++++++++----------------- termui/gauge.go | 4 ++-- termui/grid.go | 2 +- termui/linegraph.go | 10 ++++----- termui/list.go | 8 +++---- termui/render.go | 2 +- termui/sparkline.go | 4 ++-- termui/table.go | 6 +++--- termui/theme.go | 32 ---------------------------- widgets/cpu.go | 2 +- widgets/help.go | 2 +- widgets/mem.go | 4 ++-- 14 files changed, 65 insertions(+), 83 deletions(-) delete mode 100644 termui/theme.go diff --git a/termui/block.go b/termui/block.go index 2650256..5b65f15 100644 --- a/termui/block.go +++ b/termui/block.go @@ -14,12 +14,12 @@ type Block struct { XOffset int YOffset int Label string - BorderFg Attribute - BorderBg Attribute - LabelFg Attribute - LabelBg Attribute - Bg Attribute - Fg Attribute + BorderFg Color + BorderBg Color + LabelFg Color + LabelBg Color + Bg Color + Fg Color } // NewBlock returns a *Block which inherits styles from current theme. diff --git a/termui/buffer.go b/termui/buffer.go index 88a4b9f..3881b03 100644 --- a/termui/buffer.go +++ b/termui/buffer.go @@ -7,8 +7,8 @@ import ( // Cell is a rune with assigned Fg and Bg type Cell struct { Ch rune - Fg Attribute - Bg Attribute + Fg Color + Bg Color } // Buffer is a renderable rectangle cell data container. @@ -17,7 +17,7 @@ type Buffer struct { CellMap map[image.Point]Cell } -func NewCell(ch rune, Fg, Bg Attribute) Cell { +func NewCell(ch rune, Fg, Bg Color) Cell { return Cell{ch, Fg, Bg} } @@ -47,7 +47,7 @@ func (b *Buffer) SetCell(x, y int, c Cell) { b.CellMap[image.Pt(x, y)] = c } -func (b *Buffer) SetString(x, y int, s string, fg, bg Attribute) { +func (b *Buffer) SetString(x, y int, s string, fg, bg Color) { for i, char := range s { b.SetCell(x+i, y, Cell{char, fg, bg}) } diff --git a/termui/colors.go b/termui/colors.go index e9a7dda..53fdae8 100644 --- a/termui/colors.go +++ b/termui/colors.go @@ -1,28 +1,42 @@ package termui -/* ---------------Port from termbox-go --------------------- */ +type Color int -// Attribute is printable cell's color and style. -type Attribute uint16 +const ColorDefault = -1 const ( - ColorDefault Attribute = iota - ColorBlack - ColorRed - ColorGreen - ColorYellow - ColorBlue - ColorMagenta - ColorCyan - ColorWhite -) - -const NumberofColors = 8 - -const ( - AttrBold Attribute = 1 << (iota + 9) + AttrBold Color = 1 << (iota + 9) AttrUnderline AttrReverse ) -/* ----------------------- End ----------------------------- */ +var Theme = DefaultTheme + +var DefaultTheme = Colorscheme{ + Fg: 7, + Bg: -1, + + LabelFg: 7, + LabelBg: -1, + BorderFg: 6, + BorderBg: -1, + + SparkLine: 4, + LineGraph: -1, + TableCursor: 4, +} + +// A ColorScheme represents the current look-and-feel of the dashboard. +type Colorscheme struct { + Fg Color + Bg Color + + LabelFg Color + LabelBg Color + BorderFg Color + BorderBg Color + + SparkLine Color + LineGraph Color + TableCursor Color +} diff --git a/termui/gauge.go b/termui/gauge.go index cdc3c7f..6525498 100644 --- a/termui/gauge.go +++ b/termui/gauge.go @@ -8,8 +8,8 @@ import ( type Gauge struct { *Block Percent int - BarColor Attribute - PercentColor Attribute + BarColor Color + PercentColor Color Description string } diff --git a/termui/grid.go b/termui/grid.go index a21c685..052cd03 100644 --- a/termui/grid.go +++ b/termui/grid.go @@ -15,7 +15,7 @@ type Grid struct { Height int Cols int Rows int - BgColor Attribute + BgColor Color } func NewGrid() *Grid { diff --git a/termui/linegraph.go b/termui/linegraph.go index 556fdd4..acf35fc 100644 --- a/termui/linegraph.go +++ b/termui/linegraph.go @@ -11,9 +11,9 @@ import ( type LineGraph struct { *Block Data map[string][]float64 - LineColor map[string]Attribute + LineColor map[string]Color - DefaultLineColor Attribute + DefaultLineColor Color } // NewLineGraph returns a new LineGraph with current theme. @@ -21,7 +21,7 @@ func NewLineGraph() *LineGraph { return &LineGraph{ Block: NewBlock(), Data: make(map[string][]float64), - LineColor: make(map[string]Attribute), + LineColor: make(map[string]Color), DefaultLineColor: Theme.LineGraph, } @@ -31,9 +31,9 @@ func NewLineGraph() *LineGraph { func (lc *LineGraph) Buffer() *Buffer { buf := lc.Block.Buffer() c := drawille.NewCanvas() - colors := make([][]Attribute, lc.X+2) + colors := make([][]Color, lc.X+2) for i := range colors { - colors[i] = make([]Attribute, lc.Y+2) + colors[i] = make([]Color, lc.Y+2) } // Sort the series so that overlapping data will overlap the same way each time diff --git a/termui/list.go b/termui/list.go index 16e2519..0d82afb 100644 --- a/termui/list.go +++ b/termui/list.go @@ -7,7 +7,7 @@ import ( // BarChart creates multiple bars in a widget: type List struct { *Block - TextColor Attribute + TextColor Color Data []int DataLabels []string Threshold int @@ -29,12 +29,12 @@ func (bc *List) Buffer() *Buffer { if y+1 > bc.Y { break } - bg := ColorGreen + bg := Color(2) if bc.Data[y] >= bc.Threshold { - bg = ColorRed + bg = Color(1) } r := MaxString(text, (bc.X - 4)) - buf.SetString(1, y+1, r, ColorWhite, ColorDefault) + buf.SetString(1, y+1, r, Color(7), ColorDefault) buf.SetString(bc.X-2, y+1, fmt.Sprintf("%dC", bc.Data[y]), bg, ColorDefault) } diff --git a/termui/render.go b/termui/render.go index 2d900ab..989d849 100644 --- a/termui/render.go +++ b/termui/render.go @@ -29,7 +29,7 @@ func Render(bs ...Bufferer) { // set cells in buf for p, c := range buf.CellMap { if p.In(buf.Area) { - tb.SetCell(p.X+b.GetXOffset(), p.Y+b.GetYOffset(), c.Ch, tb.Attribute(c.Fg), tb.Attribute(c.Bg)) + tb.SetCell(p.X+b.GetXOffset(), p.Y+b.GetYOffset(), c.Ch, tb.Attribute(c.Fg)+1, tb.Attribute(c.Bg)+1) } } }(b) diff --git a/termui/sparkline.go b/termui/sparkline.go index 76d047c..f71d5c8 100644 --- a/termui/sparkline.go +++ b/termui/sparkline.go @@ -7,9 +7,9 @@ type Sparkline struct { Data []int Title1 string Title2 string - TitleColor Attribute + TitleColor Color Total int - LineColor Attribute + LineColor Color } // Sparklines is a renderable widget which groups together the given sparklines. diff --git a/termui/table.go b/termui/table.go index 6088986..172ad90 100644 --- a/termui/table.go +++ b/termui/table.go @@ -10,9 +10,9 @@ type Table struct { *Block Header []string Rows [][]string - Fg Attribute - Bg Attribute - Cursor Attribute + Fg Color + Bg Color + Cursor Color UniqueCol int pid string selected int diff --git a/termui/theme.go b/termui/theme.go deleted file mode 100644 index d8ea0c2..0000000 --- a/termui/theme.go +++ /dev/null @@ -1,32 +0,0 @@ -package termui - -var Theme = DefaultTheme - -var DefaultTheme = ColorScheme{ - Fg: ColorWhite, - Bg: ColorDefault, - - LabelFg: ColorWhite, - LabelBg: ColorDefault, - BorderFg: ColorCyan, - BorderBg: ColorDefault, - - SparkLine: ColorBlue, - LineGraph: ColorDefault, - TableCursor: ColorBlue, -} - -// A ColorScheme represents the current look-and-feel of the dashboard. -type ColorScheme struct { - Fg Attribute - Bg Attribute - - LabelFg Attribute - LabelBg Attribute - BorderFg Attribute - BorderBg Attribute - - SparkLine Attribute - LineGraph Attribute - TableCursor Attribute -} diff --git a/widgets/cpu.go b/widgets/cpu.go index 7cdf1a6..c36f7ad 100644 --- a/widgets/cpu.go +++ b/widgets/cpu.go @@ -21,7 +21,7 @@ func NewCPU() *CPU { for i := 0; i < c.count; i++ { key := "CPU" + strconv.Itoa(i+1) c.Data[key] = []float64{0} - c.LineColor[key] = ui.Attribute(int(ui.ColorRed) + i) + c.LineColor[key] = ui.Color(1 + i) } go c.update() diff --git a/widgets/help.go b/widgets/help.go index 6ebe9b8..d365452 100644 --- a/widgets/help.go +++ b/widgets/help.go @@ -42,7 +42,7 @@ func (hm *HelpMenu) Buffer() *ui.Buffer { for y, line := range strings.Split(KEYBINDS, "\n") { for x, char := range line { - buf.SetCell(x+1, y, ui.NewCell(char, ui.ColorWhite, ui.ColorDefault)) + buf.SetCell(x+1, y, ui.NewCell(char, ui.Color(7), ui.ColorDefault)) } } diff --git a/widgets/mem.go b/widgets/mem.go index 5778f98..3f0efca 100644 --- a/widgets/mem.go +++ b/widgets/mem.go @@ -17,8 +17,8 @@ func NewMem() *Mem { m.Label = "Memory Usage" m.Data["Main"] = []float64{0} // Sets initial data to 0 m.Data["Swap"] = []float64{0} - m.LineColor["Main"] = ui.ColorMagenta - m.LineColor["Swap"] = ui.ColorYellow + m.LineColor["Main"] = ui.Color(5) + m.LineColor["Swap"] = ui.Color(11) go m.update() ticker := time.NewTicker(m.interval)