Skip to content

Instantly share code, notes, and snippets.

@idolpx
Forked from RabaDabaDoba/ANSI-color-codes.h
Last active April 18, 2022 18:51
Show Gist options
  • Save idolpx/00ebff2307a3dbd68b97829f98d01a0f to your computer and use it in GitHub Desktop.
Save idolpx/00ebff2307a3dbd68b97829f98d01a0f to your computer and use it in GitHub Desktop.
The entire table of ANSI color codes working in C!
/*
* This is free and unencumbered software released into the public domain.
*
* For more information, please refer to <https://unlicense.org>
*/
//Regular text
#define ANSI_BLACK "\e[0;30m"
#define ANSI_RED "\e[0;31m"
#define ANSI_GREEN "\e[0;32m"
#define ANSI_YELLOW "\e[0;33m"
#define ANSI_BLUE "\e[0;34m"
#define ANSI_MAGENTA "\e[0;35m"
#define ANSI_CYAN "\e[0;36m"
#define ANSI_WHITE "\e[0;37m"
//Regular bold text
#define ANSI_BLACK_BOLD "\e[1;30m"
#define ANSI_RED_BOLD "\e[1;31m"
#define ANSI_GREEN_BOLD "\e[1;32m"
#define ANSI_YELLOW_BOLD "\e[1;33m"
#define ANSI_BLUE_BOLD "\e[1;34m"
#define ANSI_MAGENTA_BOLD "\e[1;35m"
#define ANSI_CYAN_BOLD "\e[1;36m"
#define ANSI_WHITE_BOLD "\e[1;37m"
//Regular dim text
#define ANSI_BLACK_DIM "\e[2;30m"
#define ANSI_RED_DIM "\e[2;31m"
#define ANSI_GREEN_DIM "\e[2;32m"
#define ANSI_YELLOW_DIM "\e[2;33m"
#define ANSI_BLUE_DIM "\e[2;34m"
#define ANSI_MAGENTA_DIM "\e[2;35m"
#define ANSI_CYAN_DIM "\e[2;36m"
#define ANSI_WHITE_DIM "\e[2;37m"
//Regular italics text
#define ANSI_BLACK_ITALICS "\e[3;30m"
#define ANSI_RED_ITALICS "\e[3;31m"
#define ANSI_GREEN_ITALICS "\e[3;32m"
#define ANSI_YELLOW_ITALICS "\e[3;33m"
#define ANSI_BLUE_ITALICS "\e[3;34m"
#define ANSI_MAGENTA_ITALICS "\e[3;35m"
#define ANSI_CYAN_ITALICS "\e[3;36m"
#define ANSI_WHITE_ITALICS "\e[3;37m"
//Regular underline text
#define ANSI_BLACK_UNDERLINE "\e[4;30m"
#define ANSI_RED_UNDERLINE "\e[4;31m"
#define ANSI_GREEN_UNDERLINE "\e[4;32m"
#define ANSI_YELLOW_UNDERLINE "\e[4;33m"
#define ANSI_BLUE_UNDERLINE "\e[4;34m"
#define ANSI_MAGENTA_UNDERLINE "\e[4;35m"
#define ANSI_CYAN_UNDERLINE "\e[4;36m"
#define ANSI_WHITE_UNDERLINE "\e[4;37m"
//Regular reversed text
#define ANSI_BLACK_REVERSED "\e[7;30m"
#define ANSI_RED_REVERSED "\e[7;31m"
#define ANSI_GREEN_REVERSED "\e[7;32m"
#define ANSI_YELLOW_REVERSED "\e[7;33m"
#define ANSI_BLUE_REVERSED "\e[7;34m"
#define ANSI_MAGENTA_REVERSED "\e[7;35m"
#define ANSI_CYAN_REVERSED "\e[7;36m"
#define ANSI_WHITE_REVERSED "\e[7;37m"
//Regular background
#define ANSI_BLACK_BACKGROUND "\e[40m"
#define ANSI_RED_BACKGROUND "\e[41m"
#define ANSI_GREEN_BACKGROUND "\e[42m"
#define ANSI_YELLOW_BACKGROUND "\e[43m"
#define ANSI_BLUE_BACKGROUND "\e[44m"
#define ANSI_MAGENTA_BACKGROUND "\e[45m"
#define ANSI_CYAN_BACKGROUND "\e[46m"
#define ANSI_WHITE_BACKGROUND "\e[47m"
//High intensty background
#define ANSI_BLACK_HIGH_INTENSITY_BACKGROUND "\e[0;100m"
#define ANSI_RED_HIGH_INTENSITY_BACKGROUND "\e[0;101m"
#define ANSI_GREEN_HIGH_INTENSITY_BACKGROUND "\e[0;102m"
#define ANSI_YELLOW_HIGH_INTENSITY_BACKGROUND "\e[0;103m"
#define ANSI_BLUE_HIGH_INTENSITY_BACKGROUND "\e[0;104m"
#define ANSI_MAGENTA_HIGH_INTENSITY_BACKGROUND "\e[0;105m"
#define ANSI_CYAN_HIGH_INTENSITY_BACKGROUND "\e[0;106m"
#define ANSI_WHITE_HIGH_INTENSITY_BACKGROUND "\e[0;107m"
//High intensty text
#define ANSI_BLACK_HIGH_INTENSITY "\e[0;90m"
#define ANSI_RED_HIGH_INTENSITY "\e[0;91m"
#define ANSI_GREEN_HIGH_INTENSITY "\e[0;92m"
#define ANSI_YELLOW_HIGH_INTENSITY "\e[0;93m"
#define ANSI_BLUE_HIGH_INTENSITY "\e[0;94m"
#define ANSI_MAGENTA_HIGH_INTENSITY "\e[0;95m"
#define ANSI_CYAN_HIGH_INTENSITY "\e[0;96m"
#define ANSI_WHITE_HIGH_INTENSITY "\e[0;97m"
//Bold high intensity text
#define ANSI_BLACK_BOLD_HIGH_INTENSITY "\e[1;90m"
#define ANSI_RED_BOLD_HIGH_INTENSITY "\e[1;91m"
#define ANSI_GREEN_BOLD_HIGH_INTENSITY "\e[1;92m"
#define ANSI_YELLOW_BOLD_HIGH_INTENSITY "\e[1;93m"
#define ANSI_BLUE_BOLD_HIGH_INTENSITY "\e[1;94m"
#define ANSI_MAGENTA_BOLD_HIGH_INTENSITY "\e[1;95m"
#define ANSI_CYAN_BOLD_HIGH_INTENSITY "\e[1;96m"
#define ANSI_WHITE_BOLD_HIGH_INTENSITY "\e[1;97m"
//Reset
#define ANSI_RESET "\e[0m"
#define ANSI_RESET_NL "\e[0m\n"

Regular Colors

Value Color
\e[0;30m Black
\e[0;31m Red
\e[0;32m Green
\e[0;33m Yellow
\e[0;34m Blue
\e[0;35m Purple
\e[0;36m Cyan
\e[0;37m White

Bold

Value Color
\e[1;30m Black
\e[1;31m Red
\e[1;32m Green
\e[1;33m Yellow
\e[1;34m Blue
\e[1;35m Purple
\e[1;36m Cyan
\e[1;37m White

Underline

Value Color
\e[4;30m Black
\e[4;31m Red
\e[4;32m Green
\e[4;33m Yellow
\e[4;34m Blue
\e[4;35m Purple
\e[4;36m Cyan
\e[4;37m White

Background

Value Color
\e[40m Black
\e[41m Red
\e[42m Green
\e[43m Yellow
\e[44m Blue
\e[45m Purple
\e[46m Cyan
\e[47m White

High Intensty

Value Color
\e[0;90m Black
\e[0;91m Red
\e[0;92m Green
\e[0;93m Yellow
\e[0;94m Blue
\e[0;95m Purple
\e[0;96m Cyan
\e[0;97m White

Bold High Intensty

Value Color
\e[1;90m Black
\e[1;91m Red
\e[1;92m Green
\e[1;93m Yellow
\e[1;94m Blue
\e[1;95m Purple
\e[1;96m Cyan
\e[1;97m White

High Intensty backgrounds

Value Color
\e[0;100m Black
\e[0;101m Red
\e[0;102m Green
\e[0;103m Yellow
\e[0;104m Blue
\e[0;105m Purple
\e[0;106m Cyan
\e[0;107m White

Reset

Value Color
\e[0m Reset
\e[0m CRESET
\e[0m COLOR_RESET
#include "ANSI-color-codes.h"
#include <stdio.h>
int main(){
printf(ANSI_RED_BOLD "Hey this is the color red, and it's bold! \n" ANSI_RESET);
printf(ANSI_RED "If" ANSI_BLUE "you" ANSI_YELLOW "are" ANSI_GREEN "bored" ANSI_CYAN "do" ANSI_MAGENTA "this!" ANSI_RESET_NL);
printf(ANSI_RED_BOLD "If" ANSI_BLUE_BOLD "you" ANSI_YELLOW_BOLD "are" ANSI_GREEN_BOLD "bored" ANSI_CYAN_BOLD "do" ANSI_MAGENTA_BOLD "this!" ANSI_RESET_NL);
printf(ANSI_RED_UNDERLINE "If" ANSI_BLUE_UNDERLINE "you" ANSI_YELLOW_UNDERLINE "are" ANSI_GREEN_UNDERLINE "bored" ANSI_CYAN_UNDERLINE "do" ANSI_MAGENTA_UNDERLINE "this!" ANSI_RESET_NL);
return 0;};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment