From f0f954d463f7ab0e0ce792527e6567611ed67bf9 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 13 Oct 2026 07:43:48 -0300 Subject: 50% colors i'll do rainbow and whatever else i'm missing from the rust version later too lseepy rn --- defs/colors.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'defs/colors.h') diff --git a/defs/colors.h b/defs/colors.h index 0c376db..a3179f8 100644 --- a/defs/colors.h +++ b/defs/colors.h @@ -1,7 +1,7 @@ #ifndef COLORS_H #define COLORS_H -#include +#include #include typedef enum color_mode { @@ -31,9 +31,9 @@ typedef enum NamedColor { }NamedColor; typedef struct{ - int red; - int green; - int blue; + unsigned char red; + unsigned char green; + unsigned char blue; }rgbcolor; typedef struct colorconfig { @@ -43,8 +43,29 @@ typedef struct colorconfig { bool rainbow_enabled; //flag int saturation; //default 100 int brightness; //default 50 - char **rainbow_cache; //array of rgb_color malloced + rgbcolor *rainbow_cache; //array of rgbcolor malloced size_t rainbow_count; }colorconfig; -#endif +typedef enum ColorParseError { + COLOR_OK, + COLOR_ERR_FORMAT, + COLOR_ERR_HEX, + COLOR_ERR_RGB, + COLOR_ERR_HSL, + COLOR_ERR_UNKNOWN_NAME +}ColorParseError; + +void colorconfig_init(colorconfig *config); +enum color_mode detect_color_mode(void); +bool enable_windows_ansi(void); +int parse_namedcolors(const char *name, rgbcolor *out_rgb); +ColorParseError parse_color(const char *s, rgbcolor *out); +const char *color_parse_error_message(ColorParseError error); +unsigned char rgb_to_ansi16(rgbcolor rgb); +unsigned char rgb_to_ansi256(rgbcolor rgb); +rgbcolor hsl_to_rgb(unsigned short h, unsigned char s, unsigned char l); +rgbcolor lerp_color_hsv(rgbcolor start, rgbcolor end, float t); +void rgb_to_fg_escape(rgbcolor rgb, color_mode mode, char *out, size_t size); + +#endif -- cgit v1.3-2-g0d8e