Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing tmux-256color for macOS

Installing tmux-256color for macOS

  • macOS 10.15.5
  • tmux 3.1b

macOS has ncurses version 5.7 which does not ship the terminfo description for tmux. There're two ways that can help you to solve this problem.

The Fast Blazing Solution

Instead of tmux-256color, use screen-256color which comes with system. Place this command into ~/.tmux.conf or ~/.config/tmux/tmux.conf(for version 3.1 and later):

set-option default-terminal "screen-256color"

The screen-256color in most cases is enough and more portable solution. But it does not support any italic font style.

The Right Way

Unfortunately, The latest (6.2) ncurses version does not work properly. Make sure to use ncurses which comes with macOS:

$ which tic
/usr/bin/tic

If you see another path to terminal info compiler, you must fix the $PATH for a shell, or uninstall a local ncurses by using a package manager.

Let's download and unpack the latest nucurses terminal descriptions:

$ curl -LO https://invisible-island.net/datafiles/current/terminfo.src.gz && gunzip terminfo.src.gz

And compile tmux-256color terminal info. The result is placed into ~/.terminfo:

$ /usr/bin/tic -xe tmux-256color terminfo.src

If you want to use tmux-256color for all users, use sudo. The result is placed into /usr/share/terminfo:

$ sudo /usr/bin/tic -xe tmux-256color terminfo.src

You may also to compile few more infos, it is up to you:

$ /usr/bin/tic -xe alacritty-direct,tmux-256color terminfo.src

If you see something like:

"terminfo.src", line 1650, terminal 'pccon+base': enter_bold_mode but no exit_attribute_mode
"terminfo.src", line 1650, terminal 'pccon+base': enter_reverse_mode but no exit_attribute_mode

do not worry, all should be fine. Make sure that you can use the compiled description:

$ infocmp -x tmux-256color

And finally, set default terminal in tmux configuration file:

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

RGB Colors

Also, do not forget to enable RGB colors (24 bit colors, or true colors, as you like). The $TERM outside tmux must support 256 colors. Also, it must contains Tc or RGB flag in terminfo description:

$ tmux info | grep -e RGB -e Tc

If both are missing, then you need to override terminal description in tmux configuration file:

set-option -a terminal-overrides ",XXX:RGB"

where XXX is a terminal outside tmux, like xterm-256color. And finally, terminal-overrides suports a pattern matching:

set-option -a terminal-overrides ",*256col*:RGB"

If you use Alacritty terminal, make sure the $TERM outside tmux is alacritty-direct. The alacritty terminal description does not have RGB flag. Otherwise, override description:

set-option -a terminal-overrides ",alacritty:RGB"
@joshuarli

This comment has been minimized.

Copy link

@joshuarli joshuarli commented Feb 18, 2020

Thank you!!

@phuna

This comment has been minimized.

Copy link

@phuna phuna commented Apr 16, 2020

Thanks a lot! ❤️

@smarquez1

This comment has been minimized.

Copy link

@smarquez1 smarquez1 commented Jun 8, 2020

Thanks!!

@bryceyang

This comment has been minimized.

Copy link

@bryceyang bryceyang commented Aug 27, 2020

Life saver!

@carlocab

This comment has been minimized.

Copy link

@carlocab carlocab commented Oct 29, 2020

Unfortunately, these instructions will not work if you want to use htop with coloured output. However, you can use the terminfo provided by the tmux maintainer at https://gist.github.com/nicm/ea9cf3c93f22e0246ec858122d9abea1.

Details at htop-dev/htop#251.

@ShaunMWallace

This comment has been minimized.

Copy link

@ShaunMWallace ShaunMWallace commented Dec 12, 2020

Thank you

@idanko

This comment has been minimized.

Copy link

@idanko idanko commented Feb 8, 2021

Thank you

@miozus

This comment has been minimized.

Copy link

@miozus miozus commented Apr 15, 2021

# zsh
❯ tmux info | grep -e RGB -e Tc

 196: RGB: (flag) true
 221: Tc: [missing]

vim :checkhealth

## tmux
  - OK: escape-time: 0ms
  - INFO: $TERM: tmux-256color

❤️ Thank you! cant love you much @MacOS Big Sur 11.2.3

@Arelav

This comment has been minimized.

Copy link

@Arelav Arelav commented Apr 22, 2021

Thank you!

@Mellbourn

This comment has been minimized.

Copy link

@Mellbourn Mellbourn commented May 1, 2021

What does this refer to?

The latest (6.2) ncurses version does not work properly

Are there tmux-related problems in 6.2?

@carlocab

This comment has been minimized.

Copy link

@carlocab carlocab commented May 1, 2021

I don't think it's so much an issue of ncurses 6.2 not working properly as it is a problem with using terminal apps that link against the (old) system ncurses. When you do that, and you have TERM=tmux-256color, then those terminal apps will sometimes misbehave because they don't know what tmux-256color is.

@Mellbourn

This comment has been minimized.

Copy link

@Mellbourn Mellbourn commented May 1, 2021

@carlocab that is exactly my impression, that programs don't recognize TERM=tmux-256color. But will this gist help with that? This gist is installing tmux-256color, but TERM will still be set to tmux-256color in the end.

I've asked about this problem here: https://unix.stackexchange.com/questions/647635/term-tmux-256color-causes-error-opening-terminal

@carlocab

This comment has been minimized.

Copy link

@carlocab carlocab commented May 1, 2021

If you're just going to manually do

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

in your .zshrc, then you may as well set

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

in your .tmux.conf instead. This will save you from having to reset TERM in your .zshrc.

The version of nano and ncdu that you are using link against system ncurses, which doesn't know what tmux-256color is. You can fix that for nano by using one that is compiled using the new ncurses (e.g. brew install nano). You can also compile ncdu using the newer ncurses (unfortunately the one shipped by Homebrew isn't -- happy to review a pull request that changes that if you're a brew user).

An alternative here is to just teach system ncurses what tmux-256color is, and this gist helps with that. I did still encounter some hiccups with it, though. See https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95#gistcomment-3509584.

@Mellbourn

This comment has been minimized.

Copy link

@Mellbourn Mellbourn commented May 1, 2021

If I do

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

Then tmux, and programs run inside tmux, lose the ability to display italics.

Interesting to learn more about nano and ncdu. So the versions that I use are hardcoded to use the terminfo in /usr/share/terminfo rather than /opt/homebrew/opt/ncurses/share/terminfo?

Couldn't I just copy tmux-256color from /opt/homebrew/opt/ncurses/share/terminfo to /usr/share/terminfo?

@carlocab

This comment has been minimized.

Copy link

@carlocab carlocab commented May 1, 2021

Roughly speaking, yes. You can try pointing them to /opt/homebrew/opt/ncurses/share/terminfo, except that system ncurses will not understand many of the entries there.

@occult

This comment has been minimized.

Copy link

@occult occult commented Jun 14, 2021

Nice job! Thanks for explaining this. My backspace character was creating spaces due to this.

@jettandres

This comment has been minimized.

Copy link

@jettandres jettandres commented Jun 23, 2021

thank you so much for this! I finally got tmux, vim, and zsh working in harmony!

@brandoncc

This comment has been minimized.

Copy link

@brandoncc brandoncc commented Jul 15, 2021

You are amazing, thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment