feat: add ansi colors

This commit is contained in:
Daniel Ledda
2025-02-02 20:20:25 +01:00
parent a337c0d9ac
commit 4b1dd8e66b
2 changed files with 67 additions and 3 deletions

View File

@@ -208,6 +208,52 @@ enum LogTarget {
LogTarget_count,
};
#define ANSI_INSTRUCTION_FROM_ENUM(ansiCodeEnum) ANSI_INSTRUCTION(ansiCodeEnum)
#define ANSI_INSTRUCTION(ansiCode) "\u001b[" #ansiCode "m"
#define ANSI_INSTRUCTION_STR(ansiCodeStr) "\u001b[" ansiCodeStr "m"
#define ANSI_RESET ANSI_INSTRUCTION(0)
#define ANSI_fg_black 30
#define ANSI_fg_red 31
#define ANSI_fg_green 32
#define ANSI_fg_yellow 33
#define ANSI_fg_blue 34
#define ANSI_fg_magenta 35
#define ANSI_fg_cyan 36
#define ANSI_fg_white 37
#define ANSI_fg_bblack 90
#define ANSI_fg_bred 91
#define ANSI_fg_bgreen 92
#define ANSI_fg_byellow 93
#define ANSI_fg_bblue 94
#define ANSI_fg_bmagenta 95
#define ANSI_fg_bcyan 96
#define ANSI_fg_bwhite 97
#define ANSI_bg_black 40
#define ANSI_bg_red 41
#define ANSI_bg_green 42
#define ANSI_bg_yellow 43
#define ANSI_bg_blue 44
#define ANSI_bg_magenta 45
#define ANSI_bg_cyan 46
#define ANSI_bg_white 47
#define ANSI_bg_bblack 100
#define ANSI_bg_bred 101
#define ANSI_bg_bgreen 102
#define ANSI_bg_byellow 103
#define ANSI_bg_bblue 104
#define ANSI_bg_bmagenta 105
#define ANSI_bg_bcyan 106
#define ANSI_bg_bwhite 107
#define COLOR_TEXT(text, foregroundcolor) ANSI_INSTRUCTION_FROM_ENUM(foregroundcolor) text ANSI_RESET
#define COLOR_TEXT_BG(text, backgroundcolor) ANSI_INSTRUCTION_FROM_ENUM(backgroundcolor) text ANSI_RESET
#define COLOR_TEXT_FG_BG(text, foregroundcolor, backgroundcolor) ANSI_INSTRUCTION_FROM_ENUM(foregroundcolor) ANSI_INSTRUCTION_FROM_ENUM(backgroundcolor) text ANSI_RESET
#define COLOR_TEXT_RGB(text, red, green, blue) ANSI_INSTRUCTION_STR("38;2;" #red ";" #green ";" #blue) text ANSI_RESET
void log(list<int> l, LogTarget target = LogTarget_stdout);
void log(list<string> l, LogTarget target = LogTarget_stdout);
void log(const char *fmt, ...);