refactor: hectic C: logger rules and results

This commit is contained in:
2025-04-13 19:38:11 +00:00
parent 2f6806185d
commit 267d0ec464
11 changed files with 393 additions and 320 deletions

50
package/c/hectic/cpp-test.c Executable file
View File

@@ -0,0 +1,50 @@
// ------------
// -- Colors --
// ------------
// Color mode enumeration
typedef enum {
COLOR_MODE_AUTO,
COLOR_MODE_FORCE,
COLOR_MODE_DISABLE
} ColorMode;
// External color mode variable declaration
extern ColorMode color_mode;
const char* color_mode_to_string(ColorMode mode);
// Function to set color mode
void set_output_color_mode(ColorMode mode);
// Macros for detecting terminal and color usage
#define IS_TERMINAL() (isatty(fileno(stderr)))
/*
* USE_COLOR() is true if color is forced or if color is auto and the output is a terminal.
* used for all colorized output
*/
#define USE_COLOR() ((color_mode == COLOR_MODE_FORCE) || (color_mode == COLOR_MODE_AUTO && IS_TERMINAL()))
/*
* DEBUG_COLOR_MODE is the color mode for debug output after USE_COLOR() check.
* used for debug colorized output
*/
#define DEBUG_COLOR_MODE COLOR_MODE_FORCE
#define USE_COLOR_IN_DEBUG() (USE_COLOR() ? DEBUG_COLOR_MODE : COLOR_MODE_DISABLE)
#define COLOR_RED "\033[1;31m"
#define COLOR_GREEN "\033[1;32m"
#define COLOR_YELLOW "\033[1;33m"
#define COLOR_BLUE "\033[1;34m"
#define COLOR_MAGENTA "\033[1;35m"
#define COLOR_CYAN "\033[1;36m"
#define COLOR_WHITE "\033[1;37m"
#define COLOR_RESET "\033[0m"
#define OPTIONAL_COLOR(color) (USE_COLOR() ? color : "")
#define DEBUG_COLOR(color) (USE_COLOR_IN_DEBUG() ? color : "")
OPTIONAL_COLOR(COLOR_RED) "Hello" OPTIONAL_COLOR(COLOR_RESET)
DEBUG_COLOR(COLOR_RED) "Hello" DEBUG_COLOR(COLOR_RESET)