Is there a way to create an Orange color from ANSI escape characters?
The 256-color palette is more compatible and a tad easier to use. There are number of oranges:
printf "\033[48:5:208m%s\033[m\n" "Hello world" # bright orange
printf "\033[48:5:166m%s\033[m\n" "Hello world" # darker orange
The colons may need to be semi-colons under your terminal. Change the first number to 38, to set the foreground.
Strictly speaking, no: ANSI never standardized anything (for a terminal's control sequences) which was called "orange". Some terminals can do this, but that lies outside the scope of the standards.
xterm (see XTerm Control Sequences) uses control sequences following the "ANSI" (actually withdrawn from standardization long ago) ECMA-48 syntax.
- Some of those are the standard 8 colors via SGR (which do not include orange).
- It also (using the aixterm SGR extension) adds another 8 colors. Still no orange.
- However, xterm extends (in a way not exactly standard) SGR codes 38 and 48 to provide a palette of colors using RGB (red/green/blue) values. The maximum palette size is compiled in as either 88 or 256 colors.
Orange can be composed by an RGB code. For instance X's rgb.txt file defines it as
255 165 0 orange
(bright red plus a moderately bright green). To get that in a shell script, one could use
#!/bin/sh
printf "\033[48:2:255:165:0m%s\033[m\n" "Hello world"
printf "\033[48;2;255;165;0m%s\033[m\n" "Hello world"
The difference between the two lines is the use of colon as a parameter separator (ECMA-48 has some verbiage which prefers that, for subparameters as used in xterm, which was overlooked early on). For compatibility (including with terminals copied from xterm's early implementation), xterm honors both.
xterm also supports a "non-ANSI" scheme referred to as dynamic colors, which accepts a color name, but that sets the text color for the whole screen.
Finally, xterm can assign colors to display instead of blink, bold, italics, reverse and underline (see the discussion of colorBD
for instance). That is done though X resource settings (with some help from escape sequences). The colors assigned to those resources can be set via the same 88/256 color extension.