summaryrefslogtreecommitdiffstats
path: root/termui
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-02-21 00:46:11 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-02-21 00:46:11 -0800
commit6a92c31be6666c0f3dc9554d78bac46417a963b6 (patch)
tree67fd570a03d91667ad2c45ee86e45a338fe0ab6c /termui
parent9849248c20fc16b1f3f9477a53cfa3be65b6d48d (diff)
Changed termui colors
Diffstat (limited to 'termui')
-rw-r--r--termui/block.go12
-rw-r--r--termui/buffer.go8
-rw-r--r--termui/colors.go52
-rw-r--r--termui/gauge.go4
-rw-r--r--termui/grid.go2
-rw-r--r--termui/linegraph.go10
-rw-r--r--termui/list.go8
-rw-r--r--termui/render.go2
-rw-r--r--termui/sparkline.go4
-rw-r--r--termui/table.go6
-rw-r--r--termui/theme.go32
11 files changed, 61 insertions, 79 deletions
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
-}