Next: , Previous: , Up: Common requests   [Contents][Index]

5.3 How do I get colors and syntax highlighting on a TTY?

In Emacs 21.1 and later, colors and faces are supported in non-windowed mode, i.e., on Unix and GNU/Linux text-only terminals and consoles, and when invoked as ‘emacs -nw’ on X, and MS-Windows. (Colors and faces were supported in the MS-DOS port since Emacs 19.29.) Emacs automatically detects color support at startup and uses it if available. If you think that your terminal supports colors, but Emacs won’t use them, check the termcap entry for your display type for color-related capabilities.

The command M-x list-colors-display pops up a window which exhibits all the colors Emacs knows about on the current display.

Syntax highlighting is on by default since version 22.1.

Emacs 26.1 and later support direct color mode in terminals. If Emacs finds Terminfo capabilities ‘setb24’ and ‘setf24’, 24-bit direct color mode is used. The capability strings are expected to take one 24-bit pixel value as argument and transform the pixel to a string that can be used to send 24-bit colors to the terminal.

Standard terminal definitions don’t support these capabilities and therefore custom definition is needed.

$ cat terminfo-custom.src

xterm-emacs|xterm with 24-bit direct color mode for Emacs,

$ tic -x -o ~/.terminfo terminfo-custom.src

$ TERM=xterm-emacs emacs -nw

Emacs 27.1 and later support Terminfo capability ‘RGB’ for detecting 24-bit direct color mode. Multiple standard terminal definitions support this capability.

$ TERM=xterm-direct infocmp | grep seta[bf]


$ TERM=xterm-direct emacs -nw

If your terminal is incompatible with XTerm, you may have to use another TERM definition. Any terminal whose name includes ‘direct’ should be a candidate. The toe command can be used to find out which of these are installed on your system:

$ toe | grep '\-direct'

konsole-direct  konsole with direct-color indexing
vte-direct      vte with direct-color indexing
st-direct       st with direct-color indexing
xterm-direct2   xterm with direct-color indexing (old)
xterm-direct    xterm with direct-color indexing

Terminals with ‘RGB’ capability treat pixels #000001 - #000007 as indexed colors to maintain backward compatibility with applications that are unaware of direct color mode. Therefore the seven darkest blue shades may not be available. If this is a problem, you can always use custom terminal definition with ‘setb24’ and ‘setf24’.

Next: , Previous: , Up: Common requests   [Contents][Index]