Skip to content
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

Mosh client passes xterm-color to server as xterm #446

Closed
TomFrost opened this issue Jul 8, 2013 · 8 comments
Closed

Mosh client passes xterm-color to server as xterm #446

TomFrost opened this issue Jul 8, 2013 · 8 comments

Comments

@TomFrost
Copy link

TomFrost commented Jul 8, 2013

Max OS X 10.8.3 (mosh 1.2.4 from zsh) connecting to Ubuntu 12.04 (mosh 1.2.4 on bash):

tf@local$ echo $TERM
xterm-color

tf@local$ mosh tf@remote
[snip connection output]

tf@remote$ echo $TERM
xterm

However, if I change it from xterm-color...

tf@local$ TERM=xterm-256color mosh tf@remote
[snip connection output]

tf@remote$ echo $TERM
xterm-256color

I can't seem to get xterm-color to pass without it being forced to plain xterm.

Edit: Note that, connecting between the same machines using standard ssh, I see xterm-color on the remote end.

@andersk
Copy link
Member

andersk commented Jul 8, 2013

Mosh always advertises one of xterm or xterm-256color to its inner terminal, as those are the two terminfo entries that accurately reflect the capabilities it supports.

Contrary to popular belief, xterm-color is not “xterm plus color support”. xterm has supported color for a long time. Additionally, xterm supports BCE (background color erase) while xterm-color does not. (When the outer terminal doesn’t advertise BCE support, the Mosh client translates BCE sequences to non-BCE sequences.)

So why do you think you need TERM=xterm-color on the inside?

@TomFrost
Copy link
Author

TomFrost commented Jul 8, 2013

More looks at TERM than just mosh, though. For example, the default .bashrc in the debian/ubuntu skel looks specifically for xterm-color when setting $PS1, including the ANSI escape sequences if it's there and omitting them if it's not. As a result, installing mosh on a machine and allowing users to see their color prompt requires editing the .bashrc for all users to support a color prompt for xterm|xterm-color. It's not the end of the world, but it is an annoyance considering this isn't something to worry about when using ssh directly.

@andersk
Copy link
Member

andersk commented Jul 8, 2013

Yes, Ubuntu’s default .bashrc is slightly confused in this respect. As evident from the comments there (and from developer comments on LP #103929), the intention was to disable the color prompt by default unless the user asks for color. But the right way to ask for color is to uncomment the #force_color_prompt=yes line, not to advertise an incorrect terminfo entry.

@TomFrost
Copy link
Author

TomFrost commented Jul 9, 2013

Great explanation. This does appear to be more of a bug with Ubuntu than anything else.

With that said, though, is it Mosh's responsibility to enforce that? As the TERM is set by the physical terminal emulator and pushed to remote via SSH, keeping that same functionality and having mosh use the current TERM setting may be the most intuitive way forward regardless of Ubuntu's bug. Unless mosh relies on the spec being defined by TERM, of course, in which case that would not be appropriate.

@andersk
Copy link
Member

andersk commented Jul 9, 2013

Yes, it’s Mosh’s responsibility.

Mosh doesn’t work like SSH. The Mosh server is itself a terminal, because it must maintain the terminal state independently from the client in order to do efficient state synchronization. Like any other terminal, Mosh has a responsibility to set TERM to whatever value correctly describes the capabilities of the Mosh server itself. Because the Mosh server emulates modern xterm, that value is xterm or xterm-256color (depending on whether the client asks for 256 color support).

If the Mosh server were to copy the value of TERM from the client, then applications relying on TERM (such as anything using curses or readline) would send commands intended for whatever terminal the client has, only for them to be intercepted by the Mosh server and interpreted as xterm commands. This would result in display problems. So instead, the Mosh server always advertises the TERM that it understands, and the Mosh client translates the xterm state sent by the server into output commands for the client’s outer terminal based on the client’s terminfo entry.

@andersk andersk closed this as completed Jul 9, 2013
@keithw
Copy link
Member

keithw commented Jul 9, 2013

Might be helpful to mention that screen and tmux are the same -- they advertise a TERM of screen or screen-256color or whatnot, not the original terminal, because that's the language they interpret. Then they feed a representation of the terminal back to the outer terminal in its language.

All of these programs act similarly in this respect.

@keithw
Copy link
Member

keithw commented Feb 11, 2016

Situation hasn't changed -- Mosh behaves like screen and tmux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@andersk @keithw @TomFrost and others