diff options
author | bptato <nincsnevem662@gmail.com> | 2021-11-13 09:51:06 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-11-13 09:51:17 +0100 |
commit | c141a3cea17f32f526853cd4085ae4cc80c4fed6 (patch) | |
tree | 248f7d55aefcd7b1c32891f60dffc193df6e51a8 /src/io/cell.nim | |
parent | 2e408503f452f0cac8ca2a63eaf59e0bfb332f1d (diff) | |
download | chawan-c141a3cea17f32f526853cd4085ae4cc80c4fed6.tar.gz |
Refactor output formatting code, drop non-ansi support
Diffstat (limited to 'src/io/cell.nim')
-rw-r--r-- | src/io/cell.nim | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/io/cell.nim b/src/io/cell.nim index 983c5b4d..133b88d6 100644 --- a/src/io/cell.nim +++ b/src/io/cell.nim @@ -49,3 +49,95 @@ func width*(line: FlexibleLine): int = func newFormatting*(): Formatting = return Formatting(fgcolor: defaultColor, bgcolor: defaultColor) + +proc processFormatting*(formatting: var Formatting, cellf: Formatting): string = + if formatting.bold and not cellf.bold: + result &= SGR(22) + if formatting.italic and not cellf.italic: + result &= SGR(23) + if formatting.underline and not cellf.underline: + result &= SGR(24) + if formatting.strike and not cellf.strike: + result &= SGR(29) + if formatting.overline and not cellf.overline: + result &= SGR(55) + + if cellf.fgcolor != formatting.fgcolor: + var color = cellf.fgcolor + if color.rgb: + let rgb = color.rgbcolor + result &= SGR(38, 2, rgb.r, rgb.g, rgb.b) + elif color == defaultColor: + result &= SGR() + formatting = newFormatting() + else: + result &= SGR(color.color) + + if cellf.bgcolor != formatting.bgcolor: + var color = cellf.bgcolor + if color.rgb: + let rgb = color.rgbcolor + result &= SGR(48, 2, rgb.r, rgb.g, rgb.b) + elif color == defaultColor: + result &= SGR() + formatting = newFormatting() + else: + result &= SGR(color.color) + + if not formatting.bold and cellf.bold: + result &= SGR(1) + if not formatting.italic and cellf.italic: + result &= SGR(3) + if not formatting.underline and cellf.underline: + result &= SGR(4) + if not formatting.strike and cellf.strike: + result &= SGR(9) + if not formatting.overline and cellf.overline: + result &= SGR(53) + + formatting = cellf + if formatting.bold and not cellf.bold: + result &= SGR(22) + if formatting.italic and not cellf.italic: + result &= SGR(23) + if formatting.underline and not cellf.underline: + result &= SGR(24) + if formatting.strike and not cellf.strike: + result &= SGR(29) + if formatting.overline and not cellf.overline: + result &= SGR(55) + + if cellf.fgcolor != formatting.fgcolor: + var color = cellf.fgcolor + if color.rgb: + let rgb = color.rgbcolor + result &= SGR(38, 2, rgb.r, rgb.g, rgb.b) + elif color == defaultColor: + result &= SGR() + formatting = newFormatting() + else: + result &= SGR(color.color) + + if cellf.bgcolor != formatting.bgcolor: + var color = cellf.bgcolor + if color.rgb: + let rgb = color.rgbcolor + result &= SGR(48, 2, rgb.r, rgb.g, rgb.b) + elif color == defaultColor: + result &= SGR() + formatting = newFormatting() + else: + result &= SGR(color.color) + + if not formatting.bold and cellf.bold: + result &= SGR(1) + if not formatting.italic and cellf.italic: + result &= SGR(3) + if not formatting.underline and cellf.underline: + result &= SGR(4) + if not formatting.strike and cellf.strike: + result &= SGR(9) + if not formatting.overline and cellf.overline: + result &= SGR(53) + + formatting = cellf |