source color.sh
echo "This is ${pred}RED$preset."
echo "This is $(c IndianRed)Indian Red$preset."- Define
c_truecolortotrueorfalse. There is not (yet) any automatic detection to distinguish 8-bit (256) color terminals from 24-bit (16 million)1. The Mac OS X system terminal lags behind most others in this respect2. The default istrue. - Optionally set
X11_RGB_TXTto the full path of yourrgb.txtsuch as provided with X11. If unset, defaults to/usr/share/X11/rgb.txt, or if that file is unreadable, to anrgb.txtprovided withcolors.sh. - Source
color.sh.
printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"Please note the default MacOS terminal is anemic, and does not show colors as nicely as Linux or Windows.
echo "This is $pbold${pred}bold red$preset."
echo "This is $pitalic${pgreen}italic green$preset."All predefined variables are prefixed with p, as in $pred or
${preset}.
To restore default text properties:
- reset
The basic ANSI 8 colors as foreground:
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
The most supported ANSI text effects:
- bold
- light
- italic
- underscore
- blink
- reverse
- invisible
- strikethrough
cat <<EOM
Reds include:
* $(c IndianRed)Indian red$preset
* $(c OrangeRed)orange red$preset
* $(c VioletRed)violet red$preset
* $(c DarkRed)dark red$preset
EOM
echo "Or you can make $(c 210 30 30)your own red$preset."Using an 24-bit color palette, and to a lesser degree 8-bit, you can use around 500 X11-defined colors by name, or provide your own RGB values.
- Detect 24- vs 8-bit color. See Check if terminal supports 24-bit / true color
- Detect and handle non-color, e.g., output is not to a terminal.
Footnotes
-
I need to investigate test if your terminal supports 24 bit true color. This formula may work, but needs testing, and integration into
color.sh: ↩ -
Since I last wrote this, it seems improved on MacOS. ↩