LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2010, 01:43 PM   #1
ameametalk
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Rep: Reputation: 0
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,
 
Old 08-11-2010, 03:10 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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.

Last edited by David the H.; 08-11-2010 at 03:23 PM. Reason: as posted, + minor changes for clarity
 
Old 08-11-2010, 09:30 PM   #3
ameametalk
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Original Poster
Rep: Reputation: 0
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!
 
Old 08-12-2010, 12:22 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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.
 
Old 08-16-2010, 09:50 AM   #5
ameametalk
LQ Newbie
 
Registered: Aug 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thumbs up 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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Indicator Applet Session 0.3.7 change text color in Gnome Panel 2.30.0 mkisow Linux - Desktop 1 11-20-2010 11:58 PM
Blocky text in gnome-terminal schnauzer93 Linux - Software 1 07-14-2009 06:45 PM
Changing Terminal Text Color By Recompiling Kernel kwikness Slackware 6 07-21-2007 11:27 AM
Strange message showed up in gnome-terminal fakie_flip Linux - Security 1 05-21-2007 05:32 AM
How to add color to ls in Slackware gnome-terminal? Onox Linux - Software 10 06-22-2003 09:26 PM


All times are GMT -5. The time now is 08:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration