From a5fd7bcfa0aae70179eb2760c25769b3c2dba433 Mon Sep 17 00:00:00 2001 From: Terminal Bash Date: Tue, 15 Oct 2019 01:24:39 -0600 Subject: [PATCH] Naive approach to adding colors --- widgets/view.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/widgets/view.go b/widgets/view.go index 1347de1..526a93b 100644 --- a/widgets/view.go +++ b/widgets/view.go @@ -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 }