macros and utilities for printing color to stdout from https://www.quora.com/How-do-I-print-a-colored-output-in-C Pass a COLORS_x
enum value into print_colored
and the color will be printed on stdout Note that if you want to disable printing of that color you'll have to send the COLORS_RESET
enum value through to make non-bold change 0->1 (0;31m red) vs (1;31m bold red)
More...
#include <stdbool.h>
Go to the source code of this file.
|
char * | format_colored (COLORS color, char *message) |
| returns a char * with the message formatted with ansi colors More...
|
|
char * | get_ansi_color_scheme (COLORS color) |
| returns an ansi color string to be used with printf More...
|
|
void | print_colored (COLORS color, char *message) |
| prints message to stdout with the given color More...
|
|
int | write_colored (COLORS color, int file_descriptor, char *message) |
| writes a message to fh with the given color For "sync writes" and to always flush logs to disk immediately set do_flush to true returns 0 if no error, returns 1 if error More...
|
|
macros and utilities for printing color to stdout from https://www.quora.com/How-do-I-print-a-colored-output-in-C Pass a COLORS_x
enum value into print_colored
and the color will be printed on stdout Note that if you want to disable printing of that color you'll have to send the COLORS_RESET
enum value through to make non-bold change 0->1 (0;31m red) vs (1;31m bold red)
Definition in file colors.h.
◆ ANSI_COLOR_BLUE
#define ANSI_COLOR_BLUE "\x1b[1;34m" |
◆ ANSI_COLOR_CYAN
#define ANSI_COLOR_CYAN "\x1b[1;36m" |
◆ ANSI_COLOR_GREEN
#define ANSI_COLOR_GREEN "\x1b[1;32m" |
◆ ANSI_COLOR_MAGENTA
#define ANSI_COLOR_MAGENTA "\x1b[1;35m" |
◆ ANSI_COLOR_RED
#define ANSI_COLOR_RED "\x1b[1;31m" |
◆ ANSI_COLOR_RESET
#define ANSI_COLOR_RESET "\x1b[1;0m" |
◆ ANSI_COLOR_SOFT_RED
#define ANSI_COLOR_SOFT_RED "\x1b[1;38;5;210m" |
◆ ANSI_COLOR_YELLOW
#define ANSI_COLOR_YELLOW "\x1b[1;33m" |
◆ COLORS
allows short-handed references to ANSI color schemes, and enables easier color selection anytime you want to extend the available colors with an additional enum, add a switch case in get_ansi_color_scheme
Enumerator |
---|
COLORS_RED | |
COLORS_SOFT_RED | |
COLORS_GREEN | |
COLORS_YELLOW | |
COLORS_BLUE | |
COLORS_MAGENTA | |
COLORS_CYAN | |
COLORS_RESET | |
Definition at line 25 of file colors.h.
◆ format_colored()
char* format_colored |
( |
COLORS |
color, |
|
|
char * |
message |
|
) |
| |
returns a char *
with the message formatted with ansi colors
Definition at line 31 of file colors.c.
◆ get_ansi_color_scheme()
char* get_ansi_color_scheme |
( |
COLORS |
color | ) |
|
returns an ansi color string to be used with printf
Definition at line 8 of file colors.c.
◆ print_colored()
void print_colored |
( |
COLORS |
color, |
|
|
char * |
message |
|
) |
| |
prints message to stdout with the given color
Definition at line 43 of file colors.c.
◆ write_colored()
int write_colored |
( |
COLORS |
color, |
|
|
int |
file_descriptor, |
|
|
char * |
message |
|
) |
| |
writes a message to fh with the given color For "sync writes" and to always flush logs to disk immediately set do_flush to true returns 0 if no error, returns 1 if error
Definition at line 47 of file colors.c.