Skip to content

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

Closed

Description

@TomFrost

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.

Activity

  1. andersk commented on Jul 8, 2013

    @andersk
    Member

    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?

  2. TomFrost commented on Jul 8, 2013

    @TomFrost
    Author

    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.

  3. andersk commented on Jul 8, 2013

    @andersk
    Member

    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.

  4. TomFrost commented on Jul 9, 2013

    @TomFrost
    Author

    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.

  5. andersk commented on Jul 9, 2013

    @andersk
    Member

    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.

  6. keithw commented on Jul 9, 2013

    @keithw
    Member

    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.

  7. keithw commented on Feb 11, 2016

    @keithw
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions