about summary refs log tree commit diff stats
path: root/src/local
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-19 18:39:36 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-19 18:39:36 +0100
commitb65993b77789ddbde72f65db648ab993a5097121 (patch)
treec4fb5074e9cf65150e29fe223baab40aaf54a4cf /src/local
parent18df64e54b8aefc4affabf23cec0b6e4e4b7fec4 (diff)
downloadchawan-b65993b77789ddbde72f65db648ab993a5097121.tar.gz
render, pager: fix canvas background painting order
We were painting the background box in render for dump mode, but this
conflicted with the standard requirement that the canvas be painted
before other elements.  So now we handle this directly in the pager.

Conveniently enough, this also fixes the issue of canvas color adding
pointless spacing to pages (which often made the selection feature less
useful.)
Diffstat (limited to 'src/local')
-rw-r--r--src/local/container.nim7
-rw-r--r--src/local/pager.nim15
2 files changed, 18 insertions, 4 deletions
diff --git a/src/local/container.nim b/src/local/container.nim
index d52d4159..0039197d 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -141,7 +141,7 @@ type
     config*: BufferConfig
     loaderConfig*: LoaderClientConfig
     iface*: BufferInterface
-    width {.jsget.}: int
+    width* {.jsget.}: int
     height {.jsget.}: int
     title: string # used in status msg
     hoverText: array[HoverType, string]
@@ -524,7 +524,7 @@ proc requestLines(container: Container): EmptyPromise {.discardable.} =
     container.lineshift = w.a
     for y in 0 ..< min(res.lines.len, w.len):
       container.lines[y] = res.lines[y]
-    var isBgNew = container.bgcolor != res.bgcolor
+    let isBgNew = container.bgcolor != res.bgcolor
     if isBgNew:
       container.bgcolor = res.bgcolor
     if res.numLines != container.numLines:
@@ -1739,6 +1739,7 @@ proc setCloneStream*(container: Container; stream: BufStream) =
 proc onReadLine(container: Container; w: Slice[int];
     handle: (proc(line: SimpleFlexibleLine)); res: GetLinesResult):
     EmptyPromise =
+  container.bgcolor = res.bgcolor
   for line in res.lines:
     handle(line)
   if res.numLines > w.b + 1:
@@ -1761,6 +1762,8 @@ proc readLines*(container: Container; handle: proc(line: SimpleFlexibleLine)) =
     return container.onReadLine(w, handle, res)
   ).then(proc() =
     if container.config.markLinks:
+      # avoid coloring link markers
+      container.bgcolor = defaultColor
       container.iface.getLinks.then(proc(res: seq[string]) =
         handle(SimpleFlexibleLine())
         for i, link in res.mypairs:
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 0da33a65..22dbc5ef 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -952,7 +952,7 @@ proc drawBufferAdvance(s: openArray[char]; bgcolor: CellColor; oi, ox: var int;
         ls &= s[i]
   oi = i
   ox = x
-  return ls
+  return move(ls)
 
 proc drawBuffer*(pager: Pager; container: Container; ofile: File) =
   var format = Format()
@@ -961,13 +961,24 @@ proc drawBuffer*(pager: Pager; container: Container; ofile: File) =
     var w = -1
     var i = 0
     var s = ""
+    if container.bgcolor != defaultColor and
+        (line.formats.len == 0 or line.formats[0].pos > 0):
+      s.processFormat(pager.term, format, Format(bgcolor: container.bgcolor))
     for f in line.formats:
+      var ff = f.format
+      if ff.bgcolor == defaultColor:
+        ff.bgcolor = container.bgcolor
       let ls = line.str.drawBufferAdvance(format.bgcolor, i, x, f.pos)
       s.processOutputString(pager.term, ls, w)
-      s.processFormat(pager.term, format, f.format)
+      if i < line.str.len:
+        s.processFormat(pager.term, format, ff)
     if i < line.str.len:
       let ls = line.str.drawBufferAdvance(format.bgcolor, i, x, int.high)
       s.processOutputString(pager.term, ls, w)
+    if container.bgcolor != defaultColor and x < container.width:
+      s.processFormat(pager.term, format, Format(bgcolor: container.bgcolor))
+      let spaces = ' '.repeat(container.width - x)
+      s.processOutputString(pager.term, spaces, w)
     s.processFormat(pager.term, format, Format())
     ofile.writeLine(s)
   )