Colors!

Colored console output wasn’t something I ever really explored until this quarter, so I thought I’d share how easy it actually is and how I’ve set it up to be simpler for me and easier to read!

These are the codes I’ve set up:

#define SET_BOLD_RED        "\033[1;31m"
#define SET_RED             "\033[0;31m"
#define SET_BOLD_GREEN      "\033[1;32m"
#define SET_GREEN           "\033[0;32m"
#define SET_BOLD_YELLOW     "\033[1;33m"
#define SET_YELLOW          "\033[0;33m"
#define SET_BOLD_BLUE       "\033[1;34m"
#define SET_BLUE            "\033[0;34m"
#define SET_BOLD_MAGENTA    "\033[1;35m"
#define SET_MAGENTA         "\033[0;35m"
#define SET_BOLD_CYAN       "\033[1;36m"
#define SET_CYAN            "\033[0;36m"
#define RESET_COLOR         "\033[0m"

To use them, you want to “print” them to the console. So to make something red, I’d print SET_RED, then the text, then RESET_COLOR to set it back to normal. Pretty simple and most importantly, readable!

printf("%sRed%s\n", SET_RED, RESET_COLOR);

Bad quality screenshot example 🙂

Source I learned from:

Adding Color to Your Output From C

2 Replies to “Colors!”

Leave a Reply

Your email address will not be published. Required fields are marked *