38 #define COLR_VERSION "0.4.0" 41 #pragma GCC diagnostic ignored "-Wunknown-pragmas" 51 #if (__STDC_VERSION__ >= 201112L) 52 #if defined(__GNUC__) && !defined(__clang__) 53 #if (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)) 60 #endif // DOXYGEN_SKIP 64 #error "ColrC cannot compile without C11+ generic selections (_Generic)." 69 #if !defined(_GNU_SOURCE) 88 #pragma GCC warning "Trying to compile without _GNU_SOURCE, this will not work." 90 #pragma clang diagnostic push 91 #pragma clang diagnostic ignored "-Wmacro-redefined" 128 #pragma clang diagnostic pop // -Wmacro-redefined 130 #pragma GCC warning "ColrC uses GNU extensions that your system doesn't support." 131 #if defined(COLR_GNU) 132 #pragma GCC warning "ColrC GNU extensions are enabled (COLR_GNU) for a non-GNU system." 134 #pragma GCC warning "No glibc and COLR_GNU=0, some features will be disabled." 141 #pragma clang diagnostic ignored "-Wgnu-statement-expression" 160 #include <sys/ioctl.h> 164 #if defined(DEBUG) && defined(COLR_DEBUG) 168 #pragma GCC diagnostic ignored "-Wunused-macros" 171 #define CODE_RESET_ALL "\x1b[0m" 172 #define CODE_RESET_BACK "\x1b[49m" 174 #define CODE_RESET_FORE "\x1b[39m" 176 #define WCODE_RESET_BACK L"\x1b[49m" 178 #define WCODE_RESET_FORE L"\x1b[39m" 180 #define WCODE_RESET_ALL L"\x1b[0m" 182 #define NC CODE_RESET_ALL 184 #define NCNL CODE_RESET_ALL "\n" 186 #define WNC WCODE_RESET_ALL 188 #define WNCNL WCODE_RESET_ALL L"\n" 192 #define CODE_RESET_LEN 5 198 #define CODE_LEN_MIN 5 208 #define CODEX_LEN_MIN 10 216 #define STYLE_LEN_MIN 5 231 #define CODE_RGB_LEN_MIN 14 232 #define CODE_RGB_LEN 20 240 #define COLOR_RGB_LEN 26 247 #define CODE_ANY_LEN 46 298 #define COLORARG_MARKER UINT32_MAX 303 #define COLORLASTARG_MARKER (UINT32_MAX - 20) 308 #define COLORJUSTIFY_MARKER (UINT32_MAX - 30) 313 #define COLORRESULT_MARKER (UINT32_MAX - 40) 318 #define COLORTEXT_MARKER (UINT32_MAX - 50) 323 #define COLOR_INVALID (-2) 324 #define COLOR_INVALID_RANGE (-3) 328 #define COLR_HASH_SEED 5381 337 #pragma info "Set COLR_FMT=" COLR_FMT 340 #define COLR_FMT_CHAR COLR_FMT[0] 341 #define COLR_FMT_MOD_ESC "/" 343 #define COLR_FMT_MOD_ESC_CHAR COLR_FMT_MOD_ESC[0] 357 #define EXT_INVALID COLOR_INVALID 365 #define EXT_INVALID_RANGE COLOR_INVALID_RANGE 375 #define alloc_basic() calloc(CODE_LEN, sizeof(char)) 385 #define alloc_extended() calloc(CODEX_LEN, sizeof(char)) 396 #define alloc_rgb() calloc(CODE_RGB_LEN, sizeof(char)) 406 #define alloc_style() calloc(STYLE_LEN, sizeof(char)) 415 #define asprintf_or_return(retval, ...) if_not_asprintf(__VA_ARGS__) return retval 453 #define back(x) ColorArg_to_ptr(back_arg(x)) 476 #define back_arg(x) \ 479 char* : ColorArg_from_str, \ 480 RGB: ColorArg_from_RGB, \ 481 BasicValue: ColorArg_from_BasicValue, \ 482 ExtendedValue: ColorArg_from_ExtendedValue, \ 483 StyleValue: ColorArg_from_StyleValue \ 498 #define back_str(x) ColorArg_to_esc(back_arg(x)) 538 #define back_str_static(x) \ 540 __typeof(x) _bss_val = x; \ 541 ColorArg _bss_carg = back_arg(_bss_val); \ 542 size_t _bss_len = ColorArg_length(_bss_carg); \ 543 char* _bss_codes = alloca(_bss_len); \ 544 ColorArg_to_esc_s(_bss_codes, _bss_carg); \ 567 #define basic(x) ((BasicValue)(x)) 580 #define bool_colr_enum(x) (x < 0 ? false: true) 593 #define color_arg(type, x) \ 596 char*: ColorArg_from_str(type, x), \ 597 BasicValue: ColorArg_from_value(type, TYPE_BASIC, &x), \ 598 ExtendedValue: ColorArg_from_value(type, TYPE_EXTENDED, &x), \ 599 StyleValue: ColorArg_from_value(type, TYPE_STYLE, &x), \ 600 RGB: ColorArg_from_value(type, TYPE_RGB, &x) \ 643 #define color_name_is_invalid(x) ColorType_is_invalid(ColorType_from_str(x)) 685 #define color_name_is_valid(x) ColorType_is_valid(ColorType_from_str(x)) 697 #define color_val(x) \ 700 BasicValue: ColorValue_from_value(TYPE_BASIC, &x), \ 701 ExtendedValue: ColorValue_from_value(TYPE_EXTENDED, &x), \ 702 StyleValue: ColorValue_from_value(TYPE_STYLE, &x), \ 703 RGB: ColorValue_from_value(TYPE_RGB, &x) \ 734 #define ColorText_center(text, justwidth, ...) ColorText_set_just( \ 735 Colr(text, __VA_ARGS__), \ 736 (ColorJustify){.method=JUST_CENTER, .width=justwidth, .padchar=' '} \ 766 #define ColorText_center_char(text, justwidth, c, ...) ColorText_set_just( \ 767 Colr(text, __VA_ARGS__), \ 768 (ColorJustify){.method=JUST_CENTER, .width=justwidth, .padchar=c} \ 796 #define ColorText_ljust(text, justwidth, ...) ColorText_set_just( \ 797 Colr(text, __VA_ARGS__), \ 798 (ColorJustify){.method=JUST_LEFT, .width=justwidth, .padchar=' '} \ 827 #define ColorText_ljust_char(text, justwidth, c, ...) ColorText_set_just( \ 828 Colr(text, __VA_ARGS__), \ 829 (ColorJustify){.method=JUST_LEFT, .width=justwidth, .padchar=c} \ 859 #define ColorText_rjust(text, justwidth, ...) ColorText_set_just( \ 860 Colr(text, __VA_ARGS__), \ 861 (ColorJustify){.method=JUST_RIGHT, .width=justwidth, .padchar=' '} \ 890 #define ColorText_rjust_char(text, justwidth, c, ...) ColorText_set_just( \ 891 Colr(text, __VA_ARGS__), \ 892 (ColorJustify){.method=JUST_RIGHT, .width=justwidth, .padchar=c} \ 912 #define ColorValue_has(cval, val) \ 915 BasicValue: ColorValue_has_BasicValue, \ 916 ExtendedValue: ColorValue_has_ExtendedValue, \ 917 StyleValue: ColorValue_has_StyleValue, \ 918 RGB: ColorValue_has_RGB \ 940 #define Colr(text, ...) ColorText_to_ptr(ColorText_from_values(text, __VA_ARGS__, _ColrLastArg)) 977 #define Colra(text, ...) ColorText_from_values(text, __VA_ARGS__, _ColrLastArg) 994 #define Colr_cat(...) ColorResult_to_ptr(ColorResult_new(colr_cat(__VA_ARGS__))) 1007 #define Colr_center(x, width) \ 1010 char*: Colr_center_char, \ 1011 const char*: Colr_center_char, \ 1012 ColorResult*: Colr_center_char, \ 1013 ColorText*: Colr_center_char \ 1047 #define Colr_fmt(fmt, value, ...) \ 1049 Colr_fmt_str(fmt, value), \ 1082 #define Colr_join(joiner, ...) ColrResult(colr_join(joiner, __VA_ARGS__)) 1095 #define Colr_ljust(x, width) \ 1098 char*: Colr_ljust_char, \ 1099 const char*: Colr_ljust_char, \ 1100 ColorResult*: Colr_ljust_char, \ 1101 ColorText*: Colr_ljust_char \ 1115 #define Colr_rjust(x, width) \ 1118 char*: Colr_rjust_char, \ 1119 const char*: Colr_rjust_char, \ 1120 ColorResult*: Colr_rjust_char, \ 1121 ColorText*: Colr_rjust_char \ 1134 #define ColrResult(s) ColorResult_to_ptr(ColorResult_new(s)) 1159 #define ColrColorResult(cres, ...) ColorResult_Colr(cres, __VA_ARGS__, _ColrLastArg) 1180 #define colr(text, ...) colr_cat(Colr(text, __VA_ARGS__)) 1222 #define colr_cat(...) _colr_join("", __VA_ARGS__, _ColrLastArg) 1239 #define colr_center(x, width) colr_center_char(x, width, ' ') 1257 #define colr_center_char(x, width, padchar) ColorResult_rip_str( \ 1260 char*: Colr_center_char, \ 1261 const char*: Colr_center_char, \ 1262 ColorResult*: Colr_center_char, \ 1263 ColorText*: Colr_center_char \ 1264 )(x, width, padchar)) 1273 #define colr_alloc_len(x) \ 1276 RGB: CODE_RGB_LEN, \ 1277 BasicValue: CODE_LEN, \ 1278 ExtendedValue: CODEX_LEN, \ 1279 StyleValue: STYLE_LEN \ 1292 #define colr_eq(a, b) \ 1295 ArgType: ArgType_eq, \ 1296 BasicValue: BasicValue_eq, \ 1297 ColorArg: ColorArg_eq, \ 1298 ColorJustify: ColorJustify_eq, \ 1299 ColorResult: ColorResult_eq, \ 1300 ColorType: ColorType_eq, \ 1301 ColorValue: ColorValue_eq, \ 1302 ExtendedValue: ExtendedValue_eq, \ 1304 StyleValue: StyleValue_eq \ 1321 #define colr_example(x) \ 1324 ColorArg: ColorArg_example, \ 1325 ColorValue: ColorValue_example \ 1335 #define colr_fprint(file, ...) \ 1337 char* _c_p_s = colr_cat(__VA_ARGS__); \ 1338 if (!_c_p_s) break; \ 1339 fprintf(file, "%s", _c_p_s); \ 1340 colr_free(_c_p_s); \ 1356 #define colr_free(x) \ 1359 ColorArg*: ColorArg_free, \ 1360 ColorArg**: ColorArgs_array_free, \ 1361 ColorResult*: ColorResult_free, \ 1362 ColorText*: ColorText_free, \ 1363 regmatch_t**: colr_free_re_matches, \ 1364 default: _colr_free \ 1372 #define colr_is_empty(x) \ 1375 char*: colr_str_is_empty, \ 1376 const char*: colr_str_is_empty, \ 1377 ColorArg: ColorArg_is_empty, \ 1378 ColorJustify: ColorJustify_is_empty, \ 1379 ColorText: ColorText_is_empty, \ 1380 ColorValue: ColorValue_is_empty \ 1389 #define colr_is_invalid(x) \ 1392 BasicValue: BasicValue_is_invalid, \ 1393 ExtendedValue: ExtendedValue_is_invalid, \ 1394 StyleValue: StyleValue_is_invalid, \ 1395 ColorArg: ColorArg_is_invalid, \ 1396 ColorType: ColorType_is_invalid, \ 1397 ColorValue: ColorValue_is_invalid \ 1405 #define colr_is_valid(x) \ 1408 BasicValue: BasicValue_is_valid, \ 1409 ExtendedValue: ExtendedValue_is_valid, \ 1410 StyleValue: StyleValue_is_valid, \ 1411 ColorArg: ColorArg_is_valid, \ 1412 ColorType: ColorType_is_valid, \ 1413 ColorValue: ColorValue_is_valid \ 1424 #define colr_is_valid_mblen(x) ((x) && ((x) != (size_t)-1) && ((x) != (size_t)-2)) 1435 #define colr_istr_either(s1, s2, s3) \ 1437 ((s1) && (s2) && (s3)) ? \ 1438 (colr_istr_eq((s1), (s2)) || colr_istr_eq((s1), (s3))) : \ 1450 #define colr_istr_eq(s1, s2) \ 1453 !strcasecmp((s1), (s2)) : \ 1485 #define colr_join(joiner, ...) _colr_join(joiner, __VA_ARGS__, _ColrLastArg) 1496 #define colr_length(x) \ 1499 ColorArg: ColorArg_length, \ 1500 ColorResult: ColorResult_length, \ 1501 ColorText: ColorText_length, \ 1502 ColorValue: ColorValue_length, \ 1503 void*: _colr_ptr_length \ 1521 #define colr_ljust(x, width) colr_ljust_char(x, width, ' ') 1539 #define colr_ljust_char(x, width, padchar) ColorResult_rip_str( \ 1542 char*: Colr_ljust_char, \ 1543 const char*: Colr_ljust_char, \ 1544 ColorResult*: Colr_ljust_char, \ 1545 ColorText*: Colr_ljust_char \ 1546 )(x, width, padchar)) 1563 #define colr_rjust(x, width) colr_rjust_char(x, width, ' ') 1581 #define colr_rjust_char(x, width, padchar) ColorResult_rip_str( \ 1584 char*: Colr_rjust_char, \ 1585 const char*: Colr_rjust_char, \ 1586 ColorResult*: Colr_rjust_char, \ 1587 ColorText*: Colr_rjust_char \ 1588 )(x, width, padchar)) 1590 #ifndef DOXYGEN_SKIP 1593 #define _colr_macro_str(x) #x 1594 #define colr_macro_str(x) _colr_macro_str(x) 1596 #define _colr_macro_str_all(...) #__VA_ARGS__ 1597 #define colr_macro_str_all(...) _colr_macro_str_all(__VA_ARGS__) 1599 #define _colr_macro_concat(a, b) a ## b 1600 #define colr_macro_concat(a, b) _colr_macro_concat(a, b) 1609 #define colr_max(a, b) (a > b ? a : b) 1617 #define colr_print(...) \ 1619 char* _c_p_s = colr_cat(__VA_ARGS__); \ 1620 if (!_c_p_s) break; \ 1621 printf("%s", _c_p_s); \ 1622 colr_free(_c_p_s); \ 1641 #define colr_printf_macro(func, ...) \ 1643 _Pragma("GCC diagnostic push"); \ 1644 _Pragma("GCC diagnostic ignored \"-Wformat=\""); \ 1645 _Pragma("GCC diagnostic ignored \"-Wformat-extra-args\""); \ 1646 _Pragma("clang diagnostic push"); \ 1647 _Pragma("clang diagnostic ignored \"-Wformat-invalid-specifier\""); \ 1648 colr_printf_register(); \ 1649 int _c_p_m_ret = func(__VA_ARGS__); \ 1650 _Pragma("clang diagnostic pop"); \ 1651 _Pragma("GCC diagnostic pop"); \ 1672 #define colr_printf(...) colr_printf_macro(printf, __VA_ARGS__) 1689 #define colr_fprintf(...) colr_printf_macro(fprintf, __VA_ARGS__) 1706 #define colr_sprintf(...) colr_printf_macro(sprintf, __VA_ARGS__) 1723 #define colr_snprintf(...) colr_printf_macro(snprintf, __VA_ARGS__) 1740 #define colr_asprintf(...) colr_printf_macro(asprintf, __VA_ARGS__) 1750 #define colr_puts(...) \ 1752 char* _c_p_s = colr_cat(__VA_ARGS__); \ 1753 if (!_c_p_s) break; \ 1755 colr_free(_c_p_s); \ 1835 #define colr_replace(s, target, repl) \ 1840 char* : colr_str_replace, \ 1841 regex_t* : colr_str_replace_re_pat, \ 1842 regmatch_t*: colr_str_replace_re_match, \ 1843 regmatch_t**: colr_str_replace_re_matches \ 1845 ColorArg*: _Generic( \ 1847 char* : colr_str_replace_ColorArg, \ 1848 regex_t* : colr_str_replace_re_pat_ColorArg, \ 1849 regmatch_t*: colr_str_replace_re_match_ColorArg, \ 1850 regmatch_t**: colr_str_replace_re_matches_ColorArg \ 1852 ColorResult*: _Generic( \ 1854 char* : colr_str_replace_ColorResult, \ 1855 regex_t* : colr_str_replace_re_pat_ColorResult, \ 1856 regmatch_t*: colr_str_replace_re_match_ColorResult, \ 1857 regmatch_t**: colr_str_replace_re_matches_ColorResult \ 1859 ColorText*: _Generic( \ 1861 char* : colr_str_replace_ColorText, \ 1862 regex_t* : colr_str_replace_re_pat_ColorText, \ 1863 regmatch_t*: colr_str_replace_re_match_ColorText, \ 1864 regmatch_t**: colr_str_replace_re_matches_ColorText \ 1937 #define colr_replace_all(s, target, repl) \ 1942 char* : colr_str_replace_all, \ 1943 regex_t* : colr_str_replace_re_pat_all, \ 1944 regmatch_t** : colr_str_replace_re_matches \ 1946 ColorArg*: _Generic( \ 1948 char* : colr_str_replace_all_ColorArg, \ 1949 regex_t* : colr_str_replace_re_pat_all_ColorArg, \ 1950 regmatch_t** : colr_str_replace_re_matches_ColorArg \ 1952 ColorResult*: _Generic( \ 1954 char* : colr_str_replace_all_ColorResult, \ 1955 regex_t* : colr_str_replace_re_pat_all_ColorResult, \ 1956 regmatch_t** : colr_str_replace_re_matches_ColorResult \ 1958 ColorText*: _Generic( \ 1960 char* : colr_str_replace_all_ColorText, \ 1961 regex_t* : colr_str_replace_re_pat_all_ColorText, \ 1962 regmatch_t** : colr_str_replace_re_matches_ColorText \ 2063 #define colr_replace_re(s, target, repl, flags) \ 2066 char*: colr_str_replace_re, \ 2067 ColorArg*: colr_str_replace_re_ColorArg, \ 2068 ColorResult*: colr_str_replace_re_ColorResult, \ 2069 ColorText*: colr_str_replace_re_ColorText \ 2070 )(s, target, repl, flags) 2168 #define colr_replace_re_all(s, target, repl, flags) \ 2171 char*: colr_str_replace_re_all, \ 2172 ColorArg*: colr_str_replace_re_all_ColorArg, \ 2173 ColorResult*: colr_str_replace_re_all_ColorResult, \ 2174 ColorText*: colr_str_replace_re_all_ColorText \ 2175 )(s, target, repl, flags) 2212 #define colr_repr(x) \ 2215 ColorArg: ColorArg_repr, \ 2216 ColorArg**: ColorArgs_array_repr, \ 2217 ColorJustify: ColorJustify_repr, \ 2218 ColorJustifyMethod: ColorJustifyMethod_repr, \ 2219 ColorResult: ColorResult_repr, \ 2220 ColorText: ColorText_repr, \ 2221 ColorValue: ColorValue_repr, \ 2222 ArgType: ArgType_repr, \ 2223 ColorType: ColorType_repr, \ 2224 BasicValue: BasicValue_repr, \ 2225 ExtendedValue: ExtendedValue_repr, \ 2227 StyleValue: StyleValue_repr, \ 2228 TermSize: TermSize_repr, \ 2229 const char*: colr_str_repr, \ 2230 char*: colr_str_repr, \ 2231 const char: colr_char_repr, \ 2232 char: colr_char_repr, \ 2233 void*: _colr_ptr_repr \ 2245 #define colr_str_eq(s1, s2) ( \ 2246 ((s1) && (s2)) ? !strcmp((s1), (s2)) : false \ 2258 #define colr_str_either(s1, s2, s3) (colr_str_eq(s1, s2) || colr_str_eq(s1, s3)) 2273 #define colr_to_str(x) \ 2276 ArgType: ArgType_to_str, \ 2277 BasicValue: BasicValue_to_str, \ 2278 ColorArg: ColorArg_to_esc, \ 2279 ColorResult: ColorResult_to_str, \ 2280 ColorText: ColorText_to_str, \ 2281 ColorType: ColorType_to_str, \ 2282 ExtendedValue: ExtendedValue_to_str, \ 2283 StyleValue: StyleValue_to_str, \ 2285 void*: _colr_ptr_to_str \ 2288 #ifndef DOXYGEN_SKIP 2289 #if defined(DEBUG) && defined(DBUG_H) && defined(dbug) 2304 #define dbug_repr(lbl, x) \ 2306 char* _dbug_repr_s = colr_repr(x); \ 2307 dbug("%s: %s\n", lbl, _dbug_repr_s); \ 2308 free(_dbug_repr_s); \ 2319 #define dbug(...) ((void)0) 2329 #define dbug_repr(lbl, x) ((void)0) 2331 #endif // DOXYGEN_SKIP 2348 #define ext(x) ((ExtendedValue)x) 2361 #define ext_hex(s) ext_hex_or(s, ext(0)) 2379 #define ext_hex_or(s, default_value) ExtendedValue_from_hex_default(s, default_value) 2396 #define ext_rgb(r, g, b) ExtendedValue_from_RGB((RGB){.red=r, .green=g, .blue=b}) 2410 #define ext_RGB(rgbval) ExtendedValue_from_RGB(rgbval) 2446 #define fore(x) ColorArg_to_ptr(fore_arg(x)) 2465 #define fore_arg(x) \ 2468 char* : ColorArg_from_str, \ 2469 RGB: ColorArg_from_RGB, \ 2470 BasicValue: ColorArg_from_BasicValue, \ 2471 ExtendedValue: ColorArg_from_ExtendedValue, \ 2472 StyleValue: ColorArg_from_StyleValue \ 2487 #define fore_str(x) ColorArg_to_esc(fore_arg(x)) 2527 #define fore_str_static(x) \ 2529 __typeof(x) _fss_val = x; \ 2530 ColorArg _fss_carg = fore_arg(_fss_val); \ 2531 size_t _fss_len = ColorArg_length(_fss_carg); \ 2532 char* _fss_codes = alloca(_fss_len); \ 2533 ColorArg_to_esc_s(_fss_codes, _fss_carg); \ 2556 #define hex(s) hex_or(s, rgb(0, 0, 0)) 2569 #define hex_or(s, default_rgb) RGB_from_hex_default(s, default_rgb) 2584 #define if_not_asprintf(...) if (asprintf(__VA_ARGS__) < 1) 2596 #define rgb(r, g, b) ((RGB){.red=r, .green=g, .blue=b}) 2620 #define style(x) ColorArg_to_ptr(style_arg(x)) 2634 #define style_arg(x) \ 2637 char* : ColorArg_from_str, \ 2638 StyleValue: ColorArg_from_StyleValue \ 2653 #define style_str(x) ColorArg_to_esc(style_arg(x)) 2691 #define style_str_static(x) \ 2692 (x == RESET_ALL ? "\x1b[0m" : \ 2693 (x == BOLD ? "\x1b[1m" : \ 2694 (x == BRIGHT ? "\x1b[1m" : \ 2695 (x == DIM ? "\x1b[2m" : \ 2696 (x == ITALIC ? "\x1b[3m" : \ 2697 (x == UNDERLINE ? "\x1b[4m" : \ 2698 (x == FLASH ? "\x1b[5m" : \ 2699 (x == HIGHLIGHT ? "\x1b[7m" : \ 2700 (x == STRIKETHRU ? "\x1b[9m" : \ 2701 (x == NORMAL ? "\x1b[22m" : \ 2702 (x == FRAME ? "\x1b[51m" : \ 2703 (x == ENCIRCLE ? "\x1b[52m" : \ 2704 (x == OVERLINE ? "\x1b[53m" : "\x1b[" colr_macro_str(x) "m" \ 2716 #define while_colr_va_arg(ap, vartype, x) while (x = va_arg(ap, vartype), !_colr_is_last_arg(x)) 2755 #ifndef DOXYGEN_SKIP 2758 #define BASIC_INVALID basic(BASIC_INVALID) 2759 #define BASIC_NONE basic(BASIC_NONE) 2760 #define BLACK basic(BLACK) 2761 #define RED basic(RED) 2762 #define GREEN basic(GREEN) 2763 #define YELLOW basic(YELLOW) 2764 #define BLUE basic(BLUE) 2765 #define MAGENTA basic(MAGENTA) 2766 #define CYAN basic(CYAN) 2767 #define WHITE basic(WHITE) 2768 #define UNUSED basic(UNUSED) 2769 #define RESET basic(RESET) 2770 #define LIGHTBLACK basic(LIGHTBLACK) 2771 #define LIGHTRED basic(LIGHTRED) 2772 #define LIGHTGREEN basic(LIGHTGREEN) 2773 #define LIGHTYELLOW basic(LIGHTYELLOW) 2774 #define LIGHTBLUE basic(LIGHTBLUE) 2775 #define LIGHTMAGENTA basic(LIGHTMAGENTA) 2776 #define LIGHTCYAN basic(LIGHTCYAN) 2777 #define LIGHTWHITE basic(LIGHTWHITE) 2782 #define XRESET ((ExtendedValue)0) 2783 #define XRED ((ExtendedValue)1) 2784 #define XGREEN ((ExtendedValue)2) 2785 #define XYELLOW ((ExtendedValue)3) 2786 #define XBLUE ((ExtendedValue)4) 2787 #define XMAGENTA ((ExtendedValue)5) 2788 #define XCYAN ((ExtendedValue)6) 2789 #define XWHITE ((ExtendedValue)7) 2790 #define XLIGHTBLACK ((ExtendedValue)8) 2791 #define XLIGHTRED ((ExtendedValue)9) 2792 #define XLIGHTGREEN ((ExtendedValue)10) 2793 #define XLIGHTYELLOW ((ExtendedValue)11) 2794 #define XLIGHTBLUE ((ExtendedValue)12) 2795 #define XLIGHTMAGENTA ((ExtendedValue)13) 2796 #define XLIGHTCYAN ((ExtendedValue)14) 2797 #define XLIGHTWHITE ((ExtendedValue)15) 2798 #define XBLACK ((ExtendedValue)16) 2799 #endif // DOXYGEN_SKIP 2839 #define STYLE_MAX_VALUE ((StyleValue)OVERLINE) 2840 #define STYLE_MIN_VALUE ((StyleValue)STYLE_INVALID_RANGE) 2843 #ifndef DOXYGEN_SKIP 2846 #define STYLE_INVALID_RANGE ((StyleValue)STYLE_INVALID_RANGE) 2847 #define STYLE_INVALID ((StyleValue)STYLE_INVALID) 2848 #define STYLE_NONE ((StyleValue)STYLE_NONE) 2849 #define RESET_ALL ((StyleValue)RESET_ALL) 2850 #define BRIGHT ((StyleValue)BRIGHT) 2851 #define BOLD ((StyleValue)BRIGHT) 2852 #define DIM ((StyleValue)DIM) 2853 #define ITALIC ((StyleValue)ITALIC) 2854 #define UNDERLINE ((StyleValue)UNDERLINE) 2855 #define FLASH ((StyleValue)FLASH) 2856 #define HIGHLIGHT ((StyleValue)HIGHLIGHT) 2857 #define NORMAL ((StyleValue)NORMAL) 2858 #define FRAME ((StyleValue)FRAME) 2859 #define ENCIRCLE ((StyleValue)ENCIRCLE) 2860 #define OVERLINE ((StyleValue)OVERLINE) 2861 #endif // DOXYGEN_SKIP 2871 #ifndef DOXYGEN_SKIP 2874 #define ARGTYPE_NONE ((ArgType)ARGTYPE_NONE) 2875 #define FORE ((ArgType)FORE) 2876 #define BACK ((ArgType)BACK) 2877 #define STYLE ((ArgType)STYLE) 2887 #ifndef DOXYGEN_SKIP 2890 #define JUST_NONE ((ColorJustifyMethod)JUST_NONE) 2891 #define JUST_LEFT ((ColorJustifyMethod)JUST_LEFT) 2892 #define JUST_RIGHT ((ColorJustifyMethod)JUST_RIGHT) 2893 #define JUST_CENTER ((ColorJustifyMethod)JUST_CENTER) 2898 TYPE_INVALID_STYLE = -5,
2899 TYPE_INVALID_RGB_RANGE = -4,
2908 #ifndef DOXYGEN_SKIP 2911 #define TYPE_NONE ((ColorType)TYPE_NONE) 2912 #define TYPE_INVALID_STYLE ((ColorType)TYPE_INVALID_STYLE) 2913 #define TYPE_INVALID_RGB_RANGE ((ColorType)TYPE_INVALID_RGB_RANGE) 2914 #define TYPE_INVALID_EXT_RANGE ((ColorType)TYPE_INVALID_EXT_RANGE) 2915 #define TYPE_INVALID ((ColorType)TYPE_INVALID) 2916 #define TYPE_BASIC ((ColorType)TYPE_BASIC) 2917 #define TYPE_EXTENDED ((ColorType)TYPE_EXTENDED) 2918 #define TYPE_RGB ((ColorType)TYPE_RGB) 2919 #define TYPE_STYLE ((ColorType)TYPE_STYLE) 3048 unsigned short rows;
3049 unsigned short columns;
3052 #ifndef DOXYGEN_SKIP 3077 typedef unsigned long ColrHash;
3079 #define COLR_HASH_FMT "%lu" 3082 struct _ColrLastArg_s {
3084 unsigned short value;
3087 static const struct _ColrLastArg_s _ColrLastArgValue = {
3092 #pragma clang diagnostic ignored "-Wunused-const-variable" 3093 static const struct _ColrLastArg_s*
const _ColrLastArg = &_ColrLastArgValue;
3094 #endif // DOXYGEN_SKIP 3129 int colr_printf_handler(FILE *fp,
const struct printf_info *info,
const void *
const *args);
3130 int colr_printf_info(
const struct printf_info *info,
size_t n,
int *argtypes,
int *sz);
3148 char*
colr_str_copy(
char* restrict dest,
const char* restrict src,
size_t length);
3158 char*
colr_str_ljust(
const char* s,
int width,
const char padchar);
3160 size_t colr_str_lstrip(
char* restrict dest,
const char* restrict s,
size_t length,
const char c);
3166 char*
colr_str_replace(
const char* restrict s,
const char* restrict target,
const char* restrict repl);
3167 char*
colr_str_replace_all(
const char* restrict s,
const char* restrict target,
const char* restrict repl);
3171 char*
colr_str_replace_cnt(
const char* restrict s,
const char* restrict target,
const char* restrict repl,
int count);
3175 char*
colr_str_replace_re(
const char* restrict s,
const char* restrict pattern,
const char* restrict repl,
int re_flags);
3176 char*
colr_str_replace_re_all(
const char* restrict s,
const char* restrict pattern,
const char* restrict repl,
int re_flags);
3202 char*
colr_str_rjust(
const char* s,
int width,
const char padchar);
3210 void format_bgx(
char* out,
unsigned char num);
3214 void format_fgx(
char* out,
unsigned char num);
3232 typedef char* (*rainbow_creator)(
const char* s,
double freq,
size_t offset,
size_t spread);
3234 char*
_rainbow(
RGB_fmter fmter,
const char* s,
double freq,
size_t offset,
size_t spread);
3239 char*
rainbow_fg(
const char* s,
double freq,
size_t offset,
size_t spread);
3240 char*
rainbow_fg_term(
const char* s,
double freq,
size_t offset,
size_t spread);
3241 char*
rainbow_bg(
const char* s,
double freq,
size_t offset,
size_t spread);
3242 char*
rainbow_bg_term(
const char* s,
double freq,
size_t offset,
size_t spread);
3476 ((
int)TYPE_INVALID == (
int)BASIC_INVALID) &&
3478 ((
int)EXT_INVALID == (
int)STYLE_INVALID)
3480 "Return/enum values for all color/style values should match." 3504 "Markers must be positive and unique for each struct in Colr!" char padchar
The desired padding character, or 0 to use the default (`' '`).
Definition: colr.h:2959
char * ColorArg_repr(ColorArg carg)
Creates a string (char*) representation for a ColorArg.
Definition: colr.c:5613
bool ColorArg_is_valid(ColorArg carg)
Checks to see if a ColorArg holds a valid value.
Definition: colr.c:5579
char * ExtendedValue_repr(int eval)
Creates a string (char*) representation of a ExtendedValue.
Definition: colr.c:8198
size_t _colr_join_array_length(void *ps)
Determine the length of a NULL-terminated array of strings (char*), ColorArgs, ColorResults, or ColorTexts.
Definition: colr.c:4976
char * colr_str_ljust(const char *s, int width, const char padchar)
Left-justifies a string (char*), ignoring escape codes when measuring the width.
Definition: colr.c:2347
char * colr_str_replace_re(const char *restrict s, const char *restrict pattern, const char *restrict repl, int re_flags)
Replaces a substring from a regex pattern string (char*) in a string (char*).
Definition: colr.c:3050
int ExtendedValue_from_str(const char *arg)
Converts a known name, integer string (0-255), or a hex string (char*), into an ExtendedValue suitabl...
Definition: colr.c:8095
char * StyleValue_to_str(StyleValue sval)
Create a human-friendly string (char*) representation for a StyleValue.
Definition: colr.c:8776
ColorArg ColorArg_from_str(ArgType type, const char *colorname)
Build a ColorArg (fore, back, or style value) from a known color name/style.
Definition: colr.c:5446
ColorResult * Colr_rjust_char(void *x, int width, char padchar)
Returns a right-justified (allocated) ColorResult when given a ColorText, ColorResult, or string (char*), along with the desired width and pad character.
Definition: colr.c:880
char * BasicValue_to_str(BasicValue bval)
Create a human-friendly string (char*) representation for a BasicValue.
Definition: colr.c:7932
char * colr_str_rjust(const char *s, int width, const char padchar)
Right-justifies a string (char*), ignoring escape codes when measuring the width. ...
Definition: colr.c:4186
bool ColorArg_eq(ColorArg a, ColorArg b)
Compares two ColorArg structs.
Definition: colr.c:5194
Holds a color type and it's value.
Definition: colr.h:2983
ColorArg * style
ColorArg for style value. Can be NULL.
Definition: colr.h:3041
char * ColorResult_repr(ColorResult cres)
Create a string representation for a ColorResult.
Definition: colr.c:6323
RGB RGB_from_hex_default(const char *hexstr, RGB default_value)
Convert a hex color into an RGB value, but use a default value when errors occur. ...
Definition: colr.c:8450
const ExtendedInfo extended_names[]
An array of ExtendedInfo, used with ExtendedValue_from_str().
Definition: colr.c:64
char * colr_str_replace_all_ColorText(const char *restrict s, const char *restrict target, ColorText *repl)
Replace all substrings in a string (char*) with a ColorText's string result.
Definition: colr.c:2830
#define COLORJUSTIFY_MARKER
Marker for the ColorJustify struct, for identifying a void pointer as a ColorJustify.
Definition: colr.h:308
char * StyleValue_repr(StyleValue sval)
Creates a string (char*) representation of a StyleValue.
Definition: colr.c:8799
char * colr_str_replace_all_ColorResult(const char *restrict s, const char *restrict target, ColorResult *repl)
Replace all substrings in a string (char*) with a ColorResult's string result.
Definition: colr.c:2803
bool colr_str_is_digits(const char *s)
Determines whether all characters in a string (char*) are digits.
Definition: colr.c:2292
char * colr_str_lstrip_chars(const char *restrict s, const char *restrict chars)
Removes certain characters from the start of a string (char*) and allocates a new string with the res...
Definition: colr.c:2492
char * colr_str_replace_re_all_ColorArg(const char *restrict s, const char *restrict pattern, ColorArg *repl, int re_flags)
Replace all substrings from a regex pattern string (char*) in a string (char*) with a ColorArg's stri...
Definition: colr.c:3141
char * colr_join_arrayn(void *joinerp, void *ps, size_t count)
Join an array of strings (char*), ColorArgs, or ColorTexts by another string (char*), ColorArg, or ColorText.
Definition: colr.c:4843
char * colr_str_to_lower(const char *s)
Allocate a new lowercase version of a string (char*).
Definition: colr.c:4319
char * colr_str_replace_cnt(const char *restrict s, const char *restrict target, const char *restrict repl, int count)
Replaces one or more substrings in a string (char*).
Definition: colr.c:2879
ColorArg * fore
ColorArg for fore color. Can be NULL.
Definition: colr.h:3037
char * name
The known name of the color.
Definition: colr.h:3000
#define COLOR_INVALID
Possible error return value for BasicValue_from_str(), ExtendedValue_from_str(), and colorname_to_rgb...
Definition: colr.h:323
size_t ColorValue_length(ArgType type, ColorValue cval)
Returns the length in bytes needed to allocate a string (char*) built with ColorValue_to_esc() with t...
Definition: colr.c:7438
void(* RGB_fmter)(char *out, RGB rgb)
A function type that knows how to fill a string with an rgb escape code.
Definition: colr.h:3229
void colr_append_reset(char *s)
Appends CODE_RESET_ALL to a string (char*), but makes sure to do it before any newlines.
Definition: colr.c:962
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorJustifys.
Definition: colr.h:2953
bool ColorValue_to_esc_s(char *dest, ArgType type, ColorValue cval)
Converts a ColorValue into an escape code string (char*) and fills the destination string...
Definition: colr.c:7647
bool colr_str_array_contains(char **lst, const char *s)
Determine if a string (char*) is in an array of strings (char**, where the last element is NULL)...
Definition: colr.c:1581
ColrHash colr_str_hash(const char *s)
Hash a string using djb2.
Definition: colr.c:2223
ColorArg ColorArg_from_ExtendedValue(ArgType type, ExtendedValue value)
Explicit version of ColorArg_from_value that only handles ExtendedValues.
Definition: colr.c:5345
ColorText * ColorText_set_just(ColorText *ctext, ColorJustify cjust)
Set the ColorJustify method for a ColorText, and return the ColorText.
Definition: colr.c:6718
bool ArgType_eq(ArgType a, ArgType b)
Compares two ArgTypes.
Definition: colr.c:5101
bool ExtendedValue_is_invalid(int eval)
Determines whether an integer is an invalid ExtendedValue.
Definition: colr.c:8172
ColorResult * Colr_ljust_char(void *x, int width, char padchar)
Returns a left-justified (allocated) ColorResult when given a ColorText, ColorResult, or string (char*), along with the desired width and pad character.
Definition: colr.c:843
struct winsize colr_win_size(void)
Attempts to retrieve a winsize struct from an ioctl call.
Definition: colr.c:4411
bool ColorArg_is_empty(ColorArg carg)
Checks to see if a ColorArg is an empty placeholder.
Definition: colr.c:5539
char * ColorType_repr(ColorType type)
Creates a string (char*) representation of a ColorType.
Definition: colr.c:7003
char * ColorJustifyMethod_repr(ColorJustifyMethod meth)
Creates a string (char*) representation for a ColorJustifyMethod.
Definition: colr.c:6017
#define style(x)
Create a style suitable for use with the Colr(), colr_cat(), colr_join(), Colr_cat(), Colr_join(), Colr_center(), Colr_ljust(), and Colr_rjust() macros.
Definition: colr.h:2620
bool BasicValue_is_invalid(BasicValue bval)
Determines whether a BasicValue is invalid.
Definition: colr.c:7800
ColorValue ColorValue_empty(void)
Create an "empty" ColorValue.
Definition: colr.c:7095
char * colr_str_replace_re_pat_ColorArg(const char *restrict s, regex_t *repattern, ColorArg *repl)
Replace regex patterns in a string (char*) with a ColorArg's string result.
Definition: colr.c:4014
ColorValue ColorValue_from_esc(const char *s)
Convert an escape-code string (char*) into a ColorValue.
Definition: colr.c:7188
char * colr_str_replace_re_matches_ColorResult(const char *restrict s, regmatch_t **matches, ColorResult *repl)
Replace substrings from an array of regex matches (regmatch_t**) in a string (char*) with a ColorResu...
Definition: colr.c:3659
bool colr_char_in_str(const char *s, const char c)
Determines if a character exists in the given string (char*).
Definition: colr.c:1062
char * text
Text to colorize.
Definition: colr.h:3034
bool colr_check_marker(uint32_t marker, void *p)
Checks an unsigned int against the individual bytes behind a pointer's value.
Definition: colr.c:1229
const size_t ext2rgb_map_len
Length of ext2rgb_map (should always be 256).
Definition: colr.c:404
bool colr_str_has_codes(const char *s)
Determines if a string (char*) has ANSI escape codes in it.
Definition: colr.c:2168
char * colr_str_replace_re_matches_ColorArg(const char *restrict s, regmatch_t **matches, ColorArg *repl)
Replace substrings from an array of regex matches (regmatch_t**) in a string (char*) with a ColorArg'...
Definition: colr.c:3628
const RGB ext2rgb_map[]
A map from ExtendedValue (256-color) to RGB value, where the index is the is the ExtendedValue, and the value is the RGB.
Definition: colr.c:137
void format_bg_RGB(char *out, RGB rgb)
Create an escape code for a true color (rgb) background color using values from an RGB struct...
Definition: colr.c:4486
char * colr_str_replace_re_all(const char *restrict s, const char *restrict pattern, const char *restrict repl, int re_flags)
Replaces all substrings from a regex pattern string (char*) in a string (char*).
Definition: colr.c:3104
ExtendedValue ext
ExtendedValue (256-colors) for the color.
Definition: colr.h:3002
Holds a string justification method, width, and padding character for ColorTexts. ...
Definition: colr.h:2951
BasicValue
Basic color values, with a few convenience values for extended colors.
Definition: colr.h:2726
char * colr_str_replace_ColorText(const char *restrict s, const char *restrict target, ColorText *repl)
Replace a substring in a string (char*) with a ColorText's string result.
Definition: colr.c:3000
char * colr_str_replace_re_match_ColorText(const char *restrict s, regmatch_t *match, ColorText *repl)
Replace substrings from a regex match (regmatch_t*) in a string (char*) with a ColorText's string res...
Definition: colr.c:3781
RGB rgb
RGB (TrueColor) for the color.
Definition: colr.h:3004
int colr_printf_handler(FILE *fp, const struct printf_info *info, const void *const *args)
Handles printing with printf for Colr objects.
Definition: colr.c:1391
size_t colr_str_chars_lcount(const char *restrict s, const char *restrict chars)
Counts the number of characters that are found at the beginning of a string (char*) (s)...
Definition: colr.c:1795
void format_fgx(char *out, unsigned char num)
Create an escape code for an extended fore color.
Definition: colr.c:4518
const size_t extended_names_len
Length of usable values in extended_names.
Definition: colr.c:86
char * ColorType_to_str(ColorType type)
Create a human-friendly string (char*) representation for a ColorType.
Definition: colr.c:7048
char * ColorArg_to_esc(ColorArg carg)
Converts a ColorArg into an escape code string (char*).
Definition: colr.c:5652
unsigned char blue
Blue value for a color.
Definition: colr.h:2815
bool colr_set_locale(void)
Sets the locale to (LC_ALL, "") if it hasn't already been set.
Definition: colr.c:1543
void ColorArg_free(ColorArg *p)
Free allocated memory for a ColorArg.
Definition: colr.c:5305
#define rgb(r, g, b)
Creates an anonymous RGB struct for use in function calls.
Definition: colr.h:2596
ColorText ColorText_from_valuesv(char *text, va_list args)
Builds a ColorText from 1 mandatory string (char*), and a va_list with optional fore, back, and style args (pointers to ColorArgs).
Definition: colr.c:6514
ColorResult * ColorResult_ljust(ColorResult *cres, int width, char padchar)
Left-justifies a ColorResult's string result and returns an allocated ColorResult (may be the same Co...
Definition: colr.c:6277
ColorResult ColorResult_from_str(const char *s)
Allocates a copy of a string, and creates a ColorResult from it.
Definition: colr.c:6182
char colr_char_escape_char(const char c)
Returns the char needed to represent an escape sequence in C.
Definition: colr.c:1033
char * colr_char_repr(char c)
Creates a string (char*) representation for a char.
Definition: colr.c:1105
Holds info about a known color name, like it's ExtendedValue and it's RGB value.
Definition: colr.h:2998
char * _colr_join(void *joinerp,...)
Joins ColorArgs, ColorTexts, and strings (char*) into one long string separated by it's first argumen...
Definition: colr.c:4623
char * RGB_repr(RGB rgb)
Creates a string (char*) representation for an RGB value.
Definition: colr.c:8666
ColorArg ** ColorArgs_from_str(const char *s, bool unique)
Create an array of ColorArgs from escape-codes found in a string (char*).
Definition: colr.c:5882
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorResults.
Definition: colr.h:3020
char * colr_str_replace_re_pat_all(const char *restrict s, regex_t *repattern, const char *restrict repl)
Replaces all matches to a regex pattern in a string (char*).
Definition: colr.c:3890
void format_fg_RGB_term(char *out, RGB rgb)
Create an escape code for a true color (rgb) fore color using an RGB struct's values, approximating 256-color values.
Definition: colr.c:4540
bool colr_char_is_code_end(const char c)
Determines if a character is suitable for an escape code ending.
Definition: colr.c:1086
char * colr_str_replace_re_pat(const char *restrict s, regex_t *repattern, const char *restrict repl)
Replaces regex patterns in a string (char*).
Definition: colr.c:3833
Holds a known color name and it's ExtendedValue.
Definition: colr.h:2936
StyleValue StyleValue_from_str(const char *arg)
Convert a named argument to actual StyleValue enum value.
Definition: colr.c:8727
ArgType
Argument types (fore, back, style).
Definition: colr.h:2864
const BasicInfo basic_names[]
An array of BasicInfo items, used with BasicValue_from_str().
Definition: colr.c:36
bool ColorValue_has_ExtendedValue(ColorValue cval, ExtendedValue eval)
Checks to see if a ColorValue has a ExtendedValue set.
Definition: colr.c:7361
int width
The desired width for the final string, or 0 to use colr_term_size().
Definition: colr.h:2957
ColorText * ColorText_to_ptr(ColorText ctext)
Copies a ColorText into allocated memory and returns the pointer.
Definition: colr.c:6817
char * colr_str_replace_all_ColorArg(const char *restrict s, const char *restrict target, ColorArg *repl)
Replace all substrings in a string (char*) with a ColorArg's string result.
Definition: colr.c:2774
char * ColorArg_example(ColorArg carg, bool colorized)
Create a string (char*) representation of a ColorArg with a stylized type/name using escape codes bui...
Definition: colr.c:5231
bool colr_supports_rgb_static(void)
Same as colr_supports_rgb(), but the environment is only checked on the first call.
Definition: colr.c:4372
struct winsize colr_win_size_env(void)
Get window/terminal size using the environment variables LINES, COLUMNS, or COLS. ...
Definition: colr.c:4436
char * ColorValue_repr(ColorValue cval)
Creates a string (char*) representation of a ColorValue.
Definition: colr.c:7515
int ExtendedValue_from_esc(const char *s)
Convert an escape-code string (char*) to an ExtendedValue.
Definition: colr.c:7989
ColorJustify ColorJustify_new(ColorJustifyMethod method, int width, char padchar)
Creates a ColorJustify.
Definition: colr.c:5965
#define ext(x)
Casts to ExtendedValue (unsigned char).
Definition: colr.h:2348
ExtendedValue ExtendedValue_from_RGB(RGB rgb)
Convert an RGB value into the closest matching ExtendedValue.
Definition: colr.c:8055
char * colr_str_lstrip_char(const char *s, const char c)
Strips a leading character from a string (char*), and allocates a new string with the result...
Definition: colr.c:2450
void ColorResult_free(ColorResult *p)
Free allocated memory for a ColorResult and it's .result member.
Definition: colr.c:6165
ColorArg ColorArg_from_RGB(ArgType type, RGB value)
Explicit version of ColorArg_from_value that only handles RGB structs.
Definition: colr.c:5368
bool colr_str_starts_with(const char *restrict s, const char *restrict prefix)
Checks a string (char*) for a certain prefix substring.
Definition: colr.c:4238
void colr_free_re_matches(regmatch_t **matches)
Free an array of allocated regmatch_t, like the return from colr_re_matches().
Definition: colr.c:1278
StyleValue StyleValue_from_esc(const char *s)
Convert an escape-code string (char*) to an actual StyleValue enum value.
Definition: colr.c:8705
void _colr_free(void *p)
Calls Colr *_free() functions for Colr objects, otherwise just calls free().
Definition: colr.c:4566
RGB RGB_from_BasicValue(BasicValue bval)
Return an RGB value from a known BasicValue.
Definition: colr.c:8275
char * ColorJustify_repr(ColorJustify cjust)
Creates a string (char*) representation for a ColorJustify.
Definition: colr.c:5987
bool colr_char_should_escape(const char c)
Determines if an ascii character has an escape sequence in C.
Definition: colr.c:1179
ColorText ColorText_empty(void)
Creates an "empty" ColorText with pointers set to NULL.
Definition: colr.c:6428
unsigned char red
Red value for a color.
Definition: colr.h:2811
bool ColorText_has_args(ColorText ctext)
Checks to see if a ColorText has any argument values set.
Definition: colr.c:6572
char * colr_str_replace_all(const char *restrict s, const char *restrict target, const char *restrict repl)
Replaces the first substring found in a string (char*).
Definition: colr.c:2751
uint32_t marker
The actual uint32_t marker value.
Definition: colr.h:2965
char * rainbow_bg(const char *s, double freq, size_t offset, size_t spread)
Rainbow-ize some text using rgb back colors, lolcat style.
Definition: colr.c:8902
bool ColorValue_is_invalid(ColorValue cval)
Checks to see if a ColorValue holds an invalid value.
Definition: colr.c:7412
char * colr_str_replace_re_all_ColorResult(const char *restrict s, const char *restrict pattern, ColorResult *repl, int re_flags)
Replace all substrings from a regex pattern string (char*) in a string (char*) with a ColorResult's s...
Definition: colr.c:3174
bool colr_str_is_empty(const char *s)
Checks to see if a string empty.
Definition: colr.c:2310
#define COLORARG_MARKER
Marker for the ColorArg struct, for identifying a void pointer as a ColorArg.
Definition: colr.h:298
bool colr_str_has_ColorArg(const char *s, ColorArg *carg)
Determines whether a string contains a specific color code.
Definition: colr.c:2145
char * _colr_ptr_repr(void *p)
Determine what kind of pointer is being passed, and call the appropriate <type>_repr function to obta...
Definition: colr.c:5047
Holds a known color name and it's BasicValue.
Definition: colr.h:2927
char * RGB_to_str(RGB rgb)
Convert an RGB value into a human-friendly RGB string (char*) suitable for input to RGB_from_str()...
Definition: colr.c:8610
char * colr_str_replace_re_match(const char *restrict s, regmatch_t *match, const char *restrict repl)
Replaces substrings from a single regex match (regmatch_t*) in a string (char*).
Definition: colr.c:3375
size_t ColorText_length(ColorText ctext)
Returns the length in bytes needed to allocate a string (char*) built with ColorText_to_str() with th...
Definition: colr.c:6629
size_t _colr_ptr_length(void *p)
Get the size, in bytes, needed to convert a ColorArg, ColorResult, ColorText, or string (char*) into ...
Definition: colr.c:5007
void colr_free_argsv(va_list args)
Free any ColrC objects (ColorArg, ColorResult, or ColorText pointer) passed in through a va_list...
Definition: colr.c:1266
char * colr_str_replace_re_ColorText(const char *restrict s, const char *restrict pattern, ColorText *repl, int re_flags)
Replace substrings from a regex pattern string (char*) in a string (char*) with a ColorText's string ...
Definition: colr.c:3303
ColorResult * ColorResult_from_stra(const char *s)
Allocates a copy of a string, and creates an allocated ColorResult from it.
Definition: colr.c:6199
bool ColorArg_to_esc_s(char *dest, ColorArg carg)
Converts a ColorArg into an escape code string (char*) and fills the destination string.
Definition: colr.c:5676
size_t colr_str_mb_len(const char *s)
Returns the number of characters in a string (char*), taking into account possibly multibyte characte...
Definition: colr.c:2541
ColorArg ColorArg_from_value(ArgType type, ColorType colrtype, void *p)
Used with the color_arg macro to dynamically create a ColorArg based on it's argument type...
Definition: colr.c:5514
bool ColorType_eq(ColorType a, ColorType b)
Compares two ColorTypes.
Definition: colr.c:6898
bool colr_supports_rgb(void)
Determine whether the current environment support RGB (True Colors).
Definition: colr.c:4355
ColorResult ColorResult_empty(void)
Creates a ColorResult with .result=NULL and .length=-1, with the appropriate struct marker...
Definition: colr.c:6131
unsigned char green
Green value for a color.
Definition: colr.h:2813
bool ColorResult_is_ptr(void *p)
Checks a void pointer to see if it contains a ColorResult struct.
Definition: colr.c:6233
ColorJustifyMethod method
The justification method, can be JUST_NONE.
Definition: colr.h:2955
size_t colr_str_code_len(const char *s)
Return the number of bytes that make up all the escape-codes in a string (char*). ...
Definition: colr.c:1871
#define COLORRESULT_MARKER
Marker for the ColorResult struct, for identifying a void pointer as a ColorResult.
Definition: colr.h:313
void format_style(char *out, StyleValue style)
Create an escape code for a style.
Definition: colr.c:4550
ColorResult * ColorResult_center(ColorResult *cres, int width, char padchar)
Centers a ColorResult's string result and returns an allocated ColorResult (may be the same ColorResu...
Definition: colr.c:6110
char * ColorValue_to_esc(ArgType type, ColorValue cval)
Converts a ColorValue into an escape code string (char*).
Definition: colr.c:7544
char * ColorValue_example(ColorValue cval)
Create a string (char*) representation of a ColorValue with a human-friendly type/name.
Definition: colr.c:7138
size_t _colr_join_size(void *joinerp, va_list args)
Parse arguments, just as in _colr_join(), but only return the size needed to allocate the resulting s...
Definition: colr.c:4744
regmatch_t * colr_alloc_regmatch(regmatch_t match)
Allocates space for a regmatch_t, initializes it, and returns a pointer to it.
Definition: colr.c:947
size_t colr_str_code_count(const char *s)
Return the number of escape-codes in a string (char*).
Definition: colr.c:1823
ColorType ColorType_from_str(const char *arg)
Determine which type of color value is desired by name.
Definition: colr.c:6941
size_t colr_mb_len(const char *s, size_t length)
Like mbrlen, except it will return the length of the next N (length) multibyte characters in bytes...
Definition: colr.c:1357
char * colr_str_replace_re_match_ColorArg(const char *restrict s, regmatch_t *match, ColorArg *repl)
Replace substrings from a regex match (regmatch_t*) in a string (char*) with a ColorArg's string resu...
Definition: colr.c:3720
ColorResult * Colr_center_char(void *x, int width, char padchar)
Returns a center-justified (allocated) ColorResult when given a ColorText, ColorResult, or string (char*), along with the desired width and pad character.
Definition: colr.c:807
const size_t basic_names_len
Length of usable values basic_names.
Definition: colr.c:61
bool _colr_is_last_arg(void *p)
Determines if a void pointer is _ColrLastArg (the last-arg-marker).
Definition: colr.c:4581
ExtendedValue ExtendedValue_from_hex_default(const char *hexstr, ExtendedValue default_value)
Create an ExtendedValue from a hex string (char*), but return a default value if the hex string is in...
Definition: colr.c:8042
ArgType type
Fore, back, style, invalid.
Definition: colr.h:3012
RGB RGB_monochrome(RGB rgb)
Convert an RGB value into either black or white, depending on it's average grayscale value...
Definition: colr.c:8577
char * colr_str_replace_re_pat_ColorResult(const char *restrict s, regex_t *repattern, ColorResult *repl)
Replace regex patterns in a string (char*) with a ColorResult's string result.
Definition: colr.c:4044
const ColorNameData colr_name_data[]
An array that holds a known color name, it's ExtendedValue, and it's RGB value.
Definition: colr.c:407
char * colr_str_replace_re_pat_all_ColorResult(const char *restrict s, regex_t *repattern, ColorResult *repl)
Replace all matches to a regex pattern in a string (char*) with a ColorResult's string result...
Definition: colr.c:3955
char * colr_str_replace_ColorArg(const char *restrict s, const char *restrict target, ColorArg *repl)
Replace a substring in a string (char*) with a ColorArg's string result.
Definition: colr.c:2944
ColorText * ColorText_set_ljust(ColorText *ctext, int width, char padchar)
Modify a ColorText to include a ColorJustify member to left-justify text when it is converted into a ...
Definition: colr.c:6737
size_t colr_str_char_count(const char *s, const char c)
Counts the number of characters (c) that are found in a string (char*) (s).
Definition: colr.c:1722
size_t _colr_join_arrayn_size(void *joinerp, void *ps, size_t count)
Get the size in bytes needed to join an array of strings (char*), ColorArgs, ColorResults, or ColorTexts by another string (char*), ColorArg, ColorResult, or ColorText.
Definition: colr.c:4939
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorTexts.
Definition: colr.h:3032
bool ColorText_is_ptr(void *p)
Checks a void pointer to see if it contains a ColorText struct.
Definition: colr.c:6609
void ColorText_free_args(ColorText *p)
Frees the ColorArg members of a ColorText.
Definition: colr.c:6465
char * ColorResult_to_str(ColorResult cres)
Convert a ColorResult into a string (char*).
Definition: colr.c:6418
char * ArgType_repr(ArgType type)
Creates a string (char*) representation of a ArgType.
Definition: colr.c:5116
bool ColorArg_is_invalid(ColorArg carg)
Checks to see if a ColorArg holds an invalid value.
Definition: colr.c:5550
const size_t style_names_len
Length of usable values in style_names.
Definition: colr.c:116
ColorValue value
Color type and value.
Definition: colr.h:3014
char * rainbow_fg(const char *s, double freq, size_t offset, size_t spread)
Rainbow-ize some text using rgb fore colors, lolcat style.
Definition: colr.c:8959
int ExtendedValue_from_BasicValue(BasicValue bval)
Convert a BasicValue into an ExtendedValue.
Definition: colr.c:7969
char * colr_str_replace_re_match_i(const char *restrict ref, char *target, regmatch_t *match, const char *restrict repl)
Replaces substrings from a regex match (regmatch_t*) in a string (char*).
Definition: colr.c:3481
ColorArg ColorArg_from_esc(const char *s)
Parse an escape-code string (char*) into a ColorArg.
Definition: colr.c:5397
void colr_str_lower(char *s)
Converts a string (char*) into lower case in place.
Definition: colr.c:2390
Breaks down Colr struct markers, such as COLORARG_MARKER, into individual bytes.
Definition: colr.h:2963
BasicValue BasicValue_from_esc(const char *s)
Convert an escape-code string (char*) to an actual BasicValue enum value.
Definition: colr.c:7753
ColorArg * back
ColorArg for back color. Can be NULL.
Definition: colr.h:3039
int colr_printf_info(const struct printf_info *info, size_t n, int *argtypes, int *sz)
Handles the arg count/size for the Colr printf handler.
Definition: colr.c:1482
char * TermSize_repr(TermSize ts)
Create a string (char*) representation for a TermSize.
Definition: colr.c:8866
char * result
A string (char*) result from one of the colr functions.
Definition: colr.h:3022
bool ColorJustify_eq(ColorJustify a, ColorJustify b)
Compares two ColorJustify structs.
Definition: colr.c:5927
char * colr_empty_str(void)
Allocates an empty string (char*).
Definition: colr.c:1252
bool StyleValue_is_valid(StyleValue sval)
Determines whether a StyleValue is valid.
Definition: colr.c:8761
bool colr_str_ends_with(const char *restrict s, const char *restrict suffix)
Determine if one string (char*) ends with another.
Definition: colr.c:1985
void ColorText_free(ColorText *p)
Frees a ColorText and it's ColorArgs.
Definition: colr.c:6448
bool ColorValue_eq(ColorValue a, ColorValue b)
Compares two ColorValue structs.
Definition: colr.c:7116
bool ExtendedValue_is_valid(int eval)
Determines whether an integer is a valid ExtendedValue.
Definition: colr.c:8183
ColorValue ColorValue_from_str(const char *s)
Create a ColorValue from a known color name, or RGB string (char*).
Definition: colr.c:7236
char * colr_str_replace_re_matches_ColorText(const char *restrict s, regmatch_t **matches, ColorText *repl)
Replace substrings from an array of regex matches (regmatch_t**) in a string (char*) with a ColorText...
Definition: colr.c:3689
ColorArg ColorArg_empty(void)
Create a ColorArg with ARGTYPE_NONE and ColorValue.type.TYPE_NONE.
Definition: colr.c:5175
size_t length
A length in bytes for the string result.
Definition: colr.h:3026
bool ColorArg_is_ptr(void *p)
Checks a void pointer to see if it contains a ColorArg struct.
Definition: colr.c:5563
ColorResult * Colr_fmt_str(const char *fmt,...)
Allocate and format a string like asprintf, but wrap it in an allocated ColorResult.
Definition: colr.c:922
bool colr_str_is_codes(const char *s)
Determines if a string (char*) is composed entirely of escape codes.
Definition: colr.c:2266
bool StyleValue_eq(StyleValue a, StyleValue b)
Compares two StyleValues.
Definition: colr.c:8689
ColorArg ColorArg_from_StyleValue(ArgType type, StyleValue value)
Explicit version of ColorArg_from_value that only handles StyleValues.
Definition: colr.c:5485
char * _rainbow(RGB_fmter fmter, const char *s, double freq, size_t offset, size_t spread)
Handles multibyte character string (char*) conversion and character iteration for all of the rainbow_...
Definition: colr.c:9012
ColorResult * ColorResult_Colr(ColorResult *cres,...)
Colorize a ColorResult, and return a new allocated ColorResult.
Definition: colr.c:6057
char * rainbow_fg_term(const char *s, double freq, size_t offset, size_t spread)
This is exactly like rainbow_fg(), except it uses colors that are closer to the standard 256-color va...
Definition: colr.c:8988
bool ColorValue_is_valid(ColorValue cval)
Checks to see if a ColorValue holds a valid value.
Definition: colr.c:7423
char * rainbow_bg_term(const char *s, double freq, size_t offset, size_t spread)
This is exactly like rainbow_bg(), except it uses colors that are closer to the standard 256-color va...
Definition: colr.c:8931
ColorJustify ColorJustify_empty(void)
Creates an "empty" ColorJustify, with JUST_NONE set.
Definition: colr.c:5907
#define COLORLASTARG_MARKER
Marker for the _ColrLastArg_s struct, for identifying a void pointer as a _ColrLastArg_s.
Definition: colr.h:303
RGB RGB_inverted(RGB rgb)
Make a copy of an RGB value, with the colors "inverted" (like highlighting text in the terminal)...
Definition: colr.c:8559
int RGB_from_esc(const char *s, RGB *rgb)
Convert an escape-code string (char*) to an actual RGB value.
Definition: colr.c:8353
char * ExtendedValue_to_str(ExtendedValue eval)
Creates a human-friendly string (char*) from an ExtendedValue's actual value, suitable for use with E...
Definition: colr.c:8225
char * colr_str_center(const char *s, int width, const char padchar)
Center-justifies a string (char*), ignoring escape codes when measuring the width.
Definition: colr.c:1655
#define COLOR_INVALID_RANGE
Possible error return value for RGB_from_str().
Definition: colr.h:325
Holds a known style name and it's StyleValue.
Definition: colr.h:2945
size_t ColorArg_length(ColorArg carg)
Returns the length in bytes needed to allocate a string (char*) built with ColorArg_to_esc().
Definition: colr.c:5594
Holds a terminal size, usually retrieved with colr_term_size().
Definition: colr.h:3047
int colr_printf_esc_mod
Integer to test for the presence of the "escaped output modifier" in colr_printf_handler.
Definition: colr.c:33
Holds a string (char*) that was definitely allocated by Colr.
Definition: colr.h:3018
char * colr_str_replace_ColorResult(const char *restrict s, const char *restrict target, ColorResult *repl)
Replace a substring in a string (char*) with a ColorResult's string result.
Definition: colr.c:2973
#define basic(x)
Casts to BasicValue.
Definition: colr.h:567
ColorText * ColorText_set_center(ColorText *ctext, int width, char padchar)
Modify a ColorText to include a ColorJustify member to center-justify text when it is converted into ...
Definition: colr.c:6699
void format_bg(char *out, BasicValue value)
Create an escape code for a background color.
Definition: colr.c:4463
bool ColorText_is_empty(ColorText ctext)
Checks to see if a ColorText has no usable values.
Definition: colr.c:6593
TermSize colr_term_size(void)
Attempts to retrieve the row/column size of the terminal and returns a TermSize.
Definition: colr.c:4392
#define EXT_INVALID
Alias for COLOR_INVALID.
Definition: colr.h:357
char * BasicValue_repr(BasicValue bval)
Creates a string (char*) representation of a BasicValue.
Definition: colr.c:7826
char * ColorArgs_array_repr(ColorArg **lst)
Creates a string representation for an array of ColorArg pointers.
Definition: colr.c:5758
int RGB_from_str(const char *arg, RGB *rgb)
Convert an RGB string (char*) into an RGB value.
Definition: colr.c:8494
bool ExtendedValue_eq(ExtendedValue a, ExtendedValue b)
Compares two ExtendedValues.
Definition: colr.c:7955
bool colr_str_is_all(const char *s, const char c)
Determines whether a string (char*) consists of only one character, possibly repeated.
Definition: colr.c:2243
char * colr_str_strip_codes(const char *s)
Strips escape codes from a string (char*), resulting in a new allocated string.
Definition: colr.c:4287
ColorArg * ColorArg_to_ptr(ColorArg carg)
Copies a ColorArg into memory and returns the pointer.
Definition: colr.c:5697
char * colr_str_replace(const char *restrict s, const char *restrict target, const char *restrict repl)
Replaces the first substring found in a string (char*).
Definition: colr.c:2709
bool colr_is_colr_ptr(void *p)
Determines whether a void pointer is a ColorArg, ColorResult, or ColorText pointer.
Definition: colr.c:1293
bool ColorResult_is_empty(ColorResult cres)
Checks to see if a ColorResult is "empty" (NULL or empty string).
Definition: colr.c:6220
Holds an ArgType, and a ColorValue.
Definition: colr.h:3008
int ExtendedValue_from_hex(const char *hexstr)
Create an ExtendedValue from a hex string (char*).
Definition: colr.c:8017
bool ColorType_is_invalid(ColorType type)
Check to see if a ColorType value is considered invalid.
Definition: colr.c:6977
RGB RGB_from_ExtendedValue(ExtendedValue eval)
Return an RGB value from a known ExtendedValue.
Definition: colr.c:8334
ColorResult * ColorResult_to_ptr(ColorResult cres)
Allocate memory for a ColorResult, fill it, and return it.
Definition: colr.c:6394
char * colr_str_repr(const char *s)
Convert a string (char*) into a representation of a string, by wrapping it in quotes and escaping cha...
Definition: colr.c:4112
char * colr_str_replace_re_pat_all_ColorText(const char *restrict s, regex_t *repattern, ColorText *repl)
Replace all matches to a regex pattern in a string (char*) with a ColorText's string result...
Definition: colr.c:3984
char * colr_str_replace_re_ColorResult(const char *restrict s, const char *restrict pattern, ColorResult *repl, int re_flags)
Replace substrings from a regex pattern string (char*) in a string (char*) with a ColorResult's strin...
Definition: colr.c:3272
size_t ColorResult_length(ColorResult cres)
Return the length in bytes (including the null-terminator), that is needed to store the return from C...
Definition: colr.c:6250
bool ColorType_is_valid(ColorType type)
Check to see if a ColorType value is considered valid.
Definition: colr.c:6988
int BasicValue_to_ansi(ArgType type, BasicValue bval)
Converts a fore/back BasicValue to the actual ansi code number.
Definition: colr.c:7907
Holds a string of text, and optional fore, back, and style ColorArgs.
Definition: colr.h:3030
bool RGB_eq(RGB a, RGB b)
Compare two RGB structs.
Definition: colr.c:8255
unsigned char RGB_average(RGB rgb)
Return the average for an RGB value.
Definition: colr.c:8241
Container for RGB values.
Definition: colr.h:2805
void format_bgx(char *out, unsigned char num)
Create an escape code for an extended background color.
Definition: colr.c:4474
ColorType
Color/Style code types. Used with ColorType_from_str() and ColorValue.
Definition: colr.h:2896
#define COLORTEXT_MARKER
Marker for the ColorText struct, for identifying a void pointer as a ColorText.
Definition: colr.h:318
char * ColorText_to_str(ColorText ctext)
Stringifies a ColorText struct, creating a mix of escape codes and text.
Definition: colr.c:6837
char * RGB_to_hex(RGB rgb)
Converts an RGB value into a hex string (char*).
Definition: colr.c:8592
int RGB_from_hex(const char *hexstr, RGB *rgb)
Convert a hex color into an RGB value.
Definition: colr.c:8392
bool ColorJustify_is_empty(ColorJustify cjust)
Checks to see if a ColorJustify is "empty".
Definition: colr.c:5947
ColorArg ColorArg_from_BasicValue(ArgType type, BasicValue value)
Explicit version of ColorArg_from_value that only handles BasicValues.
Definition: colr.c:5322
char * colr_join_array(void *joinerp, void *ps)
Join an array of strings (char*), ColorArgs, or ColorTexts by another string (char*), ColorArg, or ColorText.
Definition: colr.c:4802
void ColorArgs_array_free(ColorArg **ps)
Free an allocated array of ColorArgs, including the array itself.
Definition: colr.c:5727
RGB RGB_grayscale(RGB rgb)
Return a grayscale version of an RGB value.
Definition: colr.c:8544
unsigned char ExtendedValue
Convenience typedef for clarity when dealing with extended (256) colors.
Definition: colr.h:2802
char * colr_str_replace_re_all_ColorText(const char *restrict s, const char *restrict pattern, ColorText *repl, int re_flags)
Replace all substrings from a regex pattern string (char*) in a string (char*) with a ColorText's str...
Definition: colr.c:3206
char * ArgType_to_str(ArgType type)
Creates a human-friendly string (char*) from an ArgType.
Definition: colr.c:5146
const size_t colr_name_data_len
Length of colr_name_data.
Definition: colr.c:790
char * ColorText_repr(ColorText ctext)
Allocate a string (char*) representation for a ColorText.
Definition: colr.c:6661
bool ColorValue_has_StyleValue(ColorValue cval, StyleValue sval)
Checks to see if a ColorValue has a StyleValue set.
Definition: colr.c:7374
RGB RGB_to_term_RGB(RGB rgb)
Convert an RGB value into it's nearest terminal-friendly RGB value.
Definition: colr.c:8625
char * colr_str_replace_re_ColorArg(const char *restrict s, const char *restrict pattern, ColorArg *repl, int re_flags)
Replace substrings from a regex pattern string (char*) in a string (char*) with a ColorArg's string r...
Definition: colr.c:3239
bool ColorResult_eq(ColorResult a, ColorResult b)
Compares two ColorResults.
Definition: colr.c:6151
ColorResult * ColorResult_rjust(ColorResult *cres, int width, char padchar)
Right-justifies a ColorResult's string result and returns an allocated ColorResult (may be the same C...
Definition: colr.c:6365
bool ColorValue_has_BasicValue(ColorValue cval, BasicValue bval)
Checks to see if a ColorValue has a BasicValue set.
Definition: colr.c:7348
bool StyleValue_is_invalid(StyleValue sval)
Determines whether a StyleValue is invalid.
Definition: colr.c:8750
size_t colr_str_noncode_len(const char *s)
Returns the length of string (char*), ignoring escape codes and the the null-terminator.
Definition: colr.c:2578
BasicValue BasicValue_from_str(const char *arg)
Convert named argument to an actual BasicValue enum value.
Definition: colr.c:7777
ColorText ColorText_from_values(char *text,...)
Builds a ColorText from 1 mandatory string (char*), and optional fore, back, and style args (pointers...
Definition: colr.c:6488
void ColorText_set_values(ColorText *ctext, char *text,...)
Initializes an existing ColorText from 1 mandatory string (char*), and optional fore, back, and style args (pointers to ColorArgs).
Definition: colr.c:6770
RGB rainbow_step(double freq, size_t offset)
A single step in rainbow-izing produces the next color in the "rainbow" as an RGB value...
Definition: colr.c:9082
char * colr_str_replace_re_pat_ColorText(const char *restrict s, regex_t *repattern, ColorText *repl)
Replace regex patterns in a string (char*) with a ColorText's string result.
Definition: colr.c:4073
ColorJustify just
ColorJustify info, set to JUST_NONE by default.
Definition: colr.h:3043
bool BasicValue_is_valid(BasicValue bval)
Determines whether a BasicValue is valid.
Definition: colr.c:7811
void format_fg_RGB(char *out, RGB rgb)
Create an escape code for a true color (rgb) fore color using an RGB struct's values.
Definition: colr.c:4529
ColorText * ColorText_set_rjust(ColorText *ctext, int width, char padchar)
Modify a ColorText to include a ColorJustify member to right-justify text when it is converted into a...
Definition: colr.c:6755
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorArgs.
Definition: colr.h:3010
bool ColorValue_has_RGB(ColorValue cval, RGB rgb)
Checks to see if a ColorValue has a RGB value set.
Definition: colr.c:7387
char * ColorResult_rip_str(ColorResult *cres)
Returns the string from a ColorResult pointer, but frees the ColorResult itself (without destroying t...
Definition: colr.c:6337
bool ColorValue_is_empty(ColorValue cval)
Checks to see if a ColorValue is an empty placeholder.
Definition: colr.c:7401
StyleValue
Style values.
Definition: colr.h:2819
char * colr_str_replace_re_pat_all_ColorArg(const char *restrict s, regex_t *repattern, ColorArg *repl)
Replace all matches to a regex pattern in a string (char*) with a ColorArg's string result...
Definition: colr.c:3925
size_t colr_str_char_lcount(const char *s, const char c)
Counts the number of characters (c) that are found at the beginning of a string (char*) (s)...
Definition: colr.c:1759
void format_bg_RGB_term(char *out, RGB rgb)
Create an escape code for a true color (rgb) fore color using an RGB struct's values, approximating 256-color values.
Definition: colr.c:4497
const StyleInfo style_names[]
An array of StyleInfo items, used with StyleName_from_str().
Definition: colr.c:89
ColorValue ColorValue_from_value(ColorType type, void *p)
Used with the color_val macro to dynamically create a ColorValue based on it's argument type...
Definition: colr.c:7302
char * colr_str_copy(char *restrict dest, const char *restrict src, size_t length)
Copies a string (char*) like strncpy, but ensures null-termination.
Definition: colr.c:1955
size_t colr_str_lstrip(char *restrict dest, const char *restrict s, size_t length, const char c)
Strip a leading character from a string (char*), filling another string (char*) with the result...
Definition: colr.c:2417
ColorResult ColorResult_new(char *s)
Initialize a new ColorResult with an allocated string (char*).
Definition: colr.c:6301
char * _colr_ptr_to_str(void *p)
Determine what kind of pointer is being passed, and call the appropriate <type>_to_str function to ob...
Definition: colr.c:5076
char * colr_str_replace_re_matches(const char *restrict s, regmatch_t **matches, const char *restrict repl)
Replaces substrings from an array of regex match (regmatch_t*) in a string (char*).
Definition: colr.c:3559
void colr_printf_register(void)
Registers COLR_FMT_CHAR to handle Colr objects in the printf-family functions.
Definition: colr.c:1526
bool BasicValue_eq(BasicValue a, BasicValue b)
Compares two BasicValues.
Definition: colr.c:7737
regmatch_t ** colr_re_matches(const char *s, regex_t *repattern)
Returns all regmatch_t matches for regex pattern in a string (char*).
Definition: colr.c:2636
void colr_str_array_free(char **ps)
Free an allocated array of strings, including the array itself.
Definition: colr.c:1614
void format_fg(char *out, BasicValue value)
Create an escape code for a fore color.
Definition: colr.c:4507
char * colr_str_replace_re_match_ColorResult(const char *restrict s, regmatch_t *match, ColorResult *repl)
Replace substrings from a regex match (regmatch_t*) in a string (char*) with a ColorResult's string r...
Definition: colr.c:3751
ColorJustifyMethod
Justification style for ColorTexts.
Definition: colr.h:2880
bool ColorText_has_arg(ColorText ctext, ColorArg carg)
Checks to see if a ColorText has a certain ColorArg value set.
Definition: colr.c:6556
char ** colr_str_get_codes(const char *s, bool unique)
Get an array of escape-codes from a string (char*).
Definition: colr.c:2048