diff options
Diffstat (limited to 'defs')
| -rw-r--r-- | defs/all.h | 1 | ||||
| -rw-r--r-- | defs/colors.h | 33 | ||||
| -rw-r--r-- | defs/helper.h | 1 |
3 files changed, 29 insertions, 6 deletions
@@ -7,6 +7,7 @@ #include <string.h> #include <locale.h> #include <stdbool.h> +#include <ctype.h> #include "helper.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 <stdlib.h> +#include <stddef.h> #include <stdbool.h> 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 diff --git a/defs/helper.h b/defs/helper.h index d199cc2..a8a7988 100644 --- a/defs/helper.h +++ b/defs/helper.h @@ -2,5 +2,6 @@ #define helper_h int displaywidth(const char *text); +int utf8_decode(const unsigned char *bytes, unsigned long *codepoint); #endif |
