4

I want to enable italics in tmux (inside iTerm2 on macOS Big Sur 11.3). I have achieved this by setting this in .tmux.conf

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

And I have installed ncurses 6.2 using homebrew and set it first in the path. .zshrc:

  export PATH="$HOMEBREW_PREFIX/opt/ncurses/bin:$PATH"

After those changes, italics work.

However, now several ncurses-dependent programs fail to start: Both ncdu (1.15.1) and nano (2.0.6 ) error out with:

Error opening terminal: tmux-256color.

I get the impression that they don't support this TERM setting. Weirdly, ncdu 1.12 works with tmux-256color on my Raspbian computer.

What's wrong? Aren't programs like ncdu and nano supposed to be compatible with tmux-256color?

I have found a hacky workaround (for macOS, not needed on Raspbian). If I explicitly change back the TERM variable in .zshrc, everything (both italics and programs) works:

if [[ "$TERM" == "tmux-256color" ]]; then
  export TERM=screen-256color
fi

But my understanding is that setting TERM yourself is a big no-no. You are supposed to let the environment set that correctly. And I'm surprised it works at all - is tmux-256color compatible with screen-256color? Will this hack blow up in my face eventually?

1 Answer 1

4

The terminal descriptions for tmux are derived from those for screen, as you might guess by looking at the output from infocmp. But using the screen terminal descriptions, you'll lose the modified function keys, along with the ability to change the cursor appearance. Crossed-out characters won't work either. Actually italics shouldn't work because the screen terminal descriptions don't list italics (perhaps tmux has some built-in workaround for that—more likely the answer is in your .tmuxrc file).

The problem which causes ncdu and nano to reject the tmux-256color terminal description is that MacOS provides a very old version of ncurses (5.7, from 2008), which is used to link certain programs. nano is in Catalina (perhaps ncdu is in the subsequent release, but "several" is questionable since only a half-dozen programs in the MacOS base system actually use curses).

MacPorts and homebrew provide the current release of ncurses (6.2, from 2020). With 6.1 (2018), a new binary format is used for terminal descriptions which have numbers too large to fit in the signed 16-bit format. The older release ignores that binary format; its database does not have tmux-256color (added in May 2015).

Upgrading is the appropriate course of action (with more than 12 years behind ncurses, Apple's a bit slow, and cannot be counted on). MacPorts and homebrew both offer newer versions of nano and the same version of ncdu.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .