This page was created to consolidate colorization of CLI outputs.
The ANSI escape sequences define a way to put additional information into terminal output, and color is part of this "additional information". Throughout the years the range of terminal colors has been vastly expanded, from the initial eight colors to a full 24-bit truecolor.
The basic color encoding provides 8 normal-brightness colors and 8 brighter versions of these colors. Modern terminal emulators, including the Linux console itself, allows you to specify the precise RGB values that the colors translate to. This mode is supported by almost all terminal emulators.
With the advent of 256-color displays came the 256-color escape. The 256 colors are the 16 basic colors, the 216 RGB colors (laid out in a 6x6x6 cube), and 24 levels of greyscale. Except for the first 16 colors, the scheme is usually not customizable as it has a well-defined mapping to RGB. This mode is supported by most terminal emulators. (A minority of emulators use a similar but incompatible encoding with only 88 colors. You are very unlikely to use them in practice, but they will appear in the terminfo database.)
Less commonly supported is the truecolor mode, allowing one to use 16.7 million (2) colors in RGB (each value ranging from 0 to 255).
The option enables color highlighting. Color codes are emitted only on standard output; not in pipes or redirection.
The option includes file line numbers in the output.
As with the #man case, we can tell less to emit colors when it is meaning to make bold text and other formatting effects.
Add the following lines to your shell configuration file:
Some programs provide an option to disable the interactive tty detection:
In case that the program does not provide any similar option, it is possible to trick the program into thinking its stdout is an interactive terminal with the following utilities:
The option enables color highlighting. Color codes are emitted only on standard output; not in pipes or redirection.
Remember to source your config or restart your shell to make the changes take effect.
The basic function of 'most' is similar to and , but it has a smaller feature set. Configuring most to use colors is easier than using less, but additional configuration is necessary to make most behave like less. Install the most package.
They go with multiple preconfigured presets that can be changed, and new ones can be created/contributed.
Frequent users of the command line interface might want to install lesspipe.
Users may now list the compressed files inside of an archive using their pager:
lesspipe also grants less the ability of interfacing with files other than archives, serving as an alternative for the specific command associated for that file-type (such as viewing HTML via python-html2text).
Example to set bold, yellow text, with blue background:
The following command will let you discover all the terminals you have terminfo support for, and the number of colors each terminal supports. The possible values are: 8, 15, 16, 52, 64, 88 and 256.
See [3] for scripts which display a chart of your current terminal scheme.
Some terminals support the full range of 16 million colors (RGB, each with 8 bit resolution): xterm, konsole, st, etc. The corresponding TERM values , , , etc. are supported starting with ncurses version 6.1 [4]. For more info about terminal emulators and applications that support true color, see [5].
Note that the Linux kernel supports the SGR (Select Graphic Rendition) escape sequences for true-color, but it is pointless to use it, because the driver maps the 24-bit color specifications to a 256-colors color map in the kernel (see the functions , ). For this reason, there is no terminfo entry .