LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to specify text message color on GNOME terminal. (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-specify-text-message-color-on-gnome-terminal-825610/)

ameametalk 08-11-2010 01:43 PM

How to specify text message color on GNOME terminal.
 
Hi, I have a question about color setting on GNOME terminal. I'd appreciate if you kindly review and give me any information.
OS is CentOS 5.5, and GNOME terminal emulator (v2.16.0). However I regard the question is not related with OS/Gnome version level.

My question is whether if color setting is available or not for the text character outputted by kernel (or shell, i.e. Bash). Normally we can specify/modify text character color (and background color) with property setting on the terminal. However, it only takes affect to the text for inputting character, not for outputted character by kernel/shell. For example, when we type a shell command "ls -al <cr>", the text appears with the color along with the terminal property. Meanwhile, the text message displayed on the console (output message against "ls -al" command), in this case it must be file and/or directory names, will appear with some preset color which we've not preliminarily set.

In my case, I set Text color with "White", Background color with "Black". Then I expect the text output message color displayed by kernel/shell would be some brighter color. But the color is "blue" which does not look better brightness against "Black" background.

For this situation what I'd like to know is how to set/specify the color outputted by the kernel/shell (or whether or not it is possible to set manually). Please tell me if you have any information or any referrence. I appreciate any of your advise and/or message for above situation.

Thanks in advance,

David the H. 08-11-2010 03:10 PM

Back in the days before gui, terminals added color and other effects by embedding ansi escape codes into the text. These are invisible, non-printing characters that are interpreted by the terminal to produce the desired effects. These days you can still use them to colorize text, but it requires that both the program producing the output and the program displaying it be configured to display them. Your shell is generally set to interpret them by default, but other text display programs, like less or various text editors, may not.

As an example, try running "ls --color | less -R" The --color command on ls inserts color codes based on the filetype, and the -R option in less tells it to interpret them. Then try it without the -R option.

You can also view any embedded characters in text with "cat -A".

Note also that, even though these codes are invisible, they are still ascii characters, and text-manipulation programs like sed and grep can be confused by them.

You can use embedded sequences directly in scripts or such, or there's a program called tput that provides a slightly cleaner and more portable interface for them, since different platforms often use different syntax.


Some links about it:
http://tldp.org/LDP/abs/html/colorizing.html
http://webhome.csc.uvic.ca/~sae/seng...ng-colors.html
http://wiki.bash-hackers.org/scripting/terminalcodes


The default colors used by many programs are controlled through termcap/terminfo, but I'm personally not very familiar with how it works. Here's one (quite ancient) page I came across that describes setting up your own color scheme. It's quite technical though.
http://www.cs.utk.edu/~shuford/termi...ed_termcap.txt

Edit: Here's another link that explains what termcap is in a bit more detail, and another thread I posted in recently where I provided some more references.
http://www.linuxselfhelp.com/HOWTO/T...-HOWTO-15.html
http://www.linuxquestions.org/questi...o-dark-825007/

To modify the colors used in ls, take a look at the LS_COLORS variable and the dircolors command.

ameametalk 08-11-2010 09:30 PM

Hi David,
Thank you for your kind assistance with some background/historical information. First of all I should tell my mistake that the "Blue" colored character was only for directory name on ls command (as you might already know). And other file types were displayed with different colored based on preset color. Sorry for my premature judging.

I checked most of link you showed and those must be what I was looking for. I'm afraid I did not catch LS_COLORS variable (and dircolors command) so far. I found my question will be fixed with some modifications with them (i.e. simply to specify favorite color with some script adding to startup shell). I also found tput command (e.g. with "setb" or "setf" option) is also effective while temporary use in shell.
In fact I may need to learn more about termcap/terminfo, but your information is enough for me at this time.

Thank you so much for your help!

David the H. 08-12-2010 12:22 PM

If all you want to do is change the colors in ls, it's really rather easy.
The LS_COLORS variable is not generally set by default, but you can use dircolors to quickly set it up.

First run:
Code:

dircolors -p >~/.dircolors
This will copy the default settings to the hidden file .dircolors in your home directory.

Next, use a text editor to change any of the settings you want. To make directories bright red, for example, change the DIR entry to 01;31. The file should be fully commented with explanations of what all the entries do.

Then simply add the following entry to one of your bash startup files, usually ~/.bashrc.
Code:

#if ~/.dircolors file exists, load LC_COLORS environment from it.
if [ -r ~/.dircolors ]; then
    eval $(dircolors -b ~/.dircolors)
fi

This should load the new color settings into every new bash shell you launch.

Running info coreutils 'dircolors invocation' will give you the detailed documentation.

ameametalk 08-16-2010 09:50 AM

Simple and good advice
 
Hi David,
Thank you for additional information. It is almost what I'd like to try, but more helpful, as I did not have an idea you indicated. (using dircolor command and output file so as to modify LS_COLORS directly) I already confirmed my terminal worked fine along with your setup code. Thanks a lot!


All times are GMT -5. The time now is 10:22 AM.