0

ok so here

Colorizing your terminal and shell environment?

its stated that

export COLOR_NC='\e[0m' # No Color
export COLOR_BLACK='\e[0;30m'
export COLOR_GRAY='\e[1;30m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_LIGHT_GRAY='\e[0;37m'
export COLOR_WHITE='\e[1;37m'

I am wondering how these values actually work, for example, the COLOR_GREEN and COLOR_LIGHT_GREEN, they differ in only one character, but visually they differ in both color and weight, one is bold while the other is not.... anyone care to explain whats going on here?

  • Colors in a terminal are encoded with ANSI escape codes (\e). All your sequences are CSI SGR \e[...m . More information on https://en.m.wikipedia.org/wiki/ANSI_escape_code – Arnaud Valmary Dec 23 '22 at 15:51

1 Answers1

1

From what you cited \e[0m stands out; it resets attributes. The rest is a palette of 16 colors. Usually these colors are in accordance with what your descriptive names of variables say, but it does not have to be this way. When you terminal gets such-and-such sequence of bytes it starts using the associated color. The point is the associated color can be any color or even something more than a color.

E.g. I can configure my terminal emulator (konsole) to use arbitrary colors. This way I can make your COLOR_GREEN and COLOR_LIGHT_GREEN to manifest respectively as (e.g.) red and blue in my terminal. There's also an option to draw intense colors in bold font.

In general the terminal emulator gets a sequence of bytes and it reacts. The sequences in question are designed to select colors, but you can create a terminal emulator that plays sounds instead.

Some programs that use colors expect my terminal emulator to actually use colors and they expect my palette to be similar to the conventional palette; or at least they expect COLOR_LIGHT_foo to visually be the light version of COLOR_foo. If I use a non-standard palette or a crazy terminal emulator that makes such a program unreadable then it's my problem. Drawing intense colors in bold usually increases readability, so what you observed is a manifestation of rather sane settings.

Think of the colors in question as color1, color2, etc., or even request1, request2, etc. The rest is up to your terminal (terminal emulator).