mobile-shell / mosh

Mobile Shell
https://mosh.org
GNU General Public License v3.0
12.58k stars 729 forks source link

Setting screen/tmux window name (ESC k) doesn't work with mosh #992

Open mephinet opened 6 years ago

mephinet commented 6 years ago

I'm trying to make mosh my primary terminal at $work, as I've been using it for months now and I'm pretty happy with it. One thing that strikes me, though, is that the window name setting does not work for me. My setup is this: I use xfce4-terminal or xterm, and start tmux locally to have many panels (locally! - I am aware that some people run tmux on the remote end). tmux can be configured to display the session name or window name in the status bar. According to this man page the window name can be set with $ printf '\033kWINDOW_NAME\033\\'. When working locally or using ssh, this works. When using mosh, it doesn't, instead the string that should become the window name is echoed in the terminal. My guess would be that mosh doesn't support the ESC k sequence, thus not forwarding it from the server to the client. In comparison, setting the window title with the OSC sequence ESC ] 2 ; works with mosh. My environment: Gentoo Linux, tmux 2.6, mosh 1.3.2 FWIW, this was already discussed ~5 years ago: https://github.com/mobile-shell/mosh/issues/477#issuecomment-181026357

mephinet commented 6 years ago

Taking a look at the code: https://github.com/mobile-shell/mosh/blob/master/src/terminal/terminalfunctions.cc#L606 is the code that makes the OSC sequence ESC ] 2 ; work - there is no equivalent for the ESC k sequence. If this analysis is correct, than setting the window name for tmux is a not-yet-implemented.

cgull commented 6 years ago

Correct, Mosh doesn't support this tmux-specific escape sequence. Unfortunately, it is not a standard ANSI control sequence, and it will not be ignored by terminals that don't support it. Mosh's virtual terminal aspires to emulate XTerm, and this doesn't fit very well with that, so I don't see implementing this any time soon.

mephinet commented 6 years ago

Hi! I can understand that you're reluctant to implement non-standard extensions - the decision is of course up to you. Upon further reading (and trying to come up with a patch - WIP), I've realized that this feature is not tmux-specific, but was taken over from screen - as is documented here https://www.gnu.org/software/screen/manual/html_node/Control-Sequences.html and can be traced back in the code to at least 1991 (version 3.1). Maybe this sheds a more "standard" light on this sequence...

winny- commented 6 years ago

I use alacritty+tmux as my main terminal - so I also experience this issue. Perhaps we should look into implementing OSC sequence ESC ] 2 ; in tmux instead?

mephinet commented 6 years ago

@winny- as documented in the man page, tmux distinguishes between names and titles (which always confuses me).

ryanerwin commented 5 years ago

Would be awesome to see this feature get implemented in mosh, so that tmux is more consistent on ssh and mosh:

set-option -g set-titles on
set-option -g set-titles-string "#{host} - #{session_name}

For reference, here's the difference between the tmux titlebar in SSH and mosh. image


Is @cgull saying the mosh team doesn't want to implement this?

Mosh's virtual terminal aspires to emulate XTerm, and this doesn't fit very well with that

If so, that would be kind of ironic since the mosh solution to no scrollback is tmux:

The workaround for now is to run "screen" or "tmux" on the remote end and use that for scrollback.

ser commented 4 years ago

it's really annoying, half of my tabs are polluted with [mosh] prefixes.

normen commented 4 years ago

Same is true for the MacOS terminal, I am trying to get the opened document in VIM displayed in the terminal top bar, it doesn't work when I work via MOSH, with SSH it works.

The sequence is ESC ] 6 ; <url of file> BEL or ^[]6;<url>^G for short.

anarcat commented 3 months ago

i have a similar issue, with a simple reproducer:

ssh server.example.com
perl -e 'print STDERR "\033]0;foo\007";' ; read
# window title properly set here
exit
mosh server.example.com
perl -e 'print STDERR "\033]0;bar\007";' ; read
# window title not modified
exit

i don't understand why mosh wants to interpret all those escape sequences, this seems to me like a classic case of trying to smart for your own good.... ;)