diff options
author | bptato <nincsnevem662@gmail.com> | 2023-01-01 03:16:55 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-01-01 03:16:55 +0100 |
commit | b1e13dc24349d0ec4b504ac358f7a505926b6416 (patch) | |
tree | 464d682d6826206bf01b1ccca965a9479370ff61 /src/render | |
parent | 24e6e40f24558d8fb97fd518d70a572a87146307 (diff) | |
download | chawan-b1e13dc24349d0ec4b504ac358f7a505926b6416.tar.gz |
rendertext: fix format position for non-ascii
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/rendertext.nim | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim index 2aa1ec54..e91c1e10 100644 --- a/src/render/rendertext.nim +++ b/src/render/rendertext.nim @@ -12,6 +12,7 @@ type StreamRenderer* = object af: bool decoder: DecoderStream newline: bool + w: int proc newStreamRenderer*(stream: Stream): StreamRenderer = result.format = newFormat() @@ -23,7 +24,7 @@ proc renderStream*(grid: var FlexibleGrid, renderer: var StreamRenderer, len: in template add_format() = if renderer.af: renderer.af = false - grid[grid.high].addFormat(grid[^1].str.len, renderer.format) + grid[grid.high].addFormat(renderer.w, renderer.format) if grid.len == 0: grid.addLine() var buf = newSeq[Rune](len * 4) @@ -33,6 +34,7 @@ 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) @@ -49,9 +51,11 @@ proc renderStream*(grid: var FlexibleGrid, renderer: var StreamRenderer, len: in 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.twidth(renderer.w) |