aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-01 22:57:52 +0200
committerbptato <nincsnevem662@gmail.com>2024-10-01 23:16:25 +0200
commit491421e2e3e25358e2401b4c26c7d8dffdc5d507 (patch)
treedbbea01e61fdef497537210c4a31daad9d71dd8b
parent6e6d9e2ab875ffdb9dcaf1a2ed689a1390f72848 (diff)
downloadchawan-491421e2e3e25358e2401b4c26c7d8dffdc5d507.tar.gz
term: "fix" GNU screen not respecting query sequence order
wtf ... OK, it's a "fix" as much as you can fix this. I'm not adding a timer just to work around screen silently reordering my output. (Who thought this would be a good idea??) Unfortunately, this means that your background/foreground colors won't get detected when using screen. Not that they would have been until now.
-rw-r--r--src/local/term.nim31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/local/term.nim b/src/local/term.nim
index 822c513d..2d5b6c14 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -113,6 +113,7 @@ type
cursorx: int
cursory: int
colorMap: array[16, RGBColor]
+ tname: string
# control sequence introducer
const CSI = "\e["
@@ -983,11 +984,8 @@ proc quit*(term: Terminal) =
when TermcapFound:
proc loadTermcap(term: Terminal) =
- var tname = getEnv("TERM")
- if tname == "":
- tname = "dosansi"
let tc = Termcap()
- var res = tgetent(cast[cstring](addr tc.bp), cstring(tname))
+ var res = tgetent(cast[cstring](addr tc.bp), cstring(term.tname))
if res == 0: # retry as dosansi
res = tgetent(cast[cstring](addr tc.bp), "dosansi")
if res > 0: # success
@@ -1065,10 +1063,20 @@ proc queryAttrs(term: Terminal; windowOnly: bool): QueryResult =
const tcapRGB = 0x524742 # RGB supported?
if not windowOnly:
var outs = ""
- if term.config.display.default_background_color.isNone:
- outs &= XTGETBG
- if term.config.display.default_foreground_color.isNone:
- outs &= XTGETFG
+ if term.tname != "screen":
+ # screen has a horrible bug (feature?) where the responses to
+ # bg/fg queries are printed out of order (presumably because it
+ # must ask the terminal first).
+ #
+ # Of course, I can't work around this either, because screen won't
+ # respond from terminals that don't support this query. So I'll
+ # do the sole reasonable thing and skip default color queries.
+ #
+ # (By the way, tmux works as expected. Sigh.)
+ if term.config.display.default_background_color.isNone:
+ outs &= XTGETBG
+ if term.config.display.default_foreground_color.isNone:
+ outs &= XTGETFG
if term.config.display.image_mode.isNone:
outs &= KITTYQUERY
outs &= XTNUMREGS
@@ -1224,6 +1232,11 @@ proc detectTermAttributes(term: Terminal; windowOnly: bool): TermStartResult =
var res = tsrSuccess
if not term.isatty():
return res
+ if not windowOnly:
+ # set tname here because queryAttrs depends on it
+ term.tname = getEnv("TERM")
+ if term.tname == "":
+ term.tname = "dosansi"
var win: IOctl_WinSize
if ioctl(term.istream.fd, TIOCGWINSZ, addr win) != -1:
term.attrs.width = int(win.ws_col)
@@ -1248,7 +1261,7 @@ proc detectTermAttributes(term: Terminal; windowOnly: bool): TermStartResult =
if not windowOnly: # we don't check for kitty, so don't override this
if qaKittyImage in r.attrs:
term.imageMode = imKitty
- elif qaSixel in r.attrs or getEnv("TERM").startsWith("yaft"): # meh
+ elif qaSixel in r.attrs or term.tname.startsWith("yaft"): # meh
term.imageMode = imSixel
if term.imageMode == imSixel: # adjust after windowChange
if r.registers != 0: