You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mosh client passes xterm-color to server as xterm #446
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?
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.
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.
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.
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.
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.
Activity
andersk commentedon Jul 8, 2013
Mosh always advertises one of
xtermorxterm-256colorto its inner terminal, as those are the two terminfo entries that accurately reflect the capabilities it supports.Contrary to popular belief,
xterm-coloris not “xtermplus color support”.xtermhas supported color for a long time. Additionally,xtermsupports BCE (background color erase) whilexterm-colordoes 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-coloron the inside?TomFrost commentedon 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 commentedon Jul 8, 2013
Yes, Ubuntu’s default
.bashrcis 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=yesline, not to advertise an incorrect terminfo entry.TomFrost commentedon 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 commentedon 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
TERMto whatever value correctly describes the capabilities of the Mosh server itself. Because the Mosh server emulates modernxterm, that value isxtermorxterm-256color(depending on whether the client asks for 256 color support).If the Mosh server were to copy the value of
TERMfrom the client, then applications relying onTERM(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 asxtermcommands. This would result in display problems. So instead, the Mosh server always advertises theTERMthat it understands, and the Mosh client translates thextermstate sent by the server into output commands for the client’s outer terminal based on the client’s terminfo entry.keithw commentedon Jul 9, 2013
Might be helpful to mention that
screenandtmuxare the same -- they advertise a TERM ofscreenorscreen-256coloror 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 commentedon Feb 11, 2016
Situation hasn't changed -- Mosh behaves like screen and tmux.