|
|
| GCC: The Complete Reference (ISBN: 0072224053) |
 |
List Price: $59.99
Our Price: $41.99
Used Price:
Release Date: 28 August, 2002
Manufacturer: McGraw-Hill Osborne Media (Paperback)
Sales Rank: 19,110
Author: Arthur Griffith
|
More Info
|
|
|
Colours in Linux
|
2002-02-05 13:28:00
|
| |
c
|
|
|
|
|
Category: source:c:linux
|
|
Description: Display different colours on your linux console.
|
|
Platform: unix
|
|
Author: detour
|
|
Viewed: 3415
|
|
Rating: 4.5/5 (31 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
/* colour.c written by detour@metalshell.com
*
* This is an example of how to use colours on your linux
* console. It is a simple loop that cycles through the
* different options, and the different colours.
*
* Colours:
* Black 0;30 Dark Gray 1;30
* Blue 0;34 Light Blue 1;34
* Green 0;32 Light Green 1;32
* Cyan 0;36 Light Cyan 1;36
* Red 0;31 Light Red 1;31
* Purple 0;35 Light Purple 1;35
* Brown 0;33 Yellow 1;33
* Light Gray 0;37 White 1;37
* ---------------------------------------
*
* You can also do really leet things like make the colour
* blink by changing the option to 5. Everyone loves blinking
* things. To get the background colour simply add 10.
*
* http://www.metalshell.com/
*
*/
#include <stdio.h>
void setFG(int opt, int colour);
void setBG(int colour);
void resetcolour();
int main() {
int x, y;
for(x = 1; x < 9; x++)
for(y = 30; y < 38; y++) {
setFG(x,y);
printf("Wheee Colour!\n");
}
resetcolour();
printf("Now doing background colours\n");
for(x = 40; x < 48; x++) {
setBG(x);
printf("Wheee Colour!\n");
}
resetcolour();
}
void setFG(int opt, int colour) {
printf("\033[%d;%dm", opt, colour);
}
void setBG(int colour) {
printf("\033[%dm", colour);
}
void resetcolour() {
printf("\033[0;m");
}
|
|
|