On most terminals it is possible to colorize output using the 033
ANSI escape sequence.
I'm looking for a list of all supported colors and options (like bright and blinking).
Stream Tritonal & Paris Blohm - Colors (Culture Code Remix) by Culture Code from desktop or your mobile device. BitTube is a revolutionary video platform in which publishers can make money with their content, without ads. How is that possible?
As there are probably differences between the terminals supporting them, I'm mainly interested in sequences supported by xterm-compatible terminals.
Dave Jarvis6 Answers
The ANSI escape sequences you're looking for are the Select Graphic Rendition subset. All of these have the form
where XXX
is a series of semicolon-separated parameters.
To say, make text red, bold, and underlined (we'll discuss many other options below) in C you might write:
In C++ you'd use
In Python3 you'd use
and in Bash you'd use
where the first part makes the text red (31
), bold (1
), underlined (4
) and the last part clears all this (0
).
As described in the table below, there are a large number of text properties you can set, such as boldness, font, underlining, &c. (Isn't it silly that StackOverflow doesn't allow you to put proper tables in answers?)
You've got this already!
The standards implementing terminal colours began with limited (4-bit) options. The table below lists the RGB values of the background and foreground colours used for these by a variety of terminal emulators:
Using the above, you can make red text on a green background (but why?) using:
In their book 'Basic Color Terms: Their Universality and Evolution', Brent Berlin and Paul Kay used data collected from twenty different languages from a range of language families to identify eleven possible basic color categories: white, black, red, green, yellow, blue, brown, purple, pink, orange, and gray.
Berlin and Kay found that, in languages with fewer than the maximum eleven color categories, the colors followed a specific evolutionary pattern. This pattern is as follows:
- All languages contain terms for black (cool colours) and white (bright colours).
- If a language contains three terms, then it contains a term for red.
- If a language contains four terms, then it contains a term for either green or yellow (but not both).
- If a language contains five terms, then it contains terms for both green and yellow.
- If a language contains six terms, then it contains a term for blue.
- If a language contains seven terms, then it contains a term for brown.
- If a language contains eight or more terms, then it contains terms for purple, pink, orange or gray.
This may be why story Beowulf only contains the colours black, white, and red. It may also be why the Bible does not contain the colour blue. Homer's Odyssey contains black almost 200 times and white about 100 times. Red appears 15 times, while yellow and green appear only 10 times. (More information here)
Differences between languages are also interesting: note the profusion of distinct colour words used by English vs. Chinese. However, digging deeper into these languages shows that each uses colour in distinct ways. (More information)
Generally speaking, the naming, use, and grouping of colours in human languages is fascinating. Now, back to the show.
Technology advanced, and tables of 256 pre-selected colours became available, as shown below.
Using these above, you can make pink text like so:
And make an early-morning blue background using
And, of course, you can combine these:
The 8-bit colours are arranged like so:
Now we are living in the future, and the full RGB spectrum is available using:
So you can put pinkish text on a brownish background using
Support for 'true color' terminals is listed here.
Much of the above is drawn from the Wikipedia page 'ANSI escape code'.
RichardRichardThis page has a great summary:
RussHow about:
ECMA-48 - Control Functions for Coded Character Sets, 5th edition (June 1991) - A standard defining the color control codes, that is apparently supported also by xterm.
SGR 38 and 48 were originally reserved by ECMA-48, but were fleshed out a few years later in a joint ITU, IEC, and ISO standard, which comes in several parts and which (amongst a whole lot of other things) documents the SGR 38/48 control sequences for direct colour and indexed colour:
- Information technology — Open Document Architecture (ODA) and interchange format: Document structures. T.412. International Telecommunication Union.
- Information technology — Open Document Architecture (ODA) and interchange format: Character content architectures. T.416. International Telecommunication Union.
- Information technology— Open Document Architecture (ODA) and Interchange Format: Character content architectures. ISO/IEC 8613-6:1994. International Organization for Standardization.
There's a column for xterm in this table on the Wikipedia page for ANSI escape codes
sinelawsinelawThere are some more interesting ones along with related info.
PalecPalecIt's related absolutely to your terminal. VTE doesn't support blink, If you use gnome-terminal
, tilda
, guake
, terminator
, xfce4-terminal
and so on according to VTE, You'll not have blink.
If you use or want to use blink on VTE, You have to use xterm
.
You can use infocmp command with terminal name:
For example :
PersianGulfPersianGulfFor these who don't get proper results other than mentioned languages, if you're using C# to print a text into console(terminal) window you should replace '033' with 'x1b'. In Visual Basic it would be Chrw(27).