Skip to content

Instantly share code, notes, and snippets.

@RabaDabaDoba
Forked from iamnewton/bash-colors.md
Last active December 2, 2024 19:23
Show Gist options
  • Save RabaDabaDoba/145049536f815903c79944599c6f952a to your computer and use it in GitHub Desktop.
Save RabaDabaDoba/145049536f815903c79944599c6f952a 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 BLK "\e[0;30m"
#define RED "\e[0;31m"
#define GRN "\e[0;32m"
#define YEL "\e[0;33m"
#define BLU "\e[0;34m"
#define MAG "\e[0;35m"
#define CYN "\e[0;36m"
#define WHT "\e[0;37m"
//Regular bold text
#define BBLK "\e[1;30m"
#define BRED "\e[1;31m"
#define BGRN "\e[1;32m"
#define BYEL "\e[1;33m"
#define BBLU "\e[1;34m"
#define BMAG "\e[1;35m"
#define BCYN "\e[1;36m"
#define BWHT "\e[1;37m"
//Regular underline text
#define UBLK "\e[4;30m"
#define URED "\e[4;31m"
#define UGRN "\e[4;32m"
#define UYEL "\e[4;33m"
#define UBLU "\e[4;34m"
#define UMAG "\e[4;35m"
#define UCYN "\e[4;36m"
#define UWHT "\e[4;37m"
//Regular background
#define BLKB "\e[40m"
#define REDB "\e[41m"
#define GRNB "\e[42m"
#define YELB "\e[43m"
#define BLUB "\e[44m"
#define MAGB "\e[45m"
#define CYNB "\e[46m"
#define WHTB "\e[47m"
//High intensty background
#define BLKHB "\e[0;100m"
#define REDHB "\e[0;101m"
#define GRNHB "\e[0;102m"
#define YELHB "\e[0;103m"
#define BLUHB "\e[0;104m"
#define MAGHB "\e[0;105m"
#define CYNHB "\e[0;106m"
#define WHTHB "\e[0;107m"
//High intensty text
#define HBLK "\e[0;90m"
#define HRED "\e[0;91m"
#define HGRN "\e[0;92m"
#define HYEL "\e[0;93m"
#define HBLU "\e[0;94m"
#define HMAG "\e[0;95m"
#define HCYN "\e[0;96m"
#define HWHT "\e[0;97m"
//Bold high intensity text
#define BHBLK "\e[1;90m"
#define BHRED "\e[1;91m"
#define BHGRN "\e[1;92m"
#define BHYEL "\e[1;93m"
#define BHBLU "\e[1;94m"
#define BHMAG "\e[1;95m"
#define BHCYN "\e[1;96m"
#define BHWHT "\e[1;97m"
//Reset
#define reset "\e[0m"
#define CRESET "\e[0m"
#define COLOR_RESET "\e[0m"

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(BRED "Hey this is the color red, and it's bold! \n" reset);
printf(RED "If" BLU "you" YEL "are" GRN "bored" CYN "do" MAG "this! \n" reset);
printf(BRED "If" BBLU "you" BYEL "are" BGRN "bored" BCYN "do" BMAG "this! \n" reset);
printf(URED "If" UBLU "you" UYEL "are" UGRN "bored" UCYN "do" UMAG "this! \n" reset);
return 0;};
@DavePvZ
Copy link

DavePvZ commented Jul 5, 2022

Thanks!
hug

@xtrm-en
Copy link

xtrm-en commented Jul 22, 2022

many thanks!

@vitortvale
Copy link

exactly what I needed , thanks!

@BhartiRajesh99
Copy link

Not working! Plz help

@RabaDabaDoba
Copy link
Author

Not working! Plz help

Well it does work, do you have it all in the correct folder? Or missing some library? Since that's like the only causes of it not working.

@MohamedASattar
Copy link

Really fascinated

@mr-cheff
Copy link

mr-cheff commented Mar 3, 2023

@BhartiRajesh99

Not working! Plz help

maybe instead of just saying "help me!", try to show us an error or what you expected to happen vs what actually showed in the terminal or something. Thanks

@FOSSBOSS
Copy link

LoL, I literally just wrote this. I see you found some over 100 I didn't think to look for, so thanks for that.
I like how you used defines, instead of function calls. A difference in my header, is I took all the defines and made an array. that way I can create random color effects, or functions for colors, by passing the array an index.
you might want to add:
#ifndef ANSI_color_codes_H
#define ANSI_color_codes_H
#endif

while its not a color code, there is also underscore, and double underscore at:
#define UNDERLINE "\033[0;52m"
#define UNDERLINE_2 "\033[0;21m"

@Siavash1291
Copy link

When I utilize this library, it functions properly in the VS Code console. However, when I execute the console application in Windows CMD, the boldness of the texts is not displayed. Only the colors and backgrounds are shown.

@Alilqq
Copy link

Alilqq commented Jul 10, 2023

Is there a way I can use a hex/rgb color code in ansi?

@Sh0g0-1758
Copy link

This is just what I needed. Thanks a lot.

@V1ach
Copy link

V1ach commented Nov 20, 2023

It doesn't work, help plz.
My output using this library looks like:

