Skip to content

hugorplobo/colors.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

colors.h

Example of usage

Colors.h is a simple C header for stylish text in terminal based on colors.hpp.

How it works

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.

Installation

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/

Usage

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!

What colors can I use?

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;

Style

Note 1: Some terminals don't support some of this features, like blinking!

Note 2: Windows doesn't support these manipulators!

  1. bold() or BOLD
  2. faint() or FAINT
  3. italic() or ITALIC
  4. underline() or UNDERLINE
  5. blink() or BLINK
  6. reverse() or REVERSE
  7. invisible() or INVISIBLE
  8. strikethrough() or STRIKETHROUGH

Foreground

Named Colors

  1. grey() or GREY
  2. red() or RED
  3. green() or GREEN
  4. yellow() or YELLOW
  5. blue() or BLUE
  6. magenta() or MAGENTA
  7. cyan() or CYAN
  8. white() or WHITE
  9. bright_grey() or BRIGHT_GREY
  10. bright_red() or BRIGHT_RED
  11. bright_green() or BRIGHT_GREEN
  12. bright_yellow() or BRIGHT_YELLOW
  13. bright_blue() or BRIGHT_BLUE
  14. bright_magenta() or BRIGHT_MAGENTA
  15. bright_cyan() or BRIGHT_CYAN
  16. bright_white() or BRIGHT_WHITE

256 Colors

You can find the color codes here.

Note: Windows doesn't support this function!

  1. void color256(int color_code);

RGB Colors

Note: Not all terminals supports this feature!

Note 2: Windows doesn't support this function!

  1. void color_rgb(int r, int g, int b);

Background

Named Colors

  1. on_grey() or ON_GREY
  2. on_red() or ON_RED
  3. on_green() or ON_GREEN
  4. on_yellow() or ON_YELLOW
  5. on_blue() or ON_BLUE
  6. on_magenta() or ON_MAGENTA
  7. on_cyan() or ON_CYAN
  8. on_white() or ON_WHITE
  9. on_bright_grey() or ON_BRIGHT_GREY
  10. on_bright_red() or ON_BRIGHT_GREY
  11. on_bright_green() or ON_BRIGHT_GREY
  12. on_bright_yellow() or ON_BRIGHT_YELLOW
  13. on_bright_blue() or ON_BRIGHT_BLUE
  14. on_bright_magenta() or ON_BRIGHT_MAGENTA
  15. on_bright_cyan() or ON_BRIGHT_CYAN
  16. on_bright_white() or ON_BRIGHT_WHITE

256 Colors

You can find the color codes here.

Note: Windows doesn't support this function!

  1. void on_color256(int color_code);

RGB Colors

Note 1: Not all terminals supports this feature!

Note 2: Windows doesn't support this function!

  1. void on_color_rgb(int r, int g, int b);

Thanks for visiting my repository!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages