LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2002, 06:32 PM   #1
JustinH
LQ Newbie
 
Registered: Nov 2002
Posts: 2

Rep: Reputation: 0
Color Console


How do you output text in different colors?

In Windows you can use
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), MyColor);
but this doesn't work in *nix

Thanks in advance
 
Old 11-28-2002, 06:55 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what language?
 
Old 11-28-2002, 07:02 PM   #3
JustinH
LQ Newbie
 
Registered: Nov 2002
Posts: 2

Original Poster
Rep: Reputation: 0
C++
 
Old 12-05-2002, 05:25 PM   #4
JCZorch
LQ Newbie
 
Registered: Nov 2002
Posts: 6

Rep: Reputation: 0
anyone know?
 
Old 04-25-2003, 01:30 AM   #5
IceGrill
LQ Newbie
 
Registered: Jan 2002
Distribution: Mandrake
Posts: 25

Rep: Reputation: 15
yeh...i wanted to know too. they say you need an OS-specific library to handle colors, however I have no idea what linux libraries exist....
 
Old 04-29-2003, 01:20 PM   #6
tiberius
LQ Newbie
 
Registered: Apr 2003
Location: USA
Distribution: Mandrake
Posts: 3

Rep: Reputation: 0
Use terminal commands to change the colors on the terminal.
For example:
printf("\033[22;31mHello, world!\n");
will print 'Hello, world!' with a red foreground at normal intensity

\033[ - the character sequence to start a terminal command
22 - normal intensity
31m - red

You can make the text blink and do other ugly things, too.
Also, you can use terminal commands in your command prompt if you are so inclined.
Type 'man console_codes' for more details.

Alternatively you can use the ncurses library when programming in C/C++.
 
Old 04-30-2003, 03:02 PM   #7
Nukes
Member
 
Registered: Apr 2003
Location: Scotland UK
Distribution: Gentoo
Posts: 92

Rep: Reputation: 15
Just to elaborate on this. What this is is the use of ANSI codes to change colours.
the \033 is the ANSI escape sequence that starts the block.
Colour codes can be found here:
http://pueblo.sourceforge.net/doc/ma...lor_codes.html
 
  


Reply



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
How to get a color text console? dejavu_01 Debian 1 08-30-2005 11:38 AM
Console Color Changes? darioush Red Hat 4 09-16-2003 01:38 AM
default console color boob Linux - Software 1 09-07-2003 12:19 AM
changing console color? Wilson Linux - General 14 05-25-2003 09:29 PM
color in console qanopus Linux - General 2 12-13-2002 08:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:08 PM.

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
Open Source Consulting | Domain Registration