Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,501 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,378 people online right now. Registration is fast and FREE... Join Now!




Changing Terminal's BG color in C

 
Reply to this topicStart new topic

Changing Terminal's BG color in C, Apple's Terminal Background Color

lifeRoot
1 Apr, 2007 - 08:05 PM
Post #1

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 23


My Contributions
I just recently bought an apple and I'm not very familiar with unix commands, so I was wondering if anyone knows the command to change the terminal's background and text color...

I was going to use this command in my program:
CODE

system(<change background color here>);


because I think doing it any other way will be much more difficult...

I'm writing a StickyNotes program and wanted it to be yellow and black smile.gif

Thanks!

This post has been edited by lifeRoot: 1 Apr, 2007 - 08:06 PM
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Changing Terminal's BG Color In C
2 Apr, 2007 - 08:45 AM
Post #2

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 298



Thanked: 2 times
Dream Kudos: 50
My Contributions
http://www.developer.com/open/article.php/631241
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

The first link describes how to control the colors better, I think. However, I don't think these two articles give you the answer you are looking for.

Changing the overal background of the consol will be in the XWindows interface of the console itself. So if you want control over the entire background of then consol you wil need to write a UI or a GUI Program rather than a console program. I have just posted an answer to a simular question at :
http://www.dreamincode.net/forums/showtopic25845.htm

(OS X falls into the *nix category)
User is offlineProfile CardPM
+Quote Post

lifeRoot
RE: Changing Terminal's BG Color In C
2 Apr, 2007 - 04:14 PM
Post #3

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 23


My Contributions
Thanks! One of the links had some info that helped me figure it out!

I would much rather write a stand-alone program than use console but I don't know how sad.gif

I have done a little VB before... I have apple's Xcode too... is there anything I can use to make a graphical, window-based, program using C??

User is offlineProfile CardPM
+Quote Post

lifeRoot
RE: Changing Terminal's BG Color In C
2 Apr, 2007 - 11:59 PM
Post #4

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 23


My Contributions
Ok, here's the solution, thanks to ajwsurfer, for anyone else that might be interested:
CODE

printf("\033[34mThis is blue.\033[0m\n");


See that 34? That's what you use to change colors...

\033[34mThis is blue.\033[0m

Here's a list of different colors:
30 black foreground
31 red foreground
32 green foreground
33 brown foreground
34 blue foreground
35 magenta (purple) foreground
36 cyan (light blue) foreground
37 gray foreground

40 black background
41 red background
42 green background
43 brown background
44 blue background
45 magenta background
46 cyan background
47 white background

Commands can also be combined using a semicolon, like so:
CODE

printf("\033[45;37mGrey on purple.\033[0m");


Finally here is a list of other neat commands that go at the end (where the '0' is):
0 reset all attributes to their defaults
1 set bold
5 set blink
7 set reverse video
22 set normal intensity
25 blink off
27 reverse video off
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 06:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month