The following serves as a handy reference for creating ANSI escape sequences that
can be used to configure eza
, ls
, or anything else that uses them to generate
colorful text output in the terminal.
For color and text effects, Select Graphic Rendition (SGR) control sequences are used. The format for such sequences is:
\e
+ [
+ n[;n]
+ m
Component | Description |
---|---|
\e |
is a literal 'escape' (may also be \x1b or \033 ) |
n[;n] |
zero or more numbers from the tables below, separated by ";" |
m |
is the code for the SGR function |
A good way to think of such a sequence is as a function call where \e[
indicates
you are calling a function, n[;n]
represents the argument(s), and m
is the
function being called.
\e[01;04;33mHELLO WORLD\e[0m
The example above will result in the words 'HELLO WORLD' printed in bold (01
),
underlined (04
), yellow (33
) text. The sequence \e[0m
after the text resets
all effects and colors to the system default, which is typically no color and no
effects.
Note that the leading 0
is not required, so \e[1;4;33m
will yield the same
results. In fact, \e[00m
, \e[0m
and \e[m
are equivalent expressions for the global
reset sequence.
COLOR | NORMAL FG | NORMAL BG | BRIGHT FG | BRIGHT BG | RESETS |
---|---|---|---|---|---|
Black | 30 | 40 | 90 | 100 | 00 Reset Everything |
Red | 31 | 41 | 91 | 101 | 39 Reset Foreground |
Green | 32 | 42 | 92 | 102 | 49 Reset background |
Yellow | 33 | 43 | 93 | 103 | |
Blue | 34 | 44 | 94 | 104 | |
Magenta | 35 | 45 | 95 | 105 | |
Cyan | 36 | 46 | 96 | 106 | |
White | 37 | 47 | 97 | 107 |
CODE | EFFECT | RESET CODE | RESET NOTES |
---|---|---|---|
-- | All | 00 | Everything (colors and effects) |
01 | Bold | 22 | |
02 | Dim/Faint | 22 | Same as reset bold |
03 | Italic | 23 | |
04 | Underline | 24 | |
05 | Blink | 25 | |
07 | Inverse | 27 | |
08 | Hidden | 28 | |
09 | Strikethrough | 29 | |
21 | Double Underline | 24 | Same as reset underline |
53 | Overline | 55 |
To use colors from the 256 color palette available in most modern terminal emulators you must use the following control sequences:
Target | Code | Note |
---|---|---|
Foreground | 38;5;nnn | nnn = three digit color number |
Background | 48;5;nnn |
Example: \e[38;5;197m
results in very bright pink text.
To use colors from the RGB color palette available in terminal emulators that support the 'true color,' or 16 million color palette, you must use the following control sequences:
Target | Code | Note |
---|---|---|
Foreground | 38;2;r;g;b | r/g/b = component numbers in the range 0-255 |
Background | 48;2;r;g;b |
Example: \e[48;2;255;0;0m
results in red text.
Some (most?) terminal emulators use the bold effect (01
) to enable bright,
or 'intense,' colors. Often, this behavior will result in text that is both bold
AND bright. For example: 01;34
(bold blue) would render the same as 01;94
(bold, bright blue).
This behavior is especially notable when trying to use bold black (01;30
) as it
will be rendered as bold, bright black (a.k.a. dark gray).
This 'functionality' is a holdover from a time when terminals only had eight
colors and the bold flag was used to render a brighter variant of those eight
colors.
For example, Windows Terminal has a setting for 'Intense text style' that can be
set to 'bold', 'bright', or 'bold AND bright'. Setting it to 'bold' results in
the expected rendering behavior. Similarly, Xterm, can be made to properly render
bold variations by placing XTerm*boldColors: false
in your .Xdefaults file.
This setting may also work for other emulators, such as rxvt-unicode, that use the
boldColors
setting.
- An alternative to the bold black problem above is to use a gray from the 256
color palette (
38;5;244
), or you can use dim white (02;37
). - Bright black is dark gray, and bright white is bright gray.
- Dim bright colors (
02;9#
) are NOT the same as normal (3#
) colors! (e.g.31
,02;31
,91
and02;91
all yield different results) - Some color, effect, and/or reset codes may not work on all terminal emulators