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/utils/twtstr.nim | |
parent | 2e408503f452f0cac8ca2a63eaf59e0bfb332f1d (diff) | |
download | chawan-c141a3cea17f32f526853cd4085ae4cc80c4fed6.tar.gz |
Refactor output formatting code, drop non-ansi support
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r-- | src/utils/twtstr.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 9cf63d68..db5a1293 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -190,6 +190,25 @@ func skipBlanks*(buf: string, at: int): int = while result < buf.len and buf[result].isWhitespace(): inc result +template ESC*(s: varargs[string, `$`]): string = + var r = "\e[" + var first = true + for x in s: + if not first: + r &= ";" + first = false + r &= x + r + +template SGR*(s: varargs[string, `$`]): string = + ESC(s) & "m" + +template HVP*(s: varargs[string, `$`]): string = + ESC(s) & "f" + +template EL*(s: varargs[string, `$`]): string = + ESC(s) & "K" + iterator split*(s: seq[Rune], sep: Rune): seq[Rune] = var i = 0 var prev = 0 |