Changed termui colors

This commit is contained in:
Caleb Bassi 2018-02-21 00:46:11 -08:00
parent 9849248c20
commit 6a92c31be6
14 changed files with 65 additions and 83 deletions

View File

@ -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.

View File

@ -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})
}

View File

@ -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
}

View File

@ -8,8 +8,8 @@ import (
type Gauge struct {
*Block
Percent int
BarColor Attribute
PercentColor Attribute
BarColor Color
PercentColor Color
Description string
}

View File

@ -15,7 +15,7 @@ type Grid struct {
Height int
Cols int
Rows int
BgColor Attribute
BgColor Color
}
func NewGrid() *Grid {

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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.

View File

@ -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

View File

@ -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
}

View File

@ -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()

View File

@ -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))
}
}

View File

@ -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)