I'd like to try and get to a similar setup that I have with N/Vim in OSX, whereby Truecolor support is enabled in iTerm2 (which supports 24bit colors) but disabled in the native Terminal app (which doesn't support it). This is simply for flexibility - sometimes I forget to use iTerm, and sometimes I'm on a machine that is using my dotfiles, but isn't using iTerm.
I've checked that my terminal is rendering the truecolor palette by running this script which outputs the following in Iterm2
and as expected, outputs the following in Terminal.app:
I'm running fish shell version 2.5, and $TERM
is set to xterm-256color
inside of iTerm2 and also echos this in the terminal. This means if I run tput colors
it outputs 256, but from reading around on the web, I don't think it ever outputs anything higher than this though.
In Vim I achieve this with the following line of code in my .vimrc file:
if has("nvim") && terminal_program == "iTerm.app"
" has true colour support and is nvim
set termguicolors
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
colorscheme base16-materia
elseif terminal_program == "iTerm.app"
" has true colour support but is using std vim
set termguicolors
colorscheme NeoSolarized
else
set termguicolors
colorscheme solarized
endif
which lets me have a different colourscheme for nvim and distinguishes between iTerm app and the standard Terminal app.
I know that the latest version of emacs supports True color, so I installed this by running:
brew install emacs --HEAD --use-git-head --with-cocoa
emacs --version
GNU Emacs 26.0.50
... etc ...
and opening it in the cocoa windowed mode shows the additional colours when I run list-colors-display
but doing the same in the terminal with emacs -nw
only renders the standard 256, and also looks weird:
And running emacs with a non-standard TERM as the commit message mentions doesn't seem to work:
env TERM=xterm-24bit emacs -nw
emacs: Cannot open terminfo database file
The result is also the same with if I set $fish_term24bit
to 1 in my fish.config via set -g fish_term24bit 1
. So what am I missing to get the True color support working in iTerm2, before I even write the conditional code?
** edit 1 **
So further digging has thrown up the following links that could be useful:
- Github mirror of link 3
- Bugzilla discussion
both of which mentions requiring a custom setb24/setf24 terminfo capability to be present, as shown in the example and pasted again below.
@example
$ cat terminfo-24bit.src
# Use colon separators.
xterm-24bit|xterm with 24-bit direct color mode,
use=xterm-256color,
setb24=\E[48:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm,
setf24=\E[38:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm,
# Use semicolon separators.
xterm-24bits|xterm with 24-bit direct color mode,
use=xterm-256color,
setb24=\E[48;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm,
setf24=\E[38;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm,
$ tic -x -o ~/.terminfo terminfo-24bit.src
TERM=xterm-24bit emacs -nw
@end example
As directed, I put this into a file called terminfo-24bit.src and ran the specified tic command, which generated the directory .terminfo in my home dir. However, now when I run emacs I get colour sequences everywhere, which leads me to believe emacs has entered 24bit colour mode, but iTerm2 isn't interpreting these correctly...
xterm-24bits
to be better supported than the colon variantxterm-24bit
. IIRC Emacs within tmux doesn't work with the latter.