diff options
author | bptato <nincsnevem662@gmail.com> | 2022-11-22 14:50:53 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-11-22 14:50:53 +0100 |
commit | 787bceb8fd7e284699223bd060100deb6f76c066 (patch) | |
tree | f1ae4b143c7011649a23855d2198f126ecb22e5f /src/render | |
parent | 04fe0c11dd8e5b0a3f643cc4a054b2487198cdb3 (diff) | |
download | chawan-787bceb8fd7e284699223bd060100deb6f76c066.tar.gz |
Fix tab rendering
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/rendertext.nim | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim index f164c4dc..7a1c4417 100644 --- a/src/render/rendertext.nim +++ b/src/render/rendertext.nim @@ -11,6 +11,8 @@ proc renderPlainText*(text: string): FlexibleGrid = result[result.high].addFormat(result[^1].str.len, format) result.addLine() + const tabwidth = 8 + var spaces = 0 var i = 0 var af = false while i < text.len: @@ -21,8 +23,15 @@ proc renderPlainText*(text: string): FlexibleGrid = of '\r': discard of '\t': add_format - for i in 0..8: + for i in 0 ..< tabwidth: result[^1].str &= ' ' + spaces = 0 + of ' ': + add_format + result[^1].str &= ' ' + inc spaces + if spaces == 8: + spaces = 0 of '\e': i = format.parseAnsiCode(text, i) af = true @@ -45,6 +54,8 @@ proc renderStream*(stream: Stream): FlexibleGrid = result[result.high].addFormat(result[^1].str.len, format) result.addLine() + const tabwidth = 8 + var spaces = 0 var af = false while not stream.atEnd(): let c = stream.readChar() @@ -55,8 +66,15 @@ proc renderStream*(stream: Stream): FlexibleGrid = of '\r': discard of '\t': add_format - for i in 0..8: + for i in 0 ..< tabwidth - spaces: result[^1].str &= ' ' + spaces = 0 + of ' ': + add_format + result[^1].str &= c + inc spaces + if spaces == 8: + spaces = 0 of '\e': format.parseAnsiCode(stream) af = true |