Created
November 4, 2016 17:18
-
-
Save jampajeen/d917a4556487b0e2ea04e2bc848a43a0 to your computer and use it in GitHub Desktop.
console text color
This file contains hidden or 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> | |
#include <cstdlib> | |
#define CLEAR "\x1b[2J" // clear | |
#define RESET "\x1b[0m" // reset color style | |
#define BLACK "\x1b[30m" /* Black */ | |
#define RED "\x1b[31m" /* Red */ | |
#define GREEN "\x1b[32m" /* Green */ | |
#define YELLOW "\x1b[33m" /* Yellow */ | |
#define BLUE "\x1b[34m" /* Blue */ | |
#define MAGENTA "\x1b[35m" /* Magenta */ | |
#define CYAN "\x1b[36m" /* Cyan */ | |
#define WHITE "\x1b[37m" /* White */ | |
#define BOLDBLACK "\x1b[1m\x1b[30m" /* Bold Black */ | |
#define BOLDRED "\x1b[1m\x1b[31m" /* Bold Red */ | |
#define BOLDGREEN "\x1b[1m\x1b[32m" /* Bold Green */ | |
#define BOLDYELLOW "\x1b[1m\x1b[33m" /* Bold Yellow */ | |
#define BOLDBLUE "\x1b[1m\x1b[34m" /* Bold Blue */ | |
#define BOLDMAGENTA "\x1b[1m\x1b[35m" /* Bold Magenta */ | |
#define BOLDCYAN "\x1b[1m\x1b[36m" /* Bold Cyan */ | |
#define BOLDWHITE "\x1b[1m\x1b[37m" /* Bold White */ | |
#define STYLE_NORMAL 0 | |
#define STYLE_BRIGHT 1 | |
#define STYLE_DIM 2 | |
#define STYLE_UNDERLINE 3 | |
#define STYLE_BLINK 4 | |
#define STYLE_REVERSE 7 | |
#define STYLE_HIDDEN 8 | |
#define FG_BLACK 30 | |
#define FG_RED 31 | |
#define FG_GREEN 32 | |
#define FG_YELLOW 33 | |
#define FG_BLUE 34 | |
#define FG_MAGENTA 35 | |
#define FG_CYAN 36 | |
#define FG_WHITE 37 | |
#define BG_BLACK 40 | |
#define BG_RED 41 | |
#define BG_GREEN 42 | |
#define BG_YELLOW 43 | |
#define BG_BLUE 44 | |
#define BG_MAGENTA 45 | |
#define BG_CYAN 46 | |
#define BG_WHITE 47 | |
void textStyleReset() { | |
printf(RESET); | |
} | |
void textStyleBegin(int attr, int fg, int bg) { | |
printf("%c[%d;%d;%dm", 0x1b, attr, fg, bg); | |
} | |
int main() { | |
printf(RED "OK" RESET); | |
textStyleBegin(STYLE_BRIGHT, FG_RED, BG_YELLOW); | |
printf("CANCEL"); | |
textStyleReset(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment