aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-16 21:31:12 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-16 21:37:52 +0200
commitd86f1939204eee771a30f47e4cbe71fd8d9a4f5f (patch)
treea33b4d1195f7d5912a7f5da66e688f6168814b51
parentc5d70853cd4a2849ecc8697db4d9eb7f9e776c21 (diff)
downloadchawan-d86f1939204eee771a30f47e4cbe71fd8d9a4f5f.tar.gz
term: save/restore title after "set title"
It is quite straightforward, because XTerm has a functionality to do just this. (In fact, it automatically restores the title when I use smcup/rmcup. But when I don't, it will linger until I close the window or change the title again.)
-rw-r--r--src/local/term.nim14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/local/term.nim b/src/local/term.nim
index c654d890..cda376aa 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -82,6 +82,10 @@ template CSI(s: varargs[string, `$`]): string =
# primary device attributes
const DA1 = CSI("c")
+# push/pop current title to/from the terminal's title stack
+const XTPUSHTITLE = CSI(22, "t")
+const XTPOPTITLE = CSI(23, "t")
+
# report xterm text area size in pixels
const GEOMPIXEL = CSI(14, "t")
@@ -102,7 +106,7 @@ template XTGETTCAP(s: varargs[string, `$`]): string =
template OSC(s: varargs[string, `$`]): string =
"\e]" & s.join(';') & '\a'
-template XTERM_TITLE(s: string): string =
+template XTSETTITLE(s: string): string =
OSC(0, s)
const XTGETFG = OSC(10, "?") # get foreground color
@@ -416,7 +420,7 @@ proc processFormat*(term: Terminal, format: var Format, cellf: Format): string =
proc setTitle*(term: Terminal, title: string) =
if term.set_title:
- term.outfile.write(XTERM_TITLE(title.replaceControls()))
+ term.outfile.write(XTSETTITLE(title.replaceControls()))
proc enableMouse*(term: Terminal) =
term.write(XTSHIFTESCAPE & SGRMOUSEBTNON)
@@ -633,6 +637,8 @@ proc quit*(term: Terminal) =
else:
term.write(term.cursorGoto(0, term.attrs.height - 1) &
term.resetFormat() & "\n")
+ if term.set_title:
+ term.write(XTPOPTITLE)
if term.config.input.use_mouse:
term.disableMouse()
term.showCursor()
@@ -970,6 +976,8 @@ proc start*(term: Terminal; istream: PosixStream): TermStartResult =
term.enableMouse()
term.applyConfig()
term.canvas = newFixedGrid(term.attrs.width, term.attrs.height)
+ if term.set_title:
+ term.write(XTPUSHTITLE)
if term.smcup:
term.write(term.enableAltScreen())
@@ -983,6 +991,8 @@ proc restart*(term: Terminal) =
term.enableMouse()
if term.smcup:
term.write(term.enableAltScreen())
+ if term.set_title:
+ term.write(XTPUSHTITLE)
proc newTerminal*(outfile: File, config: Config): Terminal =
return Terminal(