diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-27 21:36:35 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-27 22:34:10 +0100 |
commit | 65b0b48f445b6c56016a3c842089ef117a9298bc (patch) | |
tree | 3b82319e3ec57c24e2c191d83ecb755275d30933 /src/render | |
parent | 4042ec0dd0515ac9d538e763d6b99b256b640eca (diff) | |
download | chawan-65b0b48f445b6c56016a3c842089ef117a9298bc.tar.gz |
Proper support for tabs
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/renderdocument.nim | 8 | ||||
-rw-r--r-- | src/render/rendertext.nim | 16 |
2 files changed, 5 insertions, 19 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim index bdcf4df8..a988cca7 100644 --- a/src/render/renderdocument.nim +++ b/src/render/renderdocument.nim @@ -40,7 +40,7 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat, while cx < x and i < lines[y].str.len: let pi = i fastRuneAt(lines[y].str, i, r) - let w = r.width() + let w = r.twidth(cx) # we must ensure x is max(cx, x), otherwise our assumption of cx <= x # breaks down if cx + w > x: @@ -55,13 +55,13 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat, lines[y].str &= ' '.repeat(padwidth) lines[y].str &= linestr - let linestrwidth = linestr.width() + let linestrwidth = linestr.twidth(x) - x i = 0 var nx = x # last x of new string while nx < x + linestrwidth and i < ostr.len: fastRuneAt(ostr, i, r) - nx += r.width() + nx += r.twidth(nx) if i < ostr.len: lines[y].str &= ostr.substr(i) @@ -153,7 +153,7 @@ proc setRowWord(lines: var FlexibleGrid, word: InlineWord, x, y: int, window: Wi var i = 0 while x < 0 and i < word.str.len: fastRuneAt(word.str, i, r) - x += r.width() + x += r.twidth(x) if x < 0: return # highest x is outside the canvas, no need to draw let linestr = word.str.substr(i) diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim index e3d01638..24d7039e 100644 --- a/src/render/rendertext.nim +++ b/src/render/rendertext.nim @@ -6,9 +6,7 @@ import data/charset import encoding/decoderstream import utils/twtstr -const tabwidth = 8 type StreamRenderer* = object - w: int ansiparser: AnsiCodeParser format: Format af: bool @@ -35,7 +33,6 @@ proc renderStream*(grid: var FlexibleGrid, renderer: var StreamRenderer, len: in # avoid newline at end of stream grid.addLine() renderer.newline = false - renderer.w = 0 let r = buf[i] if r.isAscii(): let c = cast[char](r) @@ -44,27 +41,16 @@ proc renderStream*(grid: var FlexibleGrid, renderer: var StreamRenderer, len: in if not cancel: if renderer.ansiparser.state == PARSE_DONE: renderer.af = true - continue case c of '\n': add_format renderer.newline = true - continue - of '\r': continue - of '\t': - add_format - let w = ((renderer.w div tabwidth) + 1) * tabwidth - while renderer.w < w: - grid[^1].str &= ' ' - inc renderer.w - continue + of '\r': discard of '\e': renderer.ansiparser.reset() - continue else: add_format grid[^1].str &= c else: add_format grid[^1].str &= r - renderer.w += r.width() |