diff options
author | bptato <nincsnevem662@gmail.com> | 2023-01-11 15:04:00 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-01-11 15:04:00 +0100 |
commit | 913fabdcea70bdf4eb85306dd1a10361786b0077 (patch) | |
tree | 91f038a95ab7754928b1aa2e3194d065fc6a00ba /src/display | |
parent | 970ebdaba81e042a805e1b8f6d22451f4660ad8f (diff) | |
download | chawan-913fabdcea70bdf4eb85306dd1a10361786b0077.tar.gz |
pager, term: fix inefficiencies, off by one errors
and other weird things I forgot to remove while debugging
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/pager.nim | 15 | ||||
-rw-r--r-- | src/display/term.nim | 13 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/display/pager.nim b/src/display/pager.nim index 8b3ed641..805f0f51 100644 --- a/src/display/pager.nim +++ b/src/display/pager.nim @@ -216,7 +216,6 @@ proc refreshDisplay(pager: Pager, container = pager.container) = var cf = line.findFormat(w) var nf = line.findNextFormat(w) let startw = w # save this for later - var lan = "" # Now fill in the visible part of the row. while i < line.str.len: let pw = w @@ -228,13 +227,17 @@ proc refreshDisplay(pager: Pager, container = pager.container) = if nf.pos != -1 and nf.pos <= pw: cf = nf nf = line.findNextFormat(pw) - pager.display[dls + k].str &= r - lan &= r if cf.pos != -1: pager.display[dls + k].format = cf.format - let tk = k + rw - while k < tk and k < pager.display.width - 1: - inc k + if r == Rune('\t'): + # Needs to be replaced with spaces, otherwise bgcolor isn't displayed. + let tk = k + rw + while k < tk: + pager.display[dls + k].str &= ' ' + inc k + else: + pager.display[dls + k].str &= r + k += rw # Finally, override cell formatting for highlighted cells. let hls = container.findHighlights(container.fromy + by) let aw = container.width - (startw - container.fromx) # actual width diff --git a/src/display/term.nim b/src/display/term.nim index dd01d2b4..239b1a53 100644 --- a/src/display/term.nim +++ b/src/display/term.nim @@ -324,12 +324,10 @@ proc processOutputString(term: Terminal, str: string, w: var int): string = if str.validateUtf8() != -1: return "?" for r in str.runes(): - let tw = r.twidth(w) - if r == Rune('\t'): - # Needs to be replaced with spaces, otherwise bgcolor isn't displayed. - for i in 0 ..< tw: - result &= ' ' - elif r.isControlChar(): + # twidth wouldn't work here, the view may start at the nth character. + # pager must ensure tabs are converted beforehand. + let tw = r.width() + if r.isControlChar(): result &= "^" & getControlLetter(char(r)) elif tw != 0: result &= r @@ -369,7 +367,8 @@ proc generateSwapOutput(term: Terminal, grid: FixedGrid, prev: FixedGrid): strin result &= term.cursorGoto(0, i div grid.width - 1) result &= term.resetFormat() result &= line - result &= term.clearEnd() + if w != grid.width: + result &= term.clearEnd() lr = false x = 0 w = 0 |