* [sup.git] branch develop updated: improve xterm title handling
@ 2026-10-05 9:05 Dan Callaghan
0 siblings, 0 replies; only message in thread
From: Dan Callaghan @ 2026-10-05 9:05 UTC (permalink / raw)
To: sup-commits
Pushed a commit to branch develop:
https://supmua.dev/git/sup/commit/d21b4bebeb134b1cccefdb1c669542cc2d109b3e.html
The following commit(s) were added to refs/heads/develop by this push:
new d21b4beb improve xterm title handling
d21b4beb is described below
commit d21b4bebeb134b1cccefdb1c669542cc2d109b3e
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Mon Oct 5 19:46:37 2026 +1100
improve xterm title handling
Check for the XT termcap when deciding whether to emit the title, since
that is the "proper" way to detect support. But also match on TERM=tmux
since its terminfo doesn't advertise XT for some reason.
Escape control characters in the title.
Strip out all characters above U+00FF on Screen due to a bug in its
handling of Unicode in xterm titles.
Fixes #572.
---
lib/sup/buffer.rb | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index 9503f217..7561d54d 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -151,7 +151,7 @@ EOS
@textfields = {}
@flash = nil
@shelled = @asking = false
- @in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/
+ @have_xterm_title = Ncurses.tigetflag("XT") > 0 || ENV["TERM"] =~ /(screen|tmux)/
@sigwinch_happened = false
@sigwinch_mutex = Mutex.new
end
@@ -262,8 +262,7 @@ EOS
get_status_and_title @focus_buf # must be called outside of the ncurses lock
end
- ## http://rtfm.etla.org/xterm/ctlseq.html (see Operating System Controls)
- print "\033]0;#{title}\07" if title && @in_x
+ emit_xterm_title title if title
Ncurses.mutex.lock unless opts[:sync] == false
@@ -292,6 +291,17 @@ EOS
Ncurses.mutex.unlock unless opts[:sync] == false
end
+ def emit_xterm_title title
+ return unless @have_xterm_title
+ ## Escape terminal control characters.
+ title = title.gsub(/[[:cntrl:]]/) { |c| Ncurses.unctrl c.ord }
+ ## Screen does not properly handle characters above U+FF in the title.
+ ## It truncates them to 8 bits which may cause it to emit control
+ ## characters into the terminal title.
+ title = title.gsub /[^\u0000-\u00ff]/, "?" if ENV["TERM"] =~ /screen/
+ print "\033]0;#{title}\07"
+ end
+
## if the named buffer already exists, pops it to the front without
## calling the block. otherwise, gets the mode from the block and
## creates a new buffer. returns two things: the buffer, and a boolean
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-05 9:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-05 9:05 [sup.git] branch develop updated: improve xterm title handling Dan Callaghan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox