about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-06 23:02:11 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-06 23:29:49 +0100
commitec33f0c42b92e107295c30406d29f726127b9ccd (patch)
tree19fb27d487f22ee9f9ffd0ff62e40596c433bc67 /src
parentd7cdd61ecc10d6cf2a5b89f0b16bbbf4bed95437 (diff)
downloadchawan-ec33f0c42b92e107295c30406d29f726127b9ccd.tar.gz
pager: hide kitty images when menu is open
So I thought this was just a simple z-ordering issue, but silly me,
it's never simple with images.  In this case it turns out Kitty can't
really do z-ordering with text the way Sixel can - in short, you must
pick if the image is below text, or above text, but never both.

I imagine you could also get something to work with z=-1 and stretched
1-pixel colored images or some similarly horrifying hack.  It seems very
annoying to code and maintain, so I won't.

(In some way this is impressive, because Sixel z-ordering sucks too.
Somehow we got into a situation where both viable image display
protocols are incapable of expressing some useful ways of image
layering, of course in a mutually incompatible way.)
Diffstat (limited to 'src')
-rw-r--r--src/local/pager.nim22
-rw-r--r--src/local/term.nim1
2 files changed, 20 insertions, 3 deletions
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 94978022..8aae7af6 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -708,6 +708,7 @@ proc initImages(pager: Pager; container: Container) =
 proc draw*(pager: Pager) =
   var redraw = false
   var imageRedraw = false
+  var hasMenu = false
   let container = pager.container
   if container != nil:
     if container.redraw:
@@ -726,12 +727,14 @@ proc draw*(pager: Pager) =
       select.drawSelect(pager.display.grid)
       select.redraw = false
       pager.display.redraw = true
+      hasMenu = true
   if (let menu = pager.menu; menu != nil and
       (menu.redraw or pager.display.redraw)):
     menu.drawSelect(pager.display.grid)
     menu.redraw = false
     pager.display.redraw = true
     imageRedraw = false
+    hasMenu = true
   if pager.display.redraw:
     pager.term.writeGrid(pager.display.grid)
     pager.display.redraw = false
@@ -750,9 +753,22 @@ proc draw*(pager: Pager) =
     pager.term.writeGrid(pager.status.grid, 0, pager.attrs.height - 1)
     pager.status.redraw = false
     redraw = true
-  if imageRedraw and pager.term.imageMode != imNone:
-    # init images only after term canvas has been finalized
-    pager.initImages(container)
+  if pager.term.imageMode != imNone:
+    if imageRedraw:
+      # init images only after term canvas has been finalized
+      pager.initImages(container)
+    elif hasMenu and pager.term.imageMode == imKitty:
+      # Kitty can't really deal with text layered both on top of *and*
+      # under images.
+      #
+      # Well, it can, but only in a peculiar way: background color is
+      # part of the text layer, so with our image model we'd a) have to
+      # specify bgcolor for the menu and b) have to use sub-optimal
+      # in-cell positioning. (You'll understand why if you try to
+      # implement it.)
+      #
+      # Ugh. :(
+      pager.term.clearImages(pager.bufHeight)
   if redraw:
     pager.term.hideCursor()
     pager.term.outputGrid()
diff --git a/src/local/term.nim b/src/local/term.nim
index 3820b16d..56548d3b 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -763,6 +763,7 @@ proc clearImages*(term: Terminal; maxh: int) =
     if not image.marked:
       term.clearImage(image, maxh)
     image.marked = false
+  term.canvasImages.setLen(0)
 
 proc checkImageDamage*(term: Terminal; maxw, maxh: int) =
   if term.imageMode == imSixel: