If none of the more specific forums is the right place to ask


Postby Carlosinfl » 2006-06-15 12:23

I was wondering if anyone knows how hard or even possible it is to have Linux generate the MOTD in bold & or colored text? I would like to MOTD to stand out a bit from the rest of the terminal text.

Thanks for any assistance ...
Posts: 889
Joined: 2005-02-05 06:11
Location: Orlando, FL

Postby lacek » 2006-06-15 14:36

You can add color and other attributes to a text by embedding special control sequences to the text. Such sequences begin with the ESC character (code 27, 0x1b -- press C-v, ESC to get it), followed by a '[' and some of the codes. The sequence is terminated with 'm'.
The codes (to my knowledge) are:

General control
0: Revert to default
1: Bold/intense foreground
3: Italic text
4: Underlined text
7: Inverted colors
9: Strikeout text
22: Switch off bold/intense foreground
23: Switch off italic text
24: Switch off underlined text
27: Switch off inverted colors
29: Switch off strikeout text

Text colors
30: Black
31: Red
32: Green
33: Brown/Yellow (depends on intensity)
34: Blue
35: Magenta
36: Cyan
37: Gray/White (depends on intensity)
39: Default (white?)

Background colors
40: Black
41: Red
42: Green
43: Brown
44: Blue
45: Magenta
46: Cyan
47: Gray
49: Default (black?)

You have to separate the codes with ';'. For example, to enable yellow text on red background, you have to write this:
ESC[1;33;41mColored textESC[0mNormal text
Substitute ESC with the escape character.

Note that not every terminals support every colors/combinations, for example, you can't really get italic text on Linux console. Play with the codes a little bit to find out what is supported.
Moderator Team Member
Posts: 769
Joined: 2004-03-11 18:49
Location: Budapest, Hungary

Postby Carlosinfl » 2006-06-15 14:37

Great info!
Posts: 889
Joined: 2005-02-05 06:11
Location: Orlando, FL

Return to General Questions

Who is online

Users browsing this forum: No registered users and 10 guests