Colors.h is a simple C header for stylish text in terminal based on colors.hpp.
The library uses ANSI escape sequences to apply colors and styles to the terminal. Windows is supported through its API, to see what features are available, see the methods list below.
Just add the colors.h
from include/colors/colors.h
file to your project's include folder.
- Example with gcc
gcc test.c -o build/test -I include/
As an only-header library, just include the header in your file as shown below. There are some macros and functions to provide the colors and styles:
#include <stdio.h>
#include <colors/colors.h>
int main() {
on_red();
puts("You can use the colors functions as shown below!");
reset();
printf("%sThere is some macros too%s, this %sway%s, you can use multiple styles in one string", ON_RED, RESET, BOLD, RESET);
puts("Remember to use RESET macro or reset() function to remove the styles!");
}
Important 1: If your project doesn't have a include folder, use the #include "colors.h"
directive instead!
Important 2: You must not forget to use reset
, otherwise, the colors and styles will be applied to the next output! In windows cmd, the colors are applied even if the program has already ended, so be sure to use this!
There are three types of functions/macros defined in the library:
- Style: changes the text decoration style;
- Foreground: changes the text color itself;
- Background: changes the text background color;
Note 1: Some terminals don't support some of this features, like blinking!
Note 2: Windows doesn't support these manipulators!
bold() or BOLD
faint() or FAINT
italic() or ITALIC
underline() or UNDERLINE
blink() or BLINK
reverse() or REVERSE
invisible() or INVISIBLE
strikethrough() or STRIKETHROUGH
grey() or GREY
red() or RED
green() or GREEN
yellow() or YELLOW
blue() or BLUE
magenta() or MAGENTA
cyan() or CYAN
white() or WHITE
bright_grey() or BRIGHT_GREY
bright_red() or BRIGHT_RED
bright_green() or BRIGHT_GREEN
bright_yellow() or BRIGHT_YELLOW
bright_blue() or BRIGHT_BLUE
bright_magenta() or BRIGHT_MAGENTA
bright_cyan() or BRIGHT_CYAN
bright_white() or BRIGHT_WHITE
You can find the color codes here.
Note: Windows doesn't support this function!
void color256(int color_code);
Note: Not all terminals supports this feature!
Note 2: Windows doesn't support this function!
void color_rgb(int r, int g, int b);
on_grey() or ON_GREY
on_red() or ON_RED
on_green() or ON_GREEN
on_yellow() or ON_YELLOW
on_blue() or ON_BLUE
on_magenta() or ON_MAGENTA
on_cyan() or ON_CYAN
on_white() or ON_WHITE
on_bright_grey() or ON_BRIGHT_GREY
on_bright_red() or ON_BRIGHT_GREY
on_bright_green() or ON_BRIGHT_GREY
on_bright_yellow() or ON_BRIGHT_YELLOW
on_bright_blue() or ON_BRIGHT_BLUE
on_bright_magenta() or ON_BRIGHT_MAGENTA
on_bright_cyan() or ON_BRIGHT_CYAN
on_bright_white() or ON_BRIGHT_WHITE
You can find the color codes here.
Note: Windows doesn't support this function!
void on_color256(int color_code);
Note 1: Not all terminals supports this feature!
Note 2: Windows doesn't support this function!
void on_color_rgb(int r, int g, int b);
Thanks for visiting my repository!