|
Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
|
ANSI escape codes and convenience macros for terminal text coloring and styling. More...
#include <stdbool.h>

Go to the source code of this file.
Macros | |
ANSI Color Codes | |
| #define | COLOR_RED "\033[31m" |
| #define | COLOR_GREEN "\033[32m" |
| #define | COLOR_BLUE "\033[34m" |
| #define | COLOR_CYAN "\033[36m" |
| #define | COLOR_MAGENTA "\033[35m" |
| #define | COLOR_YELLOW "\033[33m" |
| #define | COLOR_WHITE "\033[37m" |
| #define | COLOR_BLACK "\033[30m" |
| #define | COLOR_GRAY "\033[90m" |
ANSI Style Codes | |
| #define | STYLE_RESET "\033[0m" |
| #define | STYLE_BOLD "\033[1m" |
| #define | STYLE_UNDERLINE "\033[4m" |
Background Color Codes | |
| #define | BG_RED "\033[41m" |
| #define | BG_GREEN "\033[42m" |
| #define | BG_BLUE "\033[44m" |
| #define | BG_CYAN "\033[46m" |
| #define | BG_MAGENTA "\033[45m" |
| #define | BG_YELLOW "\033[43m" |
| #define | BG_WHITE "\033[47m" |
| #define | BG_BLACK "\033[40m" |
| #define | BG_GRAY "\033[100m" |
Convenience Macros for Common Color Usage | |
These macros conditionally apply color styling to text if the terminal supports color, otherwise return the original text unchanged. | |
| #define | RED(text) (terminal_supports_color() ? COLOR_RED text STYLE_RESET : text) |
| #define | GREEN(text) (terminal_supports_color() ? COLOR_GREEN text STYLE_RESET : text) |
| #define | BLUE(text) (terminal_supports_color() ? COLOR_BLUE text STYLE_RESET : text) |
| #define | CYAN(text) (terminal_supports_color() ? COLOR_CYAN text STYLE_RESET : text) |
| #define | MAGENTA(text) (terminal_supports_color() ? COLOR_MAGENTA text STYLE_RESET : text) |
| #define | YELLOW(text) (terminal_supports_color() ? COLOR_YELLOW text STYLE_RESET : text) |
| #define | WHITE(text) (terminal_supports_color() ? COLOR_WHITE text STYLE_RESET : text) |
| #define | BLACK(text) (terminal_supports_color() ? COLOR_BLACK text STYLE_RESET : text) |
| #define | GRAY(text) (terminal_supports_color() ? COLOR_GRAY text STYLE_RESET : text) |
Bold Color Macros | |
Macros to print bold colored text conditionally based on terminal support. | |
| #define | BOLD_RED(text) (terminal_supports_color() ? STYLE_BOLD COLOR_RED text STYLE_RESET : text) |
| #define | BOLD_GREEN(text) (terminal_supports_color() ? STYLE_BOLD COLOR_GREEN text STYLE_RESET : text) |
| #define | BOLD_BLUE(text) (terminal_supports_color() ? STYLE_BOLD COLOR_BLUE text STYLE_RESET : text) |
| #define | BOLD_CYAN(text) (terminal_supports_color() ? STYLE_BOLD COLOR_CYAN text STYLE_RESET : text) |
| #define | BOLD_MAGENTA(text) (terminal_supports_color() ? STYLE_BOLD COLOR_MAGENTA text STYLE_RESET : text) |
| #define | BOLD_YELLOW(text) (terminal_supports_color() ? STYLE_BOLD COLOR_YELLOW text STYLE_RESET : text) |
| #define | BOLD_WHITE(text) (terminal_supports_color() ? STYLE_BOLD COLOR_WHITE text STYLE_RESET : text) |
| #define | BOLD_BLACK(text) (terminal_supports_color() ? STYLE_BOLD COLOR_BLACK text STYLE_RESET : text) |
| #define | BOLD_GRAY(text) (terminal_supports_color() ? STYLE_BOLD COLOR_GRAY text STYLE_RESET : text) |
Underlined Color Macros | |
Macros to print underlined colored text conditionally based on terminal support. | |
| #define | UNDERLINE_RED(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_RED text STYLE_RESET : text) |
| #define | UNDERLINE_GREEN(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_GREEN text STYLE_RESET : text) |
| #define | UNDERLINE_BLUE(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_BLUE text STYLE_RESET : text) |
| #define | UNDERLINE_CYAN(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_CYAN text STYLE_RESET : text) |
| #define | UNDERLINE_MAGENTA(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_MAGENTA text STYLE_RESET : text) |
| #define | UNDERLINE_YELLOW(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_YELLOW text STYLE_RESET : text) |
| #define | UNDERLINE_WHITE(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_WHITE text STYLE_RESET : text) |
| #define | UNDERLINE_BLACK(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_BLACK text STYLE_RESET : text) |
| #define | UNDERLINE_GRAY(text) (terminal_supports_color() ? STYLE_UNDERLINE COLOR_GRAY text STYLE_RESET : text) |
Custom Formatting Macros | |
Macros to apply arbitrary color and style sequences conditionally. | |
| #define | COLORIZE(color, text) (terminal_supports_color() ? color text STYLE_RESET : text) |
| #define | BOLD_COLORIZE(color, text) (terminal_supports_color() ? STYLE_BOLD color text STYLE_RESET : text) |
| #define | UNDERLINE_COLORIZE(color, text) (terminal_supports_color() ? STYLE_UNDERLINE color text STYLE_RESET : text) |
| #define | STYLE_COLORIZE(style, color, text) (terminal_supports_color() ? style color text STYLE_RESET : text) |
Functions | |
| bool | terminal_supports_color (void) |
| Checks if the terminal supports ANSI color escape sequences. | |
ANSI escape codes and convenience macros for terminal text coloring and styling.
This header provides definitions for ANSI color and style escape sequences, as well as convenient macros for coloring and styling text conditionally based on whether the terminal supports color output.
The macros wrap strings with appropriate ANSI sequences and reset codes, enabling colorful, bold, and underlined text output in terminal applications.
Usage example:
| #define BG_BLACK "\033[40m" |
ANSI code for black background
| #define BG_BLUE "\033[44m" |
ANSI code for blue background
| #define BG_CYAN "\033[46m" |
ANSI code for cyan background
| #define BG_GRAY "\033[100m" |
ANSI code for gray background
| #define BG_GREEN "\033[42m" |
ANSI code for green background
| #define BG_MAGENTA "\033[45m" |
ANSI code for magenta background
| #define BG_RED "\033[41m" |
ANSI code for red background
| #define BG_WHITE "\033[47m" |
ANSI code for white background
| #define BG_YELLOW "\033[43m" |
ANSI code for yellow background
| #define BLACK | ( | text | ) | (terminal_supports_color() ? COLOR_BLACK text STYLE_RESET : text) |
| #define BLUE | ( | text | ) | (terminal_supports_color() ? COLOR_BLUE text STYLE_RESET : text) |
| #define BOLD_BLACK | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_BLACK text STYLE_RESET : text) |
| #define BOLD_BLUE | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_BLUE text STYLE_RESET : text) |
| #define BOLD_COLORIZE | ( | color, | |
| text | |||
| ) | (terminal_supports_color() ? STYLE_BOLD color text STYLE_RESET : text) |
| #define BOLD_CYAN | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_CYAN text STYLE_RESET : text) |
| #define BOLD_GRAY | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_GRAY text STYLE_RESET : text) |
| #define BOLD_GREEN | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_GREEN text STYLE_RESET : text) |
| #define BOLD_MAGENTA | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_MAGENTA text STYLE_RESET : text) |
| #define BOLD_RED | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_RED text STYLE_RESET : text) |
| #define BOLD_WHITE | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_WHITE text STYLE_RESET : text) |
| #define BOLD_YELLOW | ( | text | ) | (terminal_supports_color() ? STYLE_BOLD COLOR_YELLOW text STYLE_RESET : text) |
| #define COLOR_BLACK "\033[30m" |
ANSI code for black text
| #define COLOR_BLUE "\033[34m" |
ANSI code for blue text
| #define COLOR_CYAN "\033[36m" |
ANSI code for cyan text
| #define COLOR_GRAY "\033[90m" |
ANSI code for gray (bright black) text
| #define COLOR_GREEN "\033[32m" |
ANSI code for green text
| #define COLOR_MAGENTA "\033[35m" |
ANSI code for magenta text
| #define COLOR_RED "\033[31m" |
ANSI code for red text
| #define COLOR_WHITE "\033[37m" |
ANSI code for white text
| #define COLOR_YELLOW "\033[33m" |
ANSI code for yellow text
| #define COLORIZE | ( | color, | |
| text | |||
| ) | (terminal_supports_color() ? color text STYLE_RESET : text) |
| #define CYAN | ( | text | ) | (terminal_supports_color() ? COLOR_CYAN text STYLE_RESET : text) |
| #define GRAY | ( | text | ) | (terminal_supports_color() ? COLOR_GRAY text STYLE_RESET : text) |
| #define GREEN | ( | text | ) | (terminal_supports_color() ? COLOR_GREEN text STYLE_RESET : text) |
| #define MAGENTA | ( | text | ) | (terminal_supports_color() ? COLOR_MAGENTA text STYLE_RESET : text) |
| #define RED | ( | text | ) | (terminal_supports_color() ? COLOR_RED text STYLE_RESET : text) |
| #define STYLE_BOLD "\033[1m" |
Bold text style
| #define STYLE_COLORIZE | ( | style, | |
| color, | |||
| text | |||
| ) | (terminal_supports_color() ? style color text STYLE_RESET : text) |
| #define STYLE_RESET "\033[0m" |
Reset all styles
| #define STYLE_UNDERLINE "\033[4m" |
Underline text style
| #define UNDERLINE_BLACK | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_BLACK text STYLE_RESET : text) |
| #define UNDERLINE_BLUE | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_BLUE text STYLE_RESET : text) |
| #define UNDERLINE_COLORIZE | ( | color, | |
| text | |||
| ) | (terminal_supports_color() ? STYLE_UNDERLINE color text STYLE_RESET : text) |
| #define UNDERLINE_CYAN | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_CYAN text STYLE_RESET : text) |
| #define UNDERLINE_GRAY | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_GRAY text STYLE_RESET : text) |
| #define UNDERLINE_GREEN | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_GREEN text STYLE_RESET : text) |
| #define UNDERLINE_MAGENTA | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_MAGENTA text STYLE_RESET : text) |
| #define UNDERLINE_RED | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_RED text STYLE_RESET : text) |
| #define UNDERLINE_WHITE | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_WHITE text STYLE_RESET : text) |
| #define UNDERLINE_YELLOW | ( | text | ) | (terminal_supports_color() ? STYLE_UNDERLINE COLOR_YELLOW text STYLE_RESET : text) |
| #define WHITE | ( | text | ) | (terminal_supports_color() ? COLOR_WHITE text STYLE_RESET : text) |
| #define YELLOW | ( | text | ) | (terminal_supports_color() ? COLOR_YELLOW text STYLE_RESET : text) |
| bool terminal_supports_color | ( | void | ) |
Checks if the terminal supports ANSI color escape sequences.
This function should detect whether the current terminal session supports colored output. Common implementations check environment variables, platform, or terminal capabilities.
Checks if the terminal supports ANSI color escape sequences.
This function determines whether the terminal connected to standard output supports colored output using ANSI escape sequences.
The result is cached after the first call for efficiency.
On Windows:
On Unix/Linux:
tput colors command to verify the number of colors supported.