about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-30 19:45:46 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-30 19:57:07 +0200
commit98fdd778d2c222b9b6b61d181680a74a09ecf44f (patch)
tree4aa9bfe1a7d18973734f07a620aea78c47df5fa9
parent99363d4408c19e215d931c8273adbea40e7556a8 (diff)
downloadchawan-98fdd778d2c222b9b6b61d181680a74a09ecf44f.tar.gz
term: constify queries
+ also send register & image dimension queries in forced sixel mode,
and image dimension query on window resize
-rw-r--r--src/local/term.nim18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/local/term.nim b/src/local/term.nim
index 71ff9e25..1c3629e0 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -131,6 +131,12 @@ const XTSHIFTESCAPE = CSI(">0s")
 template XTSMGRAPHICS(pi, pa, pv: untyped): string =
   CSI("?" & $pi, $pa, $pv & "S")
 
+# number of color registers
+const XTNUMREGS = XTSMGRAPHICS(1, 1, 0)
+
+# image dimensions
+const XTIMGDIMS = XTSMGRAPHICS(2, 1, 0)
+
 # device control string
 const DCSSTART = "\eP"
 
@@ -140,6 +146,8 @@ template DCS(a, b: char; s: varargs[string]): string =
 template XTGETTCAP(s: varargs[string, `$`]): string =
   DCS('+', 'q', s)
 
+const XTGETRGB = XTGETTCAP("524742")
+
 # OS command
 template OSC(s: varargs[string, `$`]): string =
   "\e]" & s.join(';') & '\a'
@@ -969,10 +977,13 @@ proc queryAttrs(term: Terminal; windowOnly: bool): QueryResult =
       outs &= XTGETFG
     if term.config.display.image_mode.isNone:
       outs &= KITTYQUERY
-      outs &= XTSMGRAPHICS(1, 1, 0) # color registers
-      outs &= XTSMGRAPHICS(2, 1, 0) # dimensions
+      outs &= XTNUMREGS
+      outs &= XTIMGDIMS
+    elif term.config.display.image_mode.get == imSixel:
+      outs &= XTNUMREGS
+      outs &= XTIMGDIMS
     if term.config.display.color_mode.isNone:
-      outs &= XTGETTCAP("524742")
+      outs &= XTGETRGB
     outs &=
       XTGETANSI &
       GEOMPIXEL &
@@ -985,6 +996,7 @@ proc queryAttrs(term: Terminal; windowOnly: bool): QueryResult =
       GEOMPIXEL &
       CELLSIZE &
       GEOMCELL &
+      XTIMGDIMS &
       DA1
     term.outfile.write(outs)
   term.flush()