Next: , Previous: Using Customize, Up: Common requests

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.

There aren't yet any standard terminal type definitions that would support the capabilities, but Emacs can be invoked with a custom definition as shown below.

     $ 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

Currently there's no standard way to determine whether a terminal supports direct color mode. If such standard arises later on, support for ‘setb24’ and ‘setf24’ may be removed.