e[0;31m>> Select input:

>> 1 - random
>> 2 - manual
e[0m

e[0;31m appears instead of colored text. I think smth wrong with my console. I'm using Visual Studio 2019 with Windows 10. Tried to use this library on my another laptop, with the same config, but the same result. Help me plz :3

@mr-cheff
Copy link

ur terminal might just not support it

@RonaldoMiral
Copy link

Thanks a lot! It is working.😐

@SaxbyMod
Copy link

SaxbyMod commented Sep 28, 2024

Here's a better setup may update this more if I find some more modes for example on HighIntensityBackgroundColor. This goes in the same order as the above list just instead of separate var's its a list for each type.

        string[] ColorList = ["\u001b[0;30m", "\u001b[0;31m", "\u001b[0;32m", "\u001b[0;33m", "\u001b[0;34m", "\u001b[0;35m", "\u001b[0;36m", "\u001b[0;37m"];
        string[] BoldColorList = ["\u001b[1;30m", "\u001b[1;31m", "\u001b[1;32m", "\u001b[1;33m", "\u001b[1;34m", "\u001b[1;35m", "\u001b[1;36m", "\u001b[1;37m"];
        string[] DarkenedColorList = ["\u001b[2;30m", "\u001b[2;31m", "\u001b[2;32m", "\u001b[2;33m", "\u001b[2;34m", "\u001b[2;35m", "\u001b[2;36m", "\u001b[2;37m"];
        string[] ItalicColorList = ["\u001b[3;30m", "\u001b[3;31m", "\u001b[3;32m", "\u001b[3;33m", "\u001b[3;34m", "\u001b[3;35m", "\u001b[3;36m", "\u001b[3;37m"];
        string[] UnderlineColorList = ["\u001b[4;30m", "\u001b[4;31m", "\u001b[4;32m", "\u001b[4;33m", "\u001b[4;34m", "\u001b[4;35m", "\u001b[4;36m", "\u001b[4;37m"];
        string[] FlashyColorList = ["\u001b[5;30m", "\u001b[5;31m", "\u001b[5;32m", "\u001b[5;33m", "\u001b[5;34m", "\u001b[5;35m", "\u001b[5;36m", "\u001b[5;37m"];
        string[] HighlighterColorText = ["\u001b[7;30m", "\u001b[7;31m", "\u001b[7;32m", "\u001b[7;33m", "\u001b[7;34m", "\u001b[7;35m", "\u001b[7;36m", "\u001b[7;37m"];
        string[] InvisibleColorText = ["\u001b[8;30m", "\u001b[8;31m", "\u001b[8;32m", "\u001b[8;33m", "\u001b[8;34m", "\u001b[8;35m", "\u001b[8;36m", "\u001b[8;37m"];
        string[] StrikethroughColorText = ["\u001b[9;30m", "\u001b[9;31m", "\u001b[9;32m", "\u001b[9;33m", "\u001b[9;34m", "\u001b[9;35m", "\u001b[9;36m", "\u001b[9;37m"];
        string[] BackgroundColorList = ["\u001b[40m", "\u001b[41m", "\u001b[42m", "\u001b[43m", "\u001b[44m", "\u001b[45m", "\u001b[46m", "\u001b[47m"];
        string[] HighInstensityBsckgroundColorList = ["\u001b[0;100m", "\u001b[0;101m", "\u001b[0;102m", "\u001b[0;103m", "\u001b[0;104m", "\u001b[0;105m", "\u001b[0;106m", "\u001b[0;107m"];
        string[] HighIntensityColorList = ["\u001b[0;90m", "\u001b[0;91m", "\u001b[0;92m", "\u001b[0;93m", "\u001b[0;94m", "\u001b[0;95m", "\u001b[0;96m", "\u001b[0;97m"];
        string[] HighIntensityBoldColorList = ["\u001b[1;90m", "\u001b[1;91m", "\u001b[1;92m", "\u001b[1;93m", "\u001b[1;94m", "\u001b[1;95m", "\u001b[1;96m", "\u001b[1;97m"];
        string[] HighIntensityDarkenedColorList = ["\u001b[2;90m", "\u001b[2;91m", "\u001b[2;92m", "\u001b[2;93m", "\u001b[2;94m", "\u001b[2;95m", "\u001b[2;96m", "\u001b[2;97m"];
        string[] HighIntensityItalicColorList = ["\u001b[9;90m", "\u001b[9;91m", "\u001b[9;92m", "\u001b[9;93m", "\u001b[9;94m", "\u001b[9;95m", "\u001b[9;96m", "\u001b[9;97m"];
        string[] HighIntensityUnderlineColorList = ["\u001b[4;90m", "\u001b[4;91m", "\u001b[4;92m", "\u001b[4;93m", "\u001b[4;94m", "\u001b[4;95m", "\u001b[4;96m", "\u001b[4;97m"];
        string[] HighIntensityFlashyColorList = ["\u001b[5;90m", "\u001b[5;91m", "\u001b[5;92m", "\u001b[5;93m", "\u001b[5;94m", "\u001b[5;95m", "\u001b[5;96m", "\u001b[5;97m"];
        string[] HighIntensityHighlighterColorText = ["\u001b[7;90m", "\u001b[7;91m", "\u001b[7;92m", "\u001b[7;93m", "\u001b[7;94m", "\u001b[7;95m", "\u001b[7;96m", "\u001b[7;97m"];
        string[] HighIntensityInvisibleColorText = ["\u001b[8;90m", "\u001b[8;91m", "\u001b[8;92m", "\u001b[8;93m", "\u001b[8;94m", "\u001b[8;95m", "\u001b[8;96m", "\u001b[8;97m"];
        string[] HighIntensityStrikethroughColorText = ["\u001b[9;90m", "\u001b[9;91m", "\u001b[9;92m", "\u001b[9;93m", "\u001b[9;94m", "\u001b[9;95m", "\u001b[9;96m", "\u001b[9;97m"];
        string ResetColor = "\u001b[0m";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment