Thursday, June 28, 2007

How do I change the color of text in a terminal or virtual console?

Issue:
How do I change the color of text in a terminal or virtual console? Resolution:Release Found: Red Hat Enterprise Linux

Problem:
You need to display text in a terminal or virtual console but would like it to display in a pre-determined color.

Solution:
To change the color in or within a string of characters, prefix one of the codes from the table below with the escape character (ASCII code- 27 decimal, 0x1b hex, or 033 octal), followed by a [ character (ASCII code- 91 decimal, 0x5b hex, or 133 octal), and follow the code with the letter m (ASCII code- 109 decimal, 0x6d hex, or 155 octal). If you specify only escape, bracket and the letter m, without any codes inbetween, then the text properties will revert back to their default

For example, try typing the following at a shell prompt:


$ echo -e "\033\1331;33;44\155 This is yellow on blue text\033\133\155"

1;33;44 means a combination from below

No comments: