mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
add global default ColorMap
This commit is contained in:
parent
02610c59da
commit
b8eb386360
@ -1,4 +1,4 @@
|
||||
<p align="center"><img width="40%" src="/_docs/img/logo.png" alt="cTop"/></p>
|
||||
<p align="center"><img width="40%" style="background-color: transparent;" src="/_docs/img/logo.png" alt="cTop"/></p>
|
||||
#
|
||||
|
||||
Top-like interface for container metrics
|
||||
|
43
colors.go
Normal file
43
colors.go
Normal file
@ -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,
|
||||
}
|
@ -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}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
1
main.go
1
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)
|
||||
}
|
||||
|
6
menus.go
6
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, ""})
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user