mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
Naive approach to adding colors
This commit is contained in:
parent
4584cf34f5
commit
a5fd7bcfa0
@ -66,15 +66,37 @@ func (t *TextView) Buffer() ui.Buffer {
|
||||
x := t.Block.X + t.padding[0]
|
||||
y := t.Block.Y + t.padding[1]
|
||||
|
||||
colorMap := map[string]string{
|
||||
"[31m": "status.danger",
|
||||
"[33m": "status.warn",
|
||||
"[39m": "menu.text.fg",
|
||||
}
|
||||
colorCode := ""
|
||||
loopSkipper := 0
|
||||
|
||||
for _, line := range t.TextOut {
|
||||
for _, ch := range line {
|
||||
cell = ui.Cell{Ch: ch, Fg: t.TextFgColor, Bg: t.TextBgColor}
|
||||
colorCode = "[39m"
|
||||
for index, ch := range line {
|
||||
if loopSkipper > 0 {
|
||||
loopSkipper--
|
||||
continue
|
||||
}
|
||||
|
||||
// Checking to see the start of the color code
|
||||
if ch == '[' && line[index+3] == 'm' {
|
||||
colorCode = string(line[index]) + string(line[index+1]) + string(line[index+2]) + string(line[index+3])
|
||||
loopSkipper = 3
|
||||
continue
|
||||
}
|
||||
cell = ui.Cell{Ch: ch, Fg: ui.ThemeAttr(colorMap[colorCode]), Bg: t.TextBgColor}
|
||||
|
||||
buf.Set(x, y, cell)
|
||||
x++
|
||||
}
|
||||
x = t.Block.X + t.padding[0]
|
||||
y++
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user