Strovent SystemsSign in
Reference

tmux over Mosh draws the status bar or last line wrong

tmux or Neovim over Mosh can leave a smeared status bar or a missing last line. The causes: character widths, a shell that execs tmux, and TERM.

Over SSH, tmux looks fine. Over Mosh, the status bar wraps onto a second line, bits of it are left behind on the line above, the last line of output goes missing, or Neovim's windows leave garbage on the screen. There are three usual causes.

1. Characters Mosh measures differently

Mosh keeps its own copy of the screen. To do that it has to know how many columns each character takes, and it asks the system's wcwidth function. Powerline arrows, Nerd Font icons, emoji and other newer symbols are where the answers differ: the server's C library, your terminal and tmux can each count a symbol as one or two columns. When they disagree, everything after that symbol on the row is shifted, and the status bar wraps or smears.

Mosh's maintainers have said that Mosh uses the libc wcwidth, and that width differences have to be fixed in the C library, so the fix is on your side:

  • Use a plain tmux status line, without icon or powerline symbols and without plugins that add them.
  • Keep the C library on the server up to date, so its character widths are current.
  • Test without the symbols: if the problem goes away, this was the cause.

2. Your shell starts tmux before Mosh can start

If .bashrc or another login file runs exec tmux (or tmux attach) for every login, it also runs when the mosh command logs in over SSH to start mosh-server. tmux replaces the shell, mosh-server never starts, and you can end up attached to tmux over that SSH connection, with Mosh failing with "Did not find mosh server startup message". In one report in the Mosh tracker, a missing last line came from exactly this. Start tmux only for interactive logins, or after Mosh connects. See Mosh "Did not find mosh server startup message".

3. The terminal type inside tmux

Programs inside tmux should see a tmux or screen terminal type, not xterm-256color. Set it in ~/.tmux.conf:

set -g default-terminal "tmux-256color"

Use screen-256color if the host has no tmux-256color entry. See Colors wrong in tmux: get 256 colors and true color (default-terminal, RGB).

Redraw without sending Ctrl+L

Mosh has no local redraw key, and Ctrl+L goes to the program, which may clear the screen instead. To repaint tmux, use the tmux command refresh-client (you can bind it to a key in ~/.tmux.conf), or detach and attach again.

Sources

Spotted a mistake? Email [email protected].