Search code examples
terminaltmux

Why does tmux set TERM=screen?


How does tmux set the terminal to use (as reflected in the TERM environment variable).

For example. If I log in via ssh bash reports:

>set | grep TERM
TERM=xterm-256-color

If I then run tmux and from within tmux and do the same:

>set | grep TERM
TERM=screen

I think this is not always the case though since noticing it I have not managed to make tmux say anything else.

This relates to fake/mock/background terminal for testing an ncurses application

Where I am I trying to understand how the terminal emulation affects the resulting behaviour of an ncurses app.


Solution

  • tmux sets TERM to screen for two reasons:

    • tmux (like GNU screen) is a terminal emulator.
    • The screen terminal description is close enough to tmux's behavior that it suffices if tmux's own terminal description is not available.

    The manual page alludes to these two points, but does not really explain them:

    The TERM environment variable must be set to ‘screen’ or ‘tmux’ for all programs running inside tmux. New windows will automatically have ‘TERM=screen’ added to their environment, but care must be taken not to reset this in shell start-up files.

    Applications (other than hard-coded stuff) use terminal descriptions to find how to do similar operations on various terminals.

    Since tmux's terminal description has been part of the terminal database since 2015, you would only see TERM=screen on systems which are either very old, or have only a small subset of the terminal database installed.