Skip to content

Commit a5fd7bc

Browse files
author
Terminal Bash
committed
Naive approach to adding colors
1 parent 4584cf3 commit a5fd7bc

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

widgets/view.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,37 @@ func (t *TextView) Buffer() ui.Buffer {
6666
x := t.Block.X + t.padding[0]
6767
y := t.Block.Y + t.padding[1]
6868

69+
colorMap := map[string]string{
70+
"[31m": "status.danger",
71+
"[33m": "status.warn",
72+
"[39m": "menu.text.fg",
73+
}
74+
colorCode := ""
75+
loopSkipper := 0
76+
6977
for _, line := range t.TextOut {
70-
for _, ch := range line {
71-
cell = ui.Cell{Ch: ch, Fg: t.TextFgColor, Bg: t.TextBgColor}
78+
colorCode = "[39m"
79+
for index, ch := range line {
80+
if loopSkipper > 0 {
81+
loopSkipper--
82+
continue
83+
}
84+
85+
// Checking to see the start of the color code
86+
if ch == '[' && line[index+3] == 'm' {
87+
colorCode = string(line[index]) + string(line[index+1]) + string(line[index+2]) + string(line[index+3])
88+
loopSkipper = 3
89+
continue
90+
}
91+
cell = ui.Cell{Ch: ch, Fg: ui.ThemeAttr(colorMap[colorCode]), Bg: t.TextBgColor}
92+
7293
buf.Set(x, y, cell)
7394
x++
7495
}
7596
x = t.Block.X + t.padding[0]
7697
y++
7798
}
99+
78100
return buf
79101
}
80102

0 commit comments

Comments
 (0)