beta-tester
Posts: 1382
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

linux console escape color codes

Tue Aug 05, 2014 7:05 am

hello, i am playing with colors on the linux console.
but i am struggeling a bit where exactly the supported codes are documented.
the standard colors are not the problem
they are formated like this: (for light gray foreground on black background)

Code: Select all

echo -e "\x1b[0;37;40mTEST\x1b[0m"
0..1 = intensity foreground
30..37 = colors for foreground
40..47 = colors for background

but now the problens starts, when I try to get a bright background
and further more to have both in bright intensity - foreground and background at the same time
I did not found any documentation that fits to the standard linux console.
i have found out by try and error
in case of bright background and normal foreground:

Code: Select all

echo -e "\x1b[5;37;40mTEST\x1b[0m"
5 = high intensity for background
30..37 = colors for foreground
40..47 = colors for background

in case of bright background and bright foreground:

Code: Select all

echo -e "\x1b[5;1;37;40mTEST\x1b[0m"
5 = high intensity for background
1 = high intensity for foreground
30..37 = colors for foreground
40..47 = colors for background
(when ich change the order of 5 and 1 it won't work anymore - the order seem to be essentially important)

Code: Select all

echo -e "\x1b[0;37;40mTEST (light gray foreground on black background)\x1b[0m"
echo -e "\x1b[1;37;40mTEST (white foreground on black background)\x1b[0m"
echo -e "\x1b[5;37;40mTEST (light gray foreground on dark gray background)\x1b[0m"
echo -e "\x1b[5;1;37;40mTEST (white foreground on dark gray background)\x1b[0m"
but for these last two cases I can not find any documentation (specially the very last one).
that documentation I found for bright background, with using values of 100..107, is not working with the Linux console on raspbian.

:?: where can I find a detailes working documentation, that tells my exactly all the available codes of the standard Linux console that raspbian is using by default ?


BTW: when I playing with mono and Console.BackgroundColor or Console.ForegroundColor, all the high intensity colors are not working on raspbian. on windows 7 for sure, on Ubuntu console as well, but not on standard Linux console of raspbian
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: linux console escape color codes

Tue Aug 05, 2014 8:45 am

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
jojopi
Posts: 3271
Joined: Tue Oct 11, 2011 8:38 pm

Re: linux console escape color codes

Tue Aug 05, 2014 11:22 am

beta-tester wrote: :?: where can I find a detailes working documentation, that tells my exactly all the available codes of the standard Linux console that raspbian is using by default ?
man console_codes

The Linux console was originally implemented on PCs in hardware text mode. For each cell of the screen it stores one byte for the character and one byte for attributes. The high bit of the attribute byte normally selected blinking, although blinking could be disabled to allow intense backgrounds instead. This is why bright backgrounds in Linux are selected using the \033[5m blink sequence, even though blink is unimplemented in the modern framebuffer driver.

You should be aware that intense backgrounds via blink are not very portable. On old hardware and some terminal emulators you may actually get blink. And some distributions use a 512 glyph font to support more languages on console. This reuses the top bit of the attribute byte, so again you have only eight background colours available.

beta-tester
Posts: 1382
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: linux console escape color codes

Tue Aug 05, 2014 2:56 pm

DougieLawson wrote:There's extensive documentation on the colour codes at http://en.wikipedia.org/wiki/ANSI_escape_code
that I found already, but this and many others are not fitting to the raspbians behavior when I want to habe 16 colors for fore- and background
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: linux console escape color codes

Tue Aug 05, 2014 3:01 pm

man console_codes it works exactly the same on my raspberry pis as it does on my x86 Ubuntu system.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

beta-tester
Posts: 1382
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: linux console escape color codes

Tue Aug 05, 2014 3:03 pm

jojopi wrote:man console_codes

The Linux console was originally implemented on PCs in hardware text mode. For each cell of the screen it stores one byte for the character and one byte for attributes. The high bit of the attribute byte normally selected blinking, although blinking could be disabled to allow intense backgrounds instead. This is why bright backgrounds in Linux are selected using the \033[5m blink sequence, even though blink is unimplemented in the modern framebuffer driver.

You should be aware that intense backgrounds via blink are not very portable. On old hardware and some terminal emulators you may actually get blink. And some distributions use a 512 glyph font to support more languages on console. This reuses the top bit of the attribute byte, so again you have only eight background colours available.
... oops, the man pages I absolutely forgot. but even then I didn't knew what man-page will fit for my problem... man console_codes are good. ok I am happy with this - even it does not explan everything - so I live with my try and error knowledge.

my code don't need to be portable. I only use it on my RPi with a real display (not a ssh session or xterm).
(C# is my favorite programming language, where I have most experiences right now. that's the only reason why I am using mono)
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

Return to “Raspberry Pi OS”