diff options
author | bptato <nincsnevem662@gmail.com> | 2024-07-02 23:33:56 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-07-02 23:35:05 +0200 |
commit | 1eb05b007a71dbd6589e722d2aeefdf6747da022 (patch) | |
tree | bfeaa39592b50fce0f4e08caf318165ad3d704fb /src | |
parent | b4f1571df625837cb0f48eb253f37d694dd679f9 (diff) | |
download | chawan-1eb05b007a71dbd6589e722d2aeefdf6747da022.tar.gz |
term: fix excessive SGR output in ansi color mode
Diffstat (limited to 'src')
-rw-r--r-- | src/local/term.nim | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/local/term.nim b/src/local/term.nim index 8a0dbe01..c5924a87 100644 --- a/src/local/term.nim +++ b/src/local/term.nim @@ -410,15 +410,17 @@ proc processFormat*(term: Terminal; format: var Format; cellf: Format): string = cellf.fgcolor = defaultColor # correct cellf.fgcolor = term.correctContrast(cellf.bgcolor, cellf.fgcolor) - # print - case cellf.fgcolor.t - of ctNone: result &= SGR(39) - of ctANSI: result &= ansiSGR(cellf.fgcolor.color, 0) - else: assert false - case cellf.bgcolor.t - of ctNone: result &= SGR(49) - of ctANSI: result &= ansiSGR(cellf.bgcolor.color, 10) - else: assert false + if cellf.fgcolor != format.fgcolor: + # print + case cellf.fgcolor.t + of ctNone: result &= SGR(39) + of ctANSI: result &= ansiSGR(cellf.fgcolor.color, 0) + else: discard + if cellf.bgcolor != format.bgcolor: + case cellf.bgcolor.t + of ctNone: result &= SGR(49) + of ctANSI: result &= ansiSGR(cellf.bgcolor.color, 10) + else: discard of cmEightBit: # quantize if cellf.bgcolor.t == ctRGB: @@ -428,14 +430,16 @@ proc processFormat*(term: Terminal; format: var Format; cellf: Format): string = # correct cellf.fgcolor = term.correctContrast(cellf.bgcolor, cellf.fgcolor) # print - case cellf.fgcolor.t - of ctNone: result &= SGR(39) - of ctANSI: result &= eightBitSGR(cellf.fgcolor.color, 0) - of ctRGB: assert false - case cellf.bgcolor.t - of ctNone: result &= SGR(49) - of ctANSI: result &= eightBitSGR(cellf.bgcolor.color, 10) - of ctRGB: assert false + if cellf.fgcolor != format.fgcolor: + case cellf.fgcolor.t + of ctNone: result &= SGR(39) + of ctANSI: result &= eightBitSGR(cellf.fgcolor.color, 0) + of ctRGB: discard + if cellf.bgcolor != format.bgcolor: + case cellf.bgcolor.t + of ctNone: result &= SGR(49) + of ctANSI: result &= eightBitSGR(cellf.bgcolor.color, 10) + of ctRGB: discard of cmTrueColor: # correct cellf.fgcolor = term.correctContrast(cellf.bgcolor, cellf.fgcolor) |