From 787bceb8fd7e284699223bd060100deb6f76c066 Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 22 Nov 2022 14:50:53 +0100 Subject: Fix tab rendering --- src/render/rendertext.nim | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/render') 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 -- cgit