From: Dan Callaghan <dan@bl2.djc.id.au>
To: sup-commits@supmua.dev
Subject: [sup.git] branch develop updated: improve xterm title handling
Date: Mon, 05 Oct 2026 20:05:21 +1100 [thread overview]
Message-ID: <179119112182.285232.4826912792247740885@bl2.djc.id.au> (raw)
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
reply other threads:[~2026-10-05 9:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179119112182.285232.4826912792247740885@bl2.djc.id.au \
--to=dan@bl2.djc.id.au \
--cc=djc@djc.id.au \
--cc=sup-commits@supmua.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox