Created
January 3, 2012 11:15
-
-
Save sjg/1554522 to your computer and use it in GitHub Desktop.
Color Lines in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define RESET 0 | |
#define BRIGHT 1 | |
#define DIM 2 | |
#define UNDERLINE 3 | |
#define BLINK 4 | |
#define REVERSE 7 | |
#define HIDDEN 8 | |
#define BLACK 0 | |
#define RED 1 | |
#define GREEN 2 | |
#define YELLOW 3 | |
#define BLUE 4 | |
#define MAGENTA 5 | |
#define CYAN 6 | |
#define WHITE 7 | |
void textcolor(int attr, int fg, int bg); | |
int main() | |
{ textcolor(BRIGHT, RED, BLACK); | |
printf("In color\n"); | |
textcolor(RESET, WHITE, BLACK); | |
return 0; | |
} | |
void textcolor(int attr, int fg, int bg) | |
{ char command[13]; | |
/* Command is the control command to the terminal */ | |
sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40); | |
printf("%s", command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment