-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support push/pop window title sequence (CSI 22/23) #2668
Comments
Some details from reading the xterm source:
|
Related to #2668 This just implements the VT stream parsing. The actual handling of these events still needs to be done.
I added VT parsing for this in #2669. Implementation still needs to be done. |
Related to #2668 This just implements the VT stream parsing. The actual handling of these events still needs to be done.
xterm uses index 0 in its smcup/rmcup entries. Does that mean the same thing as omitting the index, since you said it’s a 1-based index? Which way does the stack grow? Is index 1 always the last-pushed item, or does each push take the next slot (and then shift everything once it fills up)? |
Oh also to note, the title stack should include the proxy icon data as well. |
Yes.
I'll have to think about this. Obviously xterm doesn't know about pwd reporting at all so it doesn't store this, but I'll have to look into other terminals to see what they do about this. Are we also 100% sure that Terminal.app also does this? |
Updated my discoveries from reading the source to add that the title stack is per-screen (primary/alt have their own stack). |
I am 100% sure that Terminal.app is restoring both window title and proxy icon state on a mode 1049 exit back to the values they had before entering mode 1049. I do not believe it's implementing any sort of stack, since it does not use the 22/23 sequence at all (and the macOS terminfo database doesn't include the 22/23 sequence in smcup/rmcup). Here's a script I just ran to test this: printf '\e]7;file:///Users/lily/Documents\a\e]2;foo\a'
read
printf '\e[?1049h'
read
printf '\e]7;file:///Users/lily/Music\a\e]2;bar\a'
read
printf '\e[?1049l'
read Since you're implementing the title stack instead of tying this to mode 1049, then the title stack should include the proxy icon. I just looked up what the "icon title" thing is in case it made more sense to use that, but nope, that was a thing for the title to use when minimizing a window into an icon. Incidentally, Terminal.app also supports OSC 6 for the "document" path, which is like OSC 7 except it treats the path as a file instead of a directory. It stores them separately but displays the document path if set (i.e. if you set both, it shows the document path, and if you then unset the document path, it shows the working directory). Ghostty does not currently support OSC 6 (maybe it should? I'm not sure right now if any software actually uses it; vim is actually sending an OSC 7 in Ghostty when editing a file even though it doesn't do that in Terminal.app and I haven't dug into that yet) but if it does support that then it too needs to be part of the title stack. |
I don't think this is the way I should implement this. Since this is a macOS specific thing, if we decide to mimic it (since we support the proxy icon we maybe should), we should probably relegate this to aport-specific behavior rather than being part of libghostty at all. The fact is that no other terminal persists the pwd as part of the title stack or mode 1049. This is purely a Terminal.app oddity. For example, it'd be really strange if this sequence occurred: (1) set pwd A (2) push title (3) set pwd B (4) pop title (5) report pwd and get "A" back. Every other terminal in the world (importantly xterm) would return "B" here. Therefore, I think the cleanest thing to do would be to separate it from this issue altogether and consider it a wholly separate feature. And I think the right way to design that one would be to implement apprt actions when alt screen is entered/exited, and have the macOS AppKit app handle pushing/popping this. The end result would be that the macOS app proxy icon behaves like Terminal.app, and the core VT emulation behaves like the rest of the world. For the sake of this issue, I'll say this issue should focus solely on CSI t 22/23 with xterm compatibility. |
Another update from reading the xterm code, verified with a shell script (below): full reset (ESC c) does NOT reset the title stack. That is surprising. #!/usr/bin/env bash
function csi() {
echo -ne "\033[$1"
}
echo -ne "\033]2;Outside\a"
csi "22;0t"
csi "?1049h"
echo -ne "\033]2;Inside\a"
echo -ne "\033c"
csi "?1049l"
csi "23;0t"
read |
What other terminal even supports OSC 7? I'm guessing Kitty does simply because the Ghostty bash script uses
I'm not aware of any code to report the pwd? It's hardly needed since processes already know their own pwd. |
Almost all of them nowadays (libvte supports it so that makes pretty much every Linux terminal, Kitty, WezTerm, Foot, etc.). More support it than don't in terms of terminal that are used by people. 😄
There's no real authority on how terminals work unfortunately. terminal-wg is a kind of authority and they've taken over the OSC7 specification. You can take up any arguments with them. Ghostty's stance on VT sequences has always been xterm followed by the majority of other terminals. I'll test to see if any other terminals associate pwd with 1049 or push/pop, but I still stand by that until more research is done, we should keep it separate from this issue. To be clear, that's not a no, I'm just not willing to make a hasty VT behavioral decision without more research into the issue across different terminal emulators, roping in those maintainers if necessary. |
One note here: I don't know if there's a standard for this, but I believe this is why we're using
Ghostty attempts to ghostty/src/termio/stream_handler.zig Lines 1079 to 1089 in 4853597
|
Oh fun, so bash and zsh don't have a way of detecting when it's a remote path (beyond simply hoping the remote shell isn't set up to emit this). FWIW |
Throwing this in here more as an FYI... Last week I was annoyed by the "ignoring CSI t with unimplemented parameter" log messages so I researched the xterm/iTerm/kitty implementations. Per what @mitchellh mentioned above, xterm currently implements it as a circular buffer/stack but that was implemented in the past year-ish. Previously (xterm-384c) it was a linked list and the third parameter wasn't implemented (commit date 2023/09/15). Pulling down the xterm source for debian 12 showed it using xterm-379 with the older behavior. iTerm implements this with NSMutableArray as a stack using the older behavior. kitty implements it via a Python deque of length 10 and implementing the newer behavior. Running a quick test with the below, I do see iTerm and the older xterm retain titles > 10:.
This is one of those cases where implementations diverge against what is "standard" across the various terminals. |
From #2667
Source: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
This is a fairly well defined sequence that is supported -- at least in its most basic push/pop form -- by many terminals (Kitty, iTerm, xterm). It can be combined with the
smcup
andrmcup
terminfo entries to push pop by default (xterm does this) on alt screen.The primary sequences we should support:
We can ignore the "icon title" variants as they aren't used by any modern window managers that I know of. We can implement those later as needed.
For bonus points, we should consider this:
cc @lilyball
The text was updated successfully, but these errors were encountered: