ColrC  0.3.7
An easy to use C library for linux terminal colors/escape-codes.
colr.h (0.3.7)
Go to the documentation of this file.
1 
34 #ifndef COLR_H
35 #define COLR_H
36 
38 #define COLR_VERSION "0.3.7"
39 
40 /* Tell gcc to ignore clang pragmas, for linting. */
41 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
42 
43 #ifndef DOXYGEN_SKIP
44 
51 #if (__STDC_VERSION__ >= 201112L)
52  #if defined(__GNUC__) && !defined(__clang__)
53  #if (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))
54  #define IS_C11
55  #endif
56  #else
57  #define IS_C11
58  #endif
59 #endif
60 #endif // DOXYGEN_SKIP
61 
62 // Without _Generic, ColrC is useless.
63 #ifndef IS_C11
64  #error "ColrC cannot compile without C11+ generic selections (_Generic)."
65 #endif
66 
67 // ColrC uses GNU extensions.
68 #if defined(__GNUC__)
69  #if !defined(_GNU_SOURCE)
70  /*
71  This enables gnu extensions.
72  ColrC will not compile at all without this.
73  Current GNU dependencies:
74  Optional:
75  Statement-Expressions in fore_str_static/back_str_static
76  register_printf_specifier from printf.h.
77  Required:
78  stdio.h: asprintf()
79  locale.h: uselocale(), LC_GLOBAL_LOCALE
80  string.h: strndup(), strdup(), strcmp(), strcasecmp(), strnlen()
81  math.h: sin(), M_PI
82  */
83  #define _GNU_SOURCE
84  #elif _GNU_SOURCE < 1
85  // This is for testing. If _GNU_SOURCE=0 is set, it will be undefined,
86  // and I can watch all of the warnings and errors that pop up.
87  #undef _GNU_SOURCE
88  #pragma GCC warning "Trying to compile without _GNU_SOURCE, this will not work."
89  #endif
90  #pragma clang diagnostic push
91  #pragma clang diagnostic ignored "-Wmacro-redefined"
92 
127  #define COLR_GNU
128  #pragma clang diagnostic pop // -Wmacro-redefined
129 #else
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."
133  #else
134  #pragma GCC warning "No glibc and COLR_GNU=0, some features will be disabled."
135  #endif
136 #endif
137 
138 #include <assert.h>
139 // assert() uses a statement-expression when compiling with __GNUC__ defined.
140 // This is here to silence clang linters.
141 #pragma clang diagnostic ignored "-Wgnu-statement-expression"
142 
143 #include <ctype.h> // islower, iscntrl, isdigit, etc.
144 /* Must include `-lm` in compiler args or Makefile LIBS!
145  This is for the `sin()` function used in `rainbow_step()`.
146 */
147 #include <math.h>
148 #include <limits.h> // Used for asprintf return checking.
149 #include <locale.h> // Not used in colr.c, but necessary for users of rainbow stuff.
150 #ifdef COLR_GNU
151  #include <printf.h> // For register_printf_specifier.
152 #endif
153 #include <regex.h> // For colr_str_replace_re and friends.
154 #include <stdarg.h> // Variadic functions and `va_list`.
155 #include <stdbool.h>
156 #include <stdint.h> // marker integers for colr structs
157 #include <stdio.h> // snprintf, fileno, etc.
158 #include <stdlib.h> // calloc, free, malloc, etc.
159 #include <string.h> // strcat
160 #include <sys/ioctl.h> // For `struct winsize` and the `ioctl()` call to use it.
161 #include <unistd.h> // isatty
162 #include <wchar.h>
163 /* This is only enabled for development. */
164 #if defined(DEBUG) && defined(COLR_DEBUG)
165  #include "dbug.h"
166 #endif
167 /* Tell gcc to ignore unused macros. */
168 #pragma GCC diagnostic ignored "-Wunused-macros"
169 
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"
190 
192 #define CODE_RESET_LEN 5
193 
198 #define CODE_LEN_MIN 5
199 
202 #define CODE_LEN 14
203 
208 #define CODEX_LEN_MIN 10
209 #define CODEX_LEN 12
211 
216 #define STYLE_LEN_MIN 5
217 #define STYLE_LEN 6
219 
225 #define COLOR_LEN 30
226 
231 #define CODE_RGB_LEN_MIN 14
232 #define CODE_RGB_LEN 20
234 
240 #define COLOR_RGB_LEN 26
241 
247 #define CODE_ANY_LEN 46
248 
298 #define COLORARG_MARKER UINT32_MAX
299 
303 #define COLORLASTARG_MARKER (UINT32_MAX - 20)
304 
308 #define COLORJUSTIFY_MARKER (UINT32_MAX - 30)
309 
313 #define COLORRESULT_MARKER (UINT32_MAX - 40)
314 
318 #define COLORTEXT_MARKER (UINT32_MAX - 50)
319 
323 #define COLOR_INVALID (-2)
324 #define COLOR_INVALID_RANGE (-3)
326 
328 #define COLR_HASH_SEED 5381
329 
334 #ifndef COLR_FMT
335  #define COLR_FMT "R"
336 #endif
337 #pragma info "Set COLR_FMT=" COLR_FMT
338 
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]
345 
348 extern int colr_printf_esc_mod;
349 
357 #define EXT_INVALID COLOR_INVALID
358 
365 #define EXT_INVALID_RANGE COLOR_INVALID_RANGE
366 
375 #define alloc_basic() calloc(CODE_LEN, sizeof(char))
376 
385 #define alloc_extended() calloc(CODEX_LEN, sizeof(char))
386 
387 
396 #define alloc_rgb() calloc(CODE_RGB_LEN, sizeof(char))
397 
406 #define alloc_style() calloc(STYLE_LEN, sizeof(char))
407 
408 
415 #define asprintf_or_return(retval, ...) if_not_asprintf(__VA_ARGS__) return retval
416 
417 
453 #define back(x) ColorArg_to_ptr(back_arg(x))
454 
476 #define back_arg(x) \
477  _Generic( \
478  (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 \
484  )(BACK, x)
485 
498 #define back_str(x) ColorArg_to_esc(back_arg(x))
499 
500 #ifdef COLR_GNU
501 
538 #define back_str_static(x) \
539  __extension__ ({ \
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); \
545  _bss_codes; \
546  })
547  /* A Variable Length Array will not work here.
548  The space for `_bss_codes` would be deallocated before this statement
549  expression returns. Using `alloca` ensures that it will live at least
550  as long as the calling function.
551  See:
552  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_002a_005f_005fbuiltin_005falloca
553  */
554 #endif // COLR_GNU
555 
567 #define basic(x) ((BasicValue)(x))
568 
580 #define bool_colr_enum(x) (x < 0 ? false: true)
581 
593 #define color_arg(type, x) \
594  _Generic( \
595  (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) \
601  )
602 
643 #define color_name_is_invalid(x) ColorType_is_invalid(ColorType_from_str(x))
644 
685 #define color_name_is_valid(x) ColorType_is_valid(ColorType_from_str(x))
686 
697 #define color_val(x) \
698  _Generic( \
699  (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) \
704  )
705 
723 #define ColorValue_has(cval, val) \
724  _Generic( \
725  (val), \
726  BasicValue: ColorValue_has_BasicValue, \
727  ExtendedValue: ColorValue_has_ExtendedValue, \
728  StyleValue: ColorValue_has_StyleValue, \
729  RGB: ColorValue_has_RGB \
730  )(cval, val)
731 
751 #define Colr(text, ...) ColorText_to_ptr(ColorText_from_values(text, __VA_ARGS__, _ColrLastArg))
752 
788 #define Colra(text, ...) ColorText_from_values(text, __VA_ARGS__, _ColrLastArg)
789 
805 #define Colr_cat(...) ColorResult_to_ptr(ColorResult_new(colr_cat(__VA_ARGS__)))
806 
834 #define Colr_center(text, justwidth, ...) ColorText_set_just( \
835  Colr(text, __VA_ARGS__), \
836  (ColorJustify){.method=JUST_CENTER, .width=justwidth, .padchar=' '} \
837  )
838 
866 #define Colr_center_char(text, justwidth, c, ...) ColorText_set_just( \
867  Colr(text, __VA_ARGS__), \
868  (ColorJustify){.method=JUST_CENTER, .width=justwidth, .padchar=c} \
869  )
870 
901 #define Colr_fmt(fmt, value, ...) \
902  ColorResult_Colr( \
903  Colr_fmt_str(fmt, value), \
904  __VA_ARGS__, \
905  _ColrLastArg \
906  )
907 
936 #define Colr_join(joiner, ...) ColrResult(colr_join(joiner, __VA_ARGS__))
937 
964 #define Colr_ljust(text, justwidth, ...) ColorText_set_just( \
965  Colr(text, __VA_ARGS__), \
966  (ColorJustify){.method=JUST_LEFT, .width=justwidth, .padchar=' '} \
967  )
968 
995 #define Colr_ljust_char(text, justwidth, c, ...) ColorText_set_just( \
996  Colr(text, __VA_ARGS__), \
997  (ColorJustify){.method=JUST_LEFT, .width=justwidth, .padchar=c} \
998  )
999 
1027 #define Colr_rjust(text, justwidth, ...) ColorText_set_just( \
1028  Colr(text, __VA_ARGS__), \
1029  (ColorJustify){.method=JUST_RIGHT, .width=justwidth, .padchar=' '} \
1030  )
1031 
1058 #define Colr_rjust_char(text, justwidth, c, ...) ColorText_set_just( \
1059  Colr(text, __VA_ARGS__), \
1060  (ColorJustify){.method=JUST_RIGHT, .width=justwidth, .padchar=c} \
1061  )
1062 
1073 #define ColrResult(s) ColorResult_to_ptr(ColorResult_new(s))
1074 
1097 #define ColrColorResult(cres, ...) ColorResult_Colr(cres, __VA_ARGS__, _ColrLastArg)
1098 
1118 #define colr(text, ...) colr_cat(Colr(text, __VA_ARGS__))
1119 
1160 #define colr_cat(...) _colr_join("", __VA_ARGS__, _ColrLastArg)
1161 
1169 #define colr_alloc_len(x) \
1170  _Generic( \
1171  (x), \
1172  RGB: CODE_RGB_LEN, \
1173  BasicValue: CODE_LEN, \
1174  ExtendedValue: CODEX_LEN, \
1175  StyleValue: STYLE_LEN \
1176  )
1177 
1188 #define colr_eq(a, b) \
1189  _Generic( \
1190  (a), \
1191  ArgType: ArgType_eq, \
1192  BasicValue: BasicValue_eq, \
1193  ColorArg: ColorArg_eq, \
1194  ColorJustify: ColorJustify_eq, \
1195  ColorResult: ColorResult_eq, \
1196  ColorType: ColorType_eq, \
1197  ColorValue: ColorValue_eq, \
1198  ExtendedValue: ExtendedValue_eq, \
1199  RGB: RGB_eq, \
1200  StyleValue: StyleValue_eq \
1201  )(a, b)
1202 
1217 #define colr_example(x) \
1218  _Generic( \
1219  (x), \
1220  ColorArg: ColorArg_example, \
1221  ColorValue: ColorValue_example \
1222  )(x)
1223 
1231 #define colr_fprint(file, ...) \
1232  do { \
1233  char* _c_p_s = colr_cat(__VA_ARGS__); \
1234  if (!_c_p_s) break; \
1235  fprintf(file, "%s", _c_p_s); \
1236  colr_free(_c_p_s); \
1237  } while (0)
1238 
1252 #define colr_free(x) \
1253  _Generic( \
1254  (x), \
1255  ColorArg*: ColorArg_free, \
1256  ColorArg**: ColorArgs_array_free, \
1257  ColorResult*: ColorResult_free, \
1258  ColorText*: ColorText_free, \
1259  regmatch_t**: colr_free_re_matches, \
1260  default: _colr_free \
1261  )(x)
1262 
1268 #define colr_is_empty(x) \
1269  _Generic( \
1270  (x), \
1271  ColorArg: ColorArg_is_empty, \
1272  ColorJustify: ColorJustify_is_empty, \
1273  ColorText: ColorText_is_empty, \
1274  ColorValue: ColorValue_is_empty \
1275  )(x)
1276 
1283 #define colr_is_invalid(x) \
1284  _Generic( \
1285  (x), \
1286  BasicValue: BasicValue_is_invalid, \
1287  ExtendedValue: ExtendedValue_is_invalid, \
1288  StyleValue: StyleValue_is_invalid, \
1289  ColorArg: ColorArg_is_invalid, \
1290  ColorType: ColorType_is_invalid, \
1291  ColorValue: ColorValue_is_invalid \
1292  )(x)
1293 
1299 #define colr_is_valid(x) \
1300  _Generic( \
1301  (x), \
1302  BasicValue: BasicValue_is_valid, \
1303  ExtendedValue: ExtendedValue_is_valid, \
1304  StyleValue: StyleValue_is_valid, \
1305  ColorArg: ColorArg_is_valid, \
1306  ColorType: ColorType_is_valid, \
1307  ColorValue: ColorValue_is_valid \
1308  )(x)
1309 
1318 #define colr_is_valid_mblen(x) ((x) && ((x) != (size_t)-1) && ((x) != (size_t)-2))
1319 
1329 #define colr_istr_either(s1, s2, s3) \
1330  ( \
1331  ((s1) && (s2) && (s3)) ? \
1332  (colr_istr_eq((s1), (s2)) || colr_istr_eq((s1), (s3))) : \
1333  false \
1334  )
1335 
1344 #define colr_istr_eq(s1, s2) \
1345  ( \
1346  ((s1) && (s2)) ? \
1347  !strcasecmp((s1), (s2)) : \
1348  false \
1349  )
1350 
1379 #define colr_join(joiner, ...) _colr_join(joiner, __VA_ARGS__, _ColrLastArg)
1380 
1390 #define colr_length(x) \
1391  _Generic( \
1392  (x), \
1393  ColorArg: ColorArg_length, \
1394  ColorResult: ColorResult_length, \
1395  ColorText: ColorText_length, \
1396  ColorValue: ColorValue_length, \
1397  void*: _colr_ptr_length \
1398  )(x)
1399 
1400 #ifndef DOXYGEN_SKIP
1401 // These are just some stringification macros.
1402 // The first one is the typical stringify macro.
1403 #define _colr_macro_str(x) #x
1404 #define colr_macro_str(x) _colr_macro_str(x)
1405 // This one stringifies the entire argument list as one string.
1406 #define _colr_macro_str_all(...) #__VA_ARGS__
1407 #define colr_macro_str_all(...) _colr_macro_str_all(__VA_ARGS__)
1408 // This is the standard concatenation macro.
1409 #define _colr_macro_concat(a, b) a ## b
1410 #define colr_macro_concat(a, b) _colr_macro_concat(a, b)
1411 #endif
1412 
1419 #define colr_max(a, b) (a > b ? a : b)
1420 
1427 #define colr_print(...) \
1428  do { \
1429  char* _c_p_s = colr_cat(__VA_ARGS__); \
1430  if (!_c_p_s) break; \
1431  printf("%s", _c_p_s); \
1432  colr_free(_c_p_s); \
1433  } while (0)
1434 
1435 
1436 #ifdef COLR_GNU
1437 
1451 #define colr_printf_macro(func, ...) \
1452  __extension__({ \
1453  _Pragma("GCC diagnostic push"); \
1454  _Pragma("GCC diagnostic ignored \"-Wformat=\""); \
1455  _Pragma("GCC diagnostic ignored \"-Wformat-extra-args\""); \
1456  _Pragma("clang diagnostic push"); \
1457  _Pragma("clang diagnostic ignored \"-Wformat-invalid-specifier\""); \
1458  colr_printf_register(); \
1459  int _c_p_m_ret = func(__VA_ARGS__); \
1460  _Pragma("clang diagnostic pop"); \
1461  _Pragma("GCC diagnostic pop"); \
1462  _c_p_m_ret; \
1463  })
1464 
1482 #define colr_printf(...) colr_printf_macro(printf, __VA_ARGS__)
1483 
1499 #define colr_fprintf(...) colr_printf_macro(fprintf, __VA_ARGS__)
1500 
1516 #define colr_sprintf(...) colr_printf_macro(sprintf, __VA_ARGS__)
1517 
1533 #define colr_snprintf(...) colr_printf_macro(snprintf, __VA_ARGS__)
1534 
1550 #define colr_asprintf(...) colr_printf_macro(asprintf, __VA_ARGS__)
1551 #endif // COLR_GNU
1552 
1560 #define colr_puts(...) \
1561  do { \
1562  char* _c_p_s = colr_cat(__VA_ARGS__); \
1563  if (!_c_p_s) break; \
1564  puts(_c_p_s); \
1565  colr_free(_c_p_s); \
1566  } while (0)
1567 
1645 #define colr_replace(s, target, repl) \
1646  _Generic( \
1647  (repl), \
1648  char*: _Generic( \
1649  (target), \
1650  char* : colr_str_replace, \
1651  regex_t* : colr_str_replace_re_pat, \
1652  regmatch_t*: colr_str_replace_re_match, \
1653  regmatch_t**: colr_str_replace_re_matches \
1654  ), \
1655  ColorArg*: _Generic( \
1656  (target), \
1657  char* : colr_str_replace_ColorArg, \
1658  regex_t* : colr_str_replace_re_pat_ColorArg, \
1659  regmatch_t*: colr_str_replace_re_match_ColorArg, \
1660  regmatch_t**: colr_str_replace_re_matches_ColorArg \
1661  ), \
1662  ColorResult*: _Generic( \
1663  (target), \
1664  char* : colr_str_replace_ColorResult, \
1665  regex_t* : colr_str_replace_re_pat_ColorResult, \
1666  regmatch_t*: colr_str_replace_re_match_ColorResult, \
1667  regmatch_t**: colr_str_replace_re_matches_ColorResult \
1668  ), \
1669  ColorText*: _Generic( \
1670  (target), \
1671  char* : colr_str_replace_ColorText, \
1672  regex_t* : colr_str_replace_re_pat_ColorText, \
1673  regmatch_t*: colr_str_replace_re_match_ColorText, \
1674  regmatch_t**: colr_str_replace_re_matches_ColorText \
1675  ) \
1676  )(s, target, repl)
1677 
1747 #define colr_replace_all(s, target, repl) \
1748  _Generic( \
1749  (repl), \
1750  char*: _Generic( \
1751  (target), \
1752  char* : colr_str_replace_all, \
1753  regex_t* : colr_str_replace_re_pat_all, \
1754  regmatch_t** : colr_str_replace_re_matches \
1755  ), \
1756  ColorArg*: _Generic( \
1757  (target), \
1758  char* : colr_str_replace_all_ColorArg, \
1759  regex_t* : colr_str_replace_re_pat_all_ColorArg, \
1760  regmatch_t** : colr_str_replace_re_matches_ColorArg \
1761  ), \
1762  ColorResult*: _Generic( \
1763  (target), \
1764  char* : colr_str_replace_all_ColorResult, \
1765  regex_t* : colr_str_replace_re_pat_all_ColorResult, \
1766  regmatch_t** : colr_str_replace_re_matches_ColorResult \
1767  ), \
1768  ColorText*: _Generic( \
1769  (target), \
1770  char* : colr_str_replace_all_ColorText, \
1771  regex_t* : colr_str_replace_re_pat_all_ColorText, \
1772  regmatch_t** : colr_str_replace_re_matches_ColorText \
1773  ) \
1774  )(s, target, repl)
1775 
1873 #define colr_replace_re(s, target, repl, flags) \
1874  _Generic( \
1875  (repl), \
1876  char*: colr_str_replace_re, \
1877  ColorArg*: colr_str_replace_re_ColorArg, \
1878  ColorResult*: colr_str_replace_re_ColorResult, \
1879  ColorText*: colr_str_replace_re_ColorText \
1880  )(s, target, repl, flags)
1881 
1978 #define colr_replace_re_all(s, target, repl, flags) \
1979  _Generic( \
1980  (repl), \
1981  char*: colr_str_replace_re_all, \
1982  ColorArg*: colr_str_replace_re_all_ColorArg, \
1983  ColorResult*: colr_str_replace_re_all_ColorResult, \
1984  ColorText*: colr_str_replace_re_all_ColorText \
1985  )(s, target, repl, flags)
1986 
2022 #define colr_repr(x) \
2023  _Generic( \
2024  (x), \
2025  ColorArg: ColorArg_repr, \
2026  ColorArg**: ColorArgs_array_repr, \
2027  ColorJustify: ColorJustify_repr, \
2028  ColorJustifyMethod: ColorJustifyMethod_repr, \
2029  ColorResult: ColorResult_repr, \
2030  ColorText: ColorText_repr, \
2031  ColorValue: ColorValue_repr, \
2032  ArgType: ArgType_repr, \
2033  ColorType: ColorType_repr, \
2034  BasicValue: BasicValue_repr, \
2035  ExtendedValue: ExtendedValue_repr, \
2036  RGB: RGB_repr, \
2037  StyleValue: StyleValue_repr, \
2038  TermSize: TermSize_repr, \
2039  const char*: colr_str_repr, \
2040  char*: colr_str_repr, \
2041  const char: colr_char_repr, \
2042  char: colr_char_repr, \
2043  void*: _colr_ptr_repr \
2044  )(x)
2045 
2046 
2055 #define colr_str_eq(s1, s2) ( \
2056  ((s1) && (s2)) ? !strcmp((s1), (s2)) : false \
2057  )
2058 
2068 #define colr_str_either(s1, s2, s3) (colr_str_eq(s1, s2) || colr_str_eq(s1, s3))
2069 
2083 #define colr_to_str(x) \
2084  _Generic( \
2085  (x), \
2086  ArgType: ArgType_to_str, \
2087  BasicValue: BasicValue_to_str, \
2088  ColorArg: ColorArg_to_esc, \
2089  ColorResult: ColorResult_to_str, \
2090  ColorText: ColorText_to_str, \
2091  ColorType: ColorType_to_str, \
2092  ExtendedValue: ExtendedValue_to_str, \
2093  StyleValue: StyleValue_to_str, \
2094  RGB: RGB_to_str, \
2095  void*: _colr_ptr_to_str \
2096  )(x)
2097 
2098 #ifndef DOXYGEN_SKIP
2099 #if defined(DEBUG) && defined(DBUG_H) && defined(dbug)
2100 
2114  #define dbug_repr(lbl, x) \
2115  do { \
2116  char* _dbug_repr_s = colr_repr(x); \
2117  dbug("%s: %s\n", lbl, _dbug_repr_s); \
2118  free(_dbug_repr_s); \
2119  } while(0)
2120 #else
2121  #if !defined(dbug)
2122 
2129  #define dbug(...) ((void)0)
2130  #endif
2131 
2139  #define dbug_repr(lbl, x) ((void)0)
2140 #endif
2141 #endif // DOXYGEN_SKIP
2142 
2158 #define ext(x) ((ExtendedValue)x)
2159 
2171 #define ext_hex(s) ext_hex_or(s, ext(0))
2172 
2189 #define ext_hex_or(s, default_value) ExtendedValue_from_hex_default(s, default_value)
2190 
2206 #define ext_rgb(r, g, b) ExtendedValue_from_RGB((RGB){.red=r, .green=g, .blue=b})
2207 
2220 #define ext_RGB(rgbval) ExtendedValue_from_RGB(rgbval)
2221 
2256 #define fore(x) ColorArg_to_ptr(fore_arg(x))
2257 
2275 #define fore_arg(x) \
2276  _Generic( \
2277  (x), \
2278  char* : ColorArg_from_str, \
2279  RGB: ColorArg_from_RGB, \
2280  BasicValue: ColorArg_from_BasicValue, \
2281  ExtendedValue: ColorArg_from_ExtendedValue, \
2282  StyleValue: ColorArg_from_StyleValue \
2283  )(FORE, x)
2284 
2297 #define fore_str(x) ColorArg_to_esc(fore_arg(x))
2298 
2299 #ifdef COLR_GNU
2300 
2337 #define fore_str_static(x) \
2338  __extension__ ({ \
2339  __typeof(x) _fss_val = x; \
2340  ColorArg _fss_carg = fore_arg(_fss_val); \
2341  size_t _fss_len = ColorArg_length(_fss_carg); \
2342  char* _fss_codes = alloca(_fss_len); \
2343  ColorArg_to_esc_s(_fss_codes, _fss_carg); \
2344  _fss_codes; \
2345  })
2346  /* A Variable Length Array will not work here.
2347  The space for `_fss_codes` would be deallocated before this statement
2348  expression returns. Using `alloca` ensures that it will live at least
2349  as long as the calling function.
2350  See:
2351  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_002a_005f_005fbuiltin_005falloca
2352  */
2353 #endif // COLR_GNU
2354 
2355 
2366 #define hex(s) hex_or(s, rgb(0, 0, 0))
2367 
2379 #define hex_or(s, default_rgb) RGB_from_hex_default(s, default_rgb)
2380 
2394 #define if_not_asprintf(...) if (asprintf(__VA_ARGS__) < 1)
2395 
2406 #define rgb(r, g, b) ((RGB){.red=r, .green=g, .blue=b})
2407 
2430 #define style(x) ColorArg_to_ptr(style_arg(x))
2431 
2444 #define style_arg(x) \
2445  _Generic( \
2446  (x), \
2447  char* : ColorArg_from_str, \
2448  StyleValue: ColorArg_from_StyleValue \
2449  )(STYLE, x)
2450 
2463 #define style_str(x) ColorArg_to_esc(style_arg(x))
2464 
2501 #define style_str_static(x) \
2502  (x == RESET_ALL ? "\x1b[0m" : \
2503  (x ==BRIGHT ? "\x1b[1m" : \
2504  (x == DIM ? "\x1b[2m" : \
2505  (x == ITALIC ? "\x1b[3m" : \
2506  (x == UNDERLINE ? "\x1b[4m" : \
2507  (x == FLASH ? "\x1b[5m" : \
2508  (x == HIGHLIGHT ? "\x1b[7m" : \
2509  (x == STRIKETHRU ? "\x1b[9m" : \
2510  (x == NORMAL ? "\x1b[22m" : \
2511  (x == FRAME ? "\x1b[51m" : \
2512  (x == ENCIRCLE ? "\x1b[52m" : \
2513  (x == OVERLINE ? "\x1b[53m" : "\x1b[" colr_macro_str(x) "m" \
2514  ))))))))))))
2515 
2525 #define while_colr_va_arg(ap, vartype, x) while (x = va_arg(ap, vartype), !_colr_is_last_arg(x))
2526 
2527 
2535 typedef enum BasicValue {
2536  BASIC_INVALID_RANGE = COLOR_INVALID_RANGE,
2537  BASIC_INVALID = COLOR_INVALID,
2538  BASIC_NONE = -1,
2539  // The actual escape code value for fore colors is BasicValue + 30 == (30-39).
2540  // The actual escape code value for back colors is BasicValue + 40 == (40-49).
2541  BLACK = 0,
2542  RED = 1,
2543  GREEN = 2,
2544  YELLOW = 3,
2545  BLUE = 4,
2546  MAGENTA = 5,
2547  CYAN = 6,
2548  WHITE = 7,
2549  UNUSED = 8,
2550  RESET = 9,
2551  // The following colors are basic "bright" colors.
2552  // The actual escape code value for fore colors is BasicValue + 80 == (90-97).
2553  // The actual escape code value for back colors is BasicValue + 90 == (100-107).
2554  LIGHTBLACK = 10,
2555  LIGHTRED = 11,
2556  LIGHTGREEN = 12,
2557  LIGHTYELLOW = 13,
2558  LIGHTBLUE = 14,
2559  LIGHTMAGENTA = 15,
2560  LIGHTCYAN = 16,
2561  LIGHTWHITE = 17,
2562 } BasicValue;
2563 
2564 #ifndef DOXYGEN_SKIP
2565 // This makes enum values more friendly to _Generic, by explicitly casting
2566 // from `int` to the enum type.
2567 #define BASIC_INVALID basic(BASIC_INVALID)
2568 #define BASIC_NONE basic(BASIC_NONE)
2569 #define BLACK basic(BLACK)
2570 #define RED basic(RED)
2571 #define GREEN basic(GREEN)
2572 #define YELLOW basic(YELLOW)
2573 #define BLUE basic(BLUE)
2574 #define MAGENTA basic(MAGENTA)
2575 #define CYAN basic(CYAN)
2576 #define WHITE basic(WHITE)
2577 #define UNUSED basic(UNUSED)
2578 #define RESET basic(RESET)
2579 #define LIGHTBLACK basic(LIGHTBLACK)
2580 #define LIGHTRED basic(LIGHTRED)
2581 #define LIGHTGREEN basic(LIGHTGREEN)
2582 #define LIGHTYELLOW basic(LIGHTYELLOW)
2583 #define LIGHTBLUE basic(LIGHTBLUE)
2584 #define LIGHTMAGENTA basic(LIGHTMAGENTA)
2585 #define LIGHTCYAN basic(LIGHTCYAN)
2586 #define LIGHTWHITE basic(LIGHTWHITE)
2587 
2591 #define XRESET ((ExtendedValue)0)
2592 #define XRED ((ExtendedValue)1)
2593 #define XGREEN ((ExtendedValue)2)
2594 #define XYELLOW ((ExtendedValue)3)
2595 #define XBLUE ((ExtendedValue)4)
2596 #define XMAGENTA ((ExtendedValue)5)
2597 #define XCYAN ((ExtendedValue)6)
2598 #define XWHITE ((ExtendedValue)7)
2599 #define XLIGHTBLACK ((ExtendedValue)8)
2600 #define XLIGHTRED ((ExtendedValue)9)
2601 #define XLIGHTGREEN ((ExtendedValue)10)
2602 #define XLIGHTYELLOW ((ExtendedValue)11)
2603 #define XLIGHTBLUE ((ExtendedValue)12)
2604 #define XLIGHTMAGENTA ((ExtendedValue)13)
2605 #define XLIGHTCYAN ((ExtendedValue)14)
2606 #define XLIGHTWHITE ((ExtendedValue)15)
2607 #define XBLACK ((ExtendedValue)16)
2608 #endif // DOXYGEN_SKIP
2609 
2611 typedef unsigned char ExtendedValue;
2612 
2614 typedef struct RGB {
2619  unsigned char red;
2622  unsigned char green;
2624  unsigned char blue;
2625 } RGB;
2626 
2628 typedef enum StyleValue {
2629  STYLE_INVALID_RANGE = COLOR_INVALID_RANGE,
2630  STYLE_INVALID = COLOR_INVALID,
2631  STYLE_NONE = -1,
2632  RESET_ALL = 0,
2633  BRIGHT = 1,
2634  DIM = 2,
2635  ITALIC = 3,
2636  UNDERLINE = 4,
2637  FLASH = 5, // DOS has a "rapid flash" for 6 also.
2638  HIGHLIGHT = 7,
2639  STRIKETHRU = 9,
2640  NORMAL = 22,
2641  // May not be supported.
2642  FRAME = 51,
2643  ENCIRCLE = 52,
2644  OVERLINE = 53, // Supported in Konsole.
2645 } StyleValue;
2646 
2648 #define STYLE_MAX_VALUE ((StyleValue)OVERLINE)
2649 #define STYLE_MIN_VALUE ((StyleValue)STYLE_INVALID_RANGE)
2651 
2652 #ifndef DOXYGEN_SKIP
2653 // This makes enum values more friendly to _Generic, by explicitly casting
2654 // from `int` to the enum type.
2655 #define STYLE_INVALID_RANGE ((StyleValue)STYLE_INVALID_RANGE)
2656 #define STYLE_INVALID ((StyleValue)STYLE_INVALID)
2657 #define STYLE_NONE ((StyleValue)STYLE_NONE)
2658 #define RESET_ALL ((StyleValue)RESET_ALL)
2659 #define BRIGHT ((StyleValue)BRIGHT)
2660 #define DIM ((StyleValue)DIM)
2661 #define ITALIC ((StyleValue)ITALIC)
2662 #define UNDERLINE ((StyleValue)UNDERLINE)
2663 #define FLASH ((StyleValue)FLASH)
2664 #define HIGHLIGHT ((StyleValue)HIGHLIGHT)
2665 #define NORMAL ((StyleValue)NORMAL)
2666 #define FRAME ((StyleValue)FRAME)
2667 #define ENCIRCLE ((StyleValue)ENCIRCLE)
2668 #define OVERLINE ((StyleValue)OVERLINE)
2669 #endif // DOXYGEN_SKIP
2670 
2672 typedef enum ArgType {
2673  ARGTYPE_NONE = -1,
2674  FORE = 0,
2675  BACK = 1,
2676  STYLE = 2,
2677 } ArgType;
2678 
2679 #ifndef DOXYGEN_SKIP
2680 // This makes enum values more friendly to _Generic, by explicitly casting
2681 // from `int` to the enum type.
2682 #define ARGTYPE_NONE ((ArgType)ARGTYPE_NONE)
2683 #define FORE ((ArgType)FORE)
2684 #define BACK ((ArgType)BACK)
2685 #define STYLE ((ArgType)STYLE)
2686 #endif
2687 typedef enum ColorJustifyMethod {
2689  JUST_NONE = -1,
2690  JUST_LEFT = 0,
2691  JUST_RIGHT = 1,
2692  JUST_CENTER = 2,
2694 
2695 #ifndef DOXYGEN_SKIP
2696 // This makes enum values more friendly to _Generic, by explicitly casting
2697 // from `int` to the enum type.
2698 #define JUST_NONE ((ColorJustifyMethod)JUST_NONE)
2699 #define JUST_LEFT ((ColorJustifyMethod)JUST_LEFT)
2700 #define JUST_RIGHT ((ColorJustifyMethod)JUST_RIGHT)
2701 #define JUST_CENTER ((ColorJustifyMethod)JUST_CENTER)
2702 #endif
2703 typedef enum ColorType {
2705  TYPE_NONE = -6,
2706  TYPE_INVALID_STYLE = -5,
2707  TYPE_INVALID_RGB_RANGE = -4,
2708  TYPE_INVALID_EXT_RANGE = COLOR_INVALID_RANGE,
2709  TYPE_INVALID = COLOR_INVALID,
2710  TYPE_BASIC = 0,
2711  TYPE_EXTENDED = 1,
2712  TYPE_RGB = 2,
2713  TYPE_STYLE = 3,
2714 } ColorType;
2715 
2716 #ifndef DOXYGEN_SKIP
2717 // This makes enum values more friendly to _Generic, by explicitly casting
2718 // from `int` to the enum type.
2719 #define TYPE_NONE ((ColorType)TYPE_NONE)
2720 #define TYPE_INVALID_STYLE ((ColorType)TYPE_INVALID_STYLE)
2721 #define TYPE_INVALID_RGB_RANGE ((ColorType)TYPE_INVALID_RGB_RANGE)
2722 #define TYPE_INVALID_EXT_RANGE ((ColorType)TYPE_INVALID_EXT_RANGE)
2723 #define TYPE_INVALID ((ColorType)TYPE_INVALID)
2724 #define TYPE_BASIC ((ColorType)TYPE_BASIC)
2725 #define TYPE_EXTENDED ((ColorType)TYPE_EXTENDED)
2726 #define TYPE_RGB ((ColorType)TYPE_RGB)
2727 #define TYPE_STYLE ((ColorType)TYPE_STYLE)
2728 #endif
2729 
2735 typedef struct BasicInfo {
2736  char* name;
2737  BasicValue value;
2738 } BasicInfo;
2744 typedef struct ExtendedInfo {
2745  char* name;
2746  ExtendedValue value;
2747 } ExtendedInfo;
2753 typedef struct StyleInfo {
2754  char* name;
2755  StyleValue value;
2756 } StyleInfo;
2757 
2759 typedef struct ColorJustify {
2761  uint32_t marker;
2765  int width;
2767  char padchar;
2768 } ColorJustify;
2769 
2771 typedef union ColorStructMarker {
2773  uint32_t marker;
2775  struct {
2776  uint8_t b1;
2777  uint8_t b2;
2778  uint8_t b3;
2779  uint8_t b4;
2780  } bytes;
2791 typedef struct ColorValue {
2792  ColorType type;
2793  BasicValue basic;
2795  RGB rgb;
2796  StyleValue style;
2797 } ColorValue;
2798 
2806 typedef struct ColorNameData {
2808  char* name;
2813 } ColorNameData;
2814 
2816 typedef struct ColorArg {
2818  uint32_t marker;
2823 } ColorArg;
2824 
2826 typedef struct ColorResult {
2828  uint32_t marker;
2830  char* result;
2834  size_t length;
2835 } ColorResult;
2836 
2838 typedef struct ColorText {
2840  uint32_t marker;
2842  char* text;
2843  // Pointers are used for compatibility with the fore(), back(), and style() macros.
2852 } ColorText;
2853 
2855 typedef struct TermSize {
2856  unsigned short rows;
2857  unsigned short columns;
2858 } TermSize;
2859 
2860 #ifndef DOXYGEN_SKIP
2861 extern const BasicInfo basic_names[];
2864 extern const size_t basic_names_len;
2866 extern const ExtendedInfo extended_names[];
2868 extern const size_t extended_names_len;
2870 extern const StyleInfo style_names[];
2872 extern const size_t style_names_len;
2873 
2875 extern const RGB ext2rgb_map[];
2877 extern const size_t ext2rgb_map_len;
2878 
2880 extern const ColorNameData colr_name_data[];
2882 extern const size_t colr_name_data_len;
2883 
2885 typedef unsigned long ColrHash;
2887 #define COLR_HASH_FMT "%lu"
2888 
2890 struct _ColrLastArg_s {
2891  uint32_t marker;
2892  unsigned short value;
2893 };
2894 
2895 static const struct _ColrLastArg_s _ColrLastArgValue = {
2896  .marker=COLORLASTARG_MARKER,
2897  .value=1337
2898 };
2899 // clang linter says it's unused, but it's used in the _colr* functions, and others.
2900 #pragma clang diagnostic ignored "-Wunused-const-variable"
2901 static const struct _ColrLastArg_s* const _ColrLastArg = &_ColrLastArgValue;
2902 #endif // DOXYGEN_SKIP
2903 
2908 #ifdef DOXYGEN_SKIP
2909  // This is strictly for Doxygen, because it doesn't know what __attribute__ is,
2910  // even if you tell it with `PREDEFINED = __attribute__(x)=`
2911  ColorResult* Colr_fmt_str(const char* fmt, ...);
2912 #else
2913  ColorResult* Colr_fmt_str(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
2914 #endif
2915 
2916 regmatch_t* colr_alloc_regmatch(regmatch_t match);
2917 void colr_append_reset(char* s);
2918 
2919 char colr_char_escape_char(const char c);
2920 bool colr_char_in_str(const char* s, const char c);
2921 bool colr_char_is_code_end(const char c);
2922 char* colr_char_repr(char c);
2923 bool colr_char_should_escape(const char c);
2924 
2925 bool colr_check_marker(uint32_t marker, void* p);
2926 char* colr_empty_str(void);
2927 void colr_free_argsv(va_list args);
2928 void colr_free_re_matches(regmatch_t** matches);
2929 bool colr_is_colr_ptr(void* p);
2930 size_t colr_mb_len(const char* s, size_t length);
2931 
2932 #ifdef COLR_GNU
2933 int colr_printf_handler(FILE *fp, const struct printf_info *info, const void *const *args);
2934 int colr_printf_info(const struct printf_info *info, size_t n, int *argtypes, int *sz);
2935 // The contructor attribute isn't used because not everyone needs this.
2936 void colr_printf_register(void); // __attribute__((constructor))
2937 #endif
2938 
2939 regmatch_t** colr_re_matches(const char* s, regex_t* repattern);
2940 bool colr_set_locale(void);
2941 bool colr_supports_rgb(void);
2942 bool colr_supports_rgb_static(void);
2943 
2944 bool colr_str_array_contains(char** lst, const char* s);
2945 void colr_str_array_free(char** ps);
2946 size_t colr_str_char_count(const char* s, const char c);
2947 size_t colr_str_char_lcount(const char* s, const char c);
2948 size_t colr_str_chars_lcount(const char* restrict s, const char* restrict chars);
2949 char* colr_str_center(const char* s, int width, const char padchar);
2950 size_t colr_str_code_count(const char* s);
2951 size_t colr_str_code_len(const char* s);
2952 char* colr_str_copy(char* restrict dest, const char* restrict src, size_t length);
2953 bool colr_str_ends_with(const char* restrict s, const char* restrict suffix);
2954 char** colr_str_get_codes(const char* s, bool unique);
2955 bool colr_str_has_ColorArg(const char* s, ColorArg* carg);
2956 bool colr_str_has_codes(const char* s);
2957 ColrHash colr_str_hash(const char* s);
2958 bool colr_str_is_all(const char* s, const char c);
2959 bool colr_str_is_codes(const char* s);
2960 bool colr_str_is_digits(const char* s);
2961 char* colr_str_ljust(const char* s, int width, const char padchar);
2962 void colr_str_lower(char* s);
2963 size_t colr_str_lstrip(char* restrict dest, const char* restrict s, size_t length, const char c);
2964 char* colr_str_lstrip_char(const char* s, const char c);
2965 char* colr_str_lstrip_chars(const char* restrict s, const char* restrict chars);
2966 size_t colr_str_mb_len(const char* s);
2967 size_t colr_str_noncode_len(const char* s);
2968 
2969 char* colr_str_replace(const char* restrict s, const char* restrict target, const char* restrict repl);
2970 char* colr_str_replace_all(const char* restrict s, const char* restrict target, const char* restrict repl);
2971 char* colr_str_replace_all_ColorArg(const char* restrict s, const char* restrict target, ColorArg* repl);
2972 char* colr_str_replace_all_ColorResult(const char* restrict s, const char* restrict target, ColorResult* repl);
2973 char* colr_str_replace_all_ColorText(const char* restrict s, const char* restrict target, ColorText* repl);
2974 char* colr_str_replace_cnt(const char* restrict s, const char* restrict target, const char* restrict repl, int count);
2975 char* colr_str_replace_ColorArg(const char* restrict s, const char* restrict target, ColorArg* repl);
2976 char* colr_str_replace_ColorResult(const char* restrict s, const char* restrict target, ColorResult* repl);
2977 char* colr_str_replace_ColorText(const char* restrict s, const char* restrict target, ColorText* repl);
2978 char* colr_str_replace_re(const char* restrict s, const char* restrict pattern, const char* restrict repl, int re_flags);
2979 char* colr_str_replace_re_all(const char* restrict s, const char* restrict pattern, const char* restrict repl, int re_flags);
2980 char* colr_str_replace_re_all_ColorArg(const char* restrict s, const char* restrict pattern, ColorArg* repl, int re_flags);
2981 char* colr_str_replace_re_all_ColorResult(const char* restrict s, const char* restrict pattern, ColorResult* repl, int re_flags);
2982 char* colr_str_replace_re_all_ColorText(const char* restrict s, const char* restrict pattern, ColorText* repl, int re_flags);
2983 char* colr_str_replace_re_ColorArg(const char* restrict s, const char* restrict pattern, ColorArg* repl, int re_flags);
2984 char* colr_str_replace_re_ColorResult(const char* restrict s, const char* restrict pattern, ColorResult* repl, int re_flags);
2985 char* colr_str_replace_re_ColorText(const char* restrict s, const char* restrict pattern, ColorText* repl, int re_flags);
2986 char* colr_str_replace_re_pat(const char* restrict s, regex_t* repattern, const char* restrict repl);
2987 char* colr_str_replace_re_pat_all(const char* restrict s, regex_t* repattern, const char* restrict repl);
2988 char* colr_str_replace_re_pat_all_ColorArg(const char* restrict s, regex_t* repattern, ColorArg* repl);
2989 char* colr_str_replace_re_pat_all_ColorResult(const char* restrict s, regex_t* repattern, ColorResult* repl);
2990 char* colr_str_replace_re_pat_all_ColorText(const char* restrict s, regex_t* repattern, ColorText* repl);
2991 char* colr_str_replace_re_pat_ColorArg(const char* restrict s, regex_t* repattern, ColorArg* repl);
2992 char* colr_str_replace_re_pat_ColorResult(const char* restrict s, regex_t* repattern, ColorResult* repl);
2993 char* colr_str_replace_re_pat_ColorText(const char* restrict s, regex_t* repattern, ColorText* repl);
2994 char* colr_str_replace_re_match(const char* restrict s, regmatch_t* match, const char* restrict repl);
2995 char* colr_str_replace_re_match_i(const char* restrict ref, char* target, regmatch_t* match, const char* restrict repl);
2996 char* colr_str_replace_re_match_ColorArg(const char* restrict s, regmatch_t* match, ColorArg* repl);
2997 char* colr_str_replace_re_match_ColorResult(const char* restrict s, regmatch_t* match, ColorResult* repl);
2998 char* colr_str_replace_re_match_ColorText(const char* restrict s, regmatch_t* match, ColorText* repl);
2999 char* colr_str_replace_re_matches(const char* restrict s, regmatch_t** matches, const char* restrict repl);
3000 char* colr_str_replace_re_matches_ColorArg(const char* restrict s, regmatch_t** matches, ColorArg* repl);
3001 char* colr_str_replace_re_matches_ColorResult(const char* restrict s, regmatch_t** matches, ColorResult* repl);
3002 char* colr_str_replace_re_matches_ColorText(const char* restrict s, regmatch_t** matches, ColorText* repl);
3003 
3004 char* colr_str_repr(const char* s);
3005 char* colr_str_rjust(const char* s, int width, const char padchar);
3006 bool colr_str_starts_with(const char* restrict s, const char* restrict prefix);
3007 char* colr_str_strip_codes(const char* s);
3008 char* colr_str_to_lower(const char* s);
3009 
3010 TermSize colr_term_size(void);
3011 struct winsize colr_win_size(void);
3012 struct winsize colr_win_size_env(void);
3013 void format_bgx(char* out, unsigned char num);
3014 void format_bg(char* out, BasicValue value);
3015 void format_bg_RGB(char* out, RGB rgb);
3016 void format_bg_RGB_term(char* out, RGB rgb);
3017 void format_fgx(char* out, unsigned char num);
3018 void format_fg(char* out, BasicValue value);
3019 void format_fg_RGB(char* out, RGB rgb);
3020 void format_fg_RGB_term(char* out, RGB rgb);
3021 void format_style(char* out, StyleValue style);
3032 typedef void (*RGB_fmter)(char* out, RGB rgb);
3035 typedef char* (*rainbow_creator)(const char* s, double freq, size_t offset, size_t spread);
3036 
3037 char* _rainbow(RGB_fmter fmter, const char* s, double freq, size_t offset, size_t spread);
3042 char* rainbow_fg(const char* s, double freq, size_t offset, size_t spread);
3043 char* rainbow_fg_term(const char* s, double freq, size_t offset, size_t spread);
3044 char* rainbow_bg(const char* s, double freq, size_t offset, size_t spread);
3045 char* rainbow_bg_term(const char* s, double freq, size_t offset, size_t spread);
3046 RGB rainbow_step(double freq, size_t offset);
3047 
3054 void _colr_free(void* p);
3055 
3060 bool _colr_is_last_arg(void* p);
3061 size_t _colr_ptr_length(void* p);
3062 char* _colr_ptr_repr(void* p);
3063 char* _colr_ptr_to_str(void* p);
3064 
3069 char* _colr_join(void* joinerp, ...);
3070 size_t _colr_join_size(void* joinerp, va_list args);
3071 
3076 size_t _colr_join_array_length(void* ps);
3077 size_t _colr_join_arrayn_size(void* joinerp, void* ps, size_t count);
3078 char* colr_join_array(void* joinerp, void* ps);
3079 char* colr_join_arrayn(void* joinerp, void* ps, size_t count);
3080 
3085 bool ArgType_eq(ArgType a, ArgType b);
3086 char* ArgType_repr(ArgType type);
3087 char* ArgType_to_str(ArgType type);
3088 
3093 void ColorArgs_array_free(ColorArg** ps);
3094 char* ColorArgs_array_repr(ColorArg** lst);
3095 ColorArg ColorArg_empty(void);
3096 bool ColorArg_eq(ColorArg a, ColorArg b);
3097 char* ColorArg_example(ColorArg carg, bool colorized);
3098 void ColorArg_free(ColorArg* p);
3101 ColorArg ColorArg_from_RGB(ArgType type, RGB value);
3102 ColorArg ColorArg_from_esc(const char* s);
3103 ColorArg ColorArg_from_str(ArgType type, const char* colorname);
3105 ColorArg ColorArg_from_value(ArgType type, ColorType colrtype, void* p);
3106 bool ColorArg_is_empty(ColorArg carg);
3107 bool ColorArg_is_invalid(ColorArg carg);
3108 bool ColorArg_is_ptr(void* p);
3109 bool ColorArg_is_valid(ColorArg carg);
3110 size_t ColorArg_length(ColorArg carg);
3111 char* ColorArg_repr(ColorArg carg);
3113 char* ColorArg_to_esc(ColorArg carg);
3114 bool ColorArg_to_esc_s(char* dest, ColorArg carg);
3115 
3116 ColorArg** ColorArgs_from_str(const char* s, bool unique);
3117 
3125 ColorJustify ColorJustify_new(ColorJustifyMethod method, int width, char padchar);
3126 char* ColorJustify_repr(ColorJustify cjust);
3128 
3136 void ColorResult_free(ColorResult* p);
3137 ColorResult ColorResult_from_str(const char* s);
3138 ColorResult* ColorResult_from_stra(const char* s);
3139 bool ColorResult_is_ptr(void* p);
3140 size_t ColorResult_length(ColorResult cres);
3141 ColorResult ColorResult_new(char* s);
3142 char* ColorResult_repr(ColorResult cres);
3144 char* ColorResult_to_str(ColorResult cres);
3145 
3152 void ColorText_free(ColorText* p);
3154 ColorText ColorText_from_values(char* text, ...);
3155 ColorText ColorText_from_valuesv(char* text, va_list args);
3156 bool ColorText_has_arg(ColorText ctext, ColorArg carg);
3157 bool ColorText_has_args(ColorText ctext);
3158 bool ColorText_is_empty(ColorText ctext);
3159 bool ColorText_is_ptr(void* p);
3160 size_t ColorText_length(ColorText ctext);
3161 char* ColorText_repr(ColorText ctext);
3163 void ColorText_set_values(ColorText* ctext, char* text, ...);
3165 char* ColorText_to_str(ColorText ctext);
3166 
3171 bool ColorType_eq(ColorType a, ColorType b);
3172 ColorType ColorType_from_str(const char* arg);
3173 bool ColorType_is_invalid(ColorType type);
3174 bool ColorType_is_valid(ColorType type);
3175 char* ColorType_repr(ColorType type);
3176 char* ColorType_to_str(ColorType type);
3177 
3184 char* ColorValue_example(ColorValue cval);
3185 ColorValue ColorValue_from_esc(const char* s);
3186 ColorValue ColorValue_from_str(const char* s);
3191 bool ColorValue_has_RGB(ColorValue cval, RGB rgb);
3192 bool ColorValue_is_empty(ColorValue cval);
3194 bool ColorValue_is_valid(ColorValue cval);
3195 size_t ColorValue_length(ArgType type, ColorValue cval);
3196 char* ColorValue_repr(ColorValue cval);
3197 char* ColorValue_to_esc(ArgType type, ColorValue cval);
3198 bool ColorValue_to_esc_s(char* dest, ArgType type, ColorValue cval);
3199 
3205 BasicValue BasicValue_from_esc(const char* s);
3206 BasicValue BasicValue_from_str(const char* arg);
3207 bool BasicValue_is_valid(BasicValue bval);
3209 int BasicValue_to_ansi(ArgType type, BasicValue bval);
3210 char* BasicValue_to_str(BasicValue bval);
3211 char* BasicValue_repr(BasicValue bval);
3218 int ExtendedValue_from_esc(const char* s);
3219 int ExtendedValue_from_hex(const char* hexstr);
3220 ExtendedValue ExtendedValue_from_hex_default(const char* hexstr, ExtendedValue default_value);
3222 int ExtendedValue_from_str(const char* arg);
3223 bool ExtendedValue_is_invalid(int eval);
3224 bool ExtendedValue_is_valid(int eval);
3225 char* ExtendedValue_repr(int eval);
3227 
3233 StyleValue StyleValue_from_esc(const char* s);
3234 StyleValue StyleValue_from_str(const char* arg);
3236 bool StyleValue_is_valid(StyleValue sval);
3237 char* StyleValue_repr(StyleValue sval);
3238 char* StyleValue_to_str(StyleValue sval);
3243 unsigned char RGB_average(RGB rgb);
3244 bool RGB_eq(RGB a, RGB b);
3247 int RGB_from_esc(const char* s, RGB* rgb);
3248 int RGB_from_hex(const char* hexstr, RGB* rgb);
3249 RGB RGB_from_hex_default(const char* hexstr, RGB default_value);
3250 int RGB_from_str(const char* arg, RGB* rgb);
3251 RGB RGB_grayscale(RGB rgb);
3252 RGB RGB_inverted(RGB rgb);
3253 RGB RGB_monochrome(RGB rgb);
3254 char* RGB_to_hex(RGB rgb);
3255 char* RGB_to_str(RGB rgb);
3256 RGB RGB_to_term_RGB(RGB rgb);
3257 char* RGB_repr(RGB rgb);
3258 
3262 char* TermSize_repr(TermSize ts);
3263 
3268 static_assert(
3269  (
3270  ((int)COLOR_INVALID == (int)TYPE_INVALID) &&
3271  ((int)TYPE_INVALID == (int)BASIC_INVALID) &&
3272  ((int)BASIC_INVALID == (int)EXT_INVALID) &&
3273  ((int)EXT_INVALID == (int)STYLE_INVALID)
3274  ),
3275  "Return/enum values for all color/style values should match."
3276 );
3277 static_assert(
3278  (
3279  COLORARG_MARKER &&
3282  ) &&
3286  ) &&
3287  (COLORTEXT_MARKER &&
3291  ) &&
3292  (COLORRESULT_MARKER &&
3297  )
3298  ),
3299  "Markers must be positive and unique for each struct in Colr!"
3300 );
3301 
3302 #endif // COLR_H
char padchar
The desired padding character, or 0 to use the default (`&#39; &#39;`).
Definition: colr.h:2767
char * ColorArg_repr(ColorArg carg)
Creates a string (char*) representation for a ColorArg.
Definition: colr.c:5494
bool ColorArg_is_valid(ColorArg carg)
Checks to see if a ColorArg holds a valid value.
Definition: colr.c:5460
char * ExtendedValue_repr(int eval)
Creates a string (char*) representation of a ExtendedValue.
Definition: colr.c:7894
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:4857
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:2228
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:2931
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:7791
char * StyleValue_to_str(StyleValue sval)
Create a human-friendly string (char*) representation for a StyleValue.
Definition: colr.c:8472
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:5327
char * BasicValue_to_str(BasicValue bval)
Create a human-friendly string (char*) representation for a BasicValue.
Definition: colr.c:7628
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:4067
bool ColorArg_eq(ColorArg a, ColorArg b)
Compares two ColorArg structs.
Definition: colr.c:5075
Holds a color type and it&#39;s value.
Definition: colr.h:2791
ColorArg * style
ColorArg for style value. Can be NULL.
Definition: colr.h:2849
char * ColorResult_repr(ColorResult cres)
Create a string representation for a ColorResult.
Definition: colr.c:6126
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:8146
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&#39;s string result.
Definition: colr.c:2711
#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:8495
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&#39;s string result.
Definition: colr.c:2684
bool colr_str_is_digits(const char *s)
Determines whether all characters in a string (char*) are digits.
Definition: colr.c:2183
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:2373
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&#39;s stri...
Definition: colr.c:3022
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:4724
char * colr_str_to_lower(const char *s)
Allocate a new lowercase version of a string (char*).
Definition: colr.c:4200
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:2760
ColorArg * fore
ColorArg for fore color. Can be NULL.
Definition: colr.h:2845
char * name
The known name of the color.
Definition: colr.h:2808
#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:7134
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:3032
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:853
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorJustifys.
Definition: colr.h:2761
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:7343
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:1472
ColrHash colr_str_hash(const char *s)
Hash a string using djb2.
Definition: colr.c:2114
ColorArg ColorArg_from_ExtendedValue(ArgType type, ExtendedValue value)
Explicit version of ColorArg_from_value that only handles ExtendedValues.
Definition: colr.c:5226
ColorText * ColorText_set_just(ColorText *ctext, ColorJustify cjust)
Set the ColorJustify method for a ColorText, and return the ColorText.
Definition: colr.c:6451
bool ArgType_eq(ArgType a, ArgType b)
Compares two ArgTypes.
Definition: colr.c:4982
bool ExtendedValue_is_invalid(int eval)
Determines whether an integer is an invalid ExtendedValue.
Definition: colr.c:7868
struct winsize colr_win_size(void)
Attempts to retrieve a winsize struct from an ioctl call.
Definition: colr.c:4292
bool ColorArg_is_empty(ColorArg carg)
Checks to see if a ColorArg is an empty placeholder.
Definition: colr.c:5420
char * ColorType_repr(ColorType type)
Creates a string (char*) representation of a ColorType.
Definition: colr.c:6699
char * ColorJustifyMethod_repr(ColorJustifyMethod meth)
Creates a string (char*) representation for a ColorJustifyMethod.
Definition: colr.c:5898
#define style(x)
Create a style suitable for use with the colr_cat(), colr_join(), Colr(), Colr_cat(), and Colr_join() macros.
Definition: colr.h:2430
bool BasicValue_is_invalid(BasicValue bval)
Determines whether a BasicValue is invalid.
Definition: colr.c:7496
ColorValue ColorValue_empty(void)
Create an "empty" ColorValue.
Definition: colr.c:6791
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&#39;s string result.
Definition: colr.c:3895
ColorValue ColorValue_from_esc(const char *s)
Convert an escape-code string (char*) into a ColorValue.
Definition: colr.c:6884
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:3540
bool colr_char_in_str(const char *s, const char c)
Determines if a character exists in the given string (char*).
Definition: colr.c:953
char * text
Text to colorize.
Definition: colr.h:2842
bool colr_check_marker(uint32_t marker, void *p)
Checks an unsigned int against the individual bytes behind a pointer&#39;s value.
Definition: colr.c:1120
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:2059
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&#39;...
Definition: colr.c:3509
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:4367
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:2985
ExtendedValue ext
ExtendedValue (256-colors) for the color.
Definition: colr.h:2810
Holds a string justification method, width, and padding character for ColorTexts. ...
Definition: colr.h:2759
BasicValue
Basic color values, with a few convenience values for extended colors.
Definition: colr.h:2535
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&#39;s string result.
Definition: colr.c:2881
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&#39;s string res...
Definition: colr.c:3662
RGB rgb
RGB (TrueColor) for the color.
Definition: colr.h:2812
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:1282
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:1686
void format_fgx(char *out, unsigned char num)
Create an escape code for an extended fore color.
Definition: colr.c:4399
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:6744
char * ColorArg_to_esc(ColorArg carg)
Converts a ColorArg into an escape code string (char*).
Definition: colr.c:5533
unsigned char blue
Blue value for a color.
Definition: colr.h:2624
bool colr_set_locale(void)
Sets the locale to (LC_ALL, "") if it hasn&#39;t already been set.
Definition: colr.c:1434
void ColorArg_free(ColorArg *p)
Free allocated memory for a ColorArg.
Definition: colr.c:5186
#define rgb(r, g, b)
Creates an anonymous RGB struct for use in function calls.
Definition: colr.h:2406
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:6265
ColorResult ColorResult_from_str(const char *s)
Allocates a copy of a string, and creates a ColorResult from it.
Definition: colr.c:6029
char colr_char_escape_char(const char c)
Returns the char needed to represent an escape sequence in C.
Definition: colr.c:924
char * colr_char_repr(char c)
Creates a string (char*) representation for a char.
Definition: colr.c:996
Holds info about a known color name, like it&#39;s ExtendedValue and it&#39;s RGB value.
Definition: colr.h:2806
char * _colr_join(void *joinerp,...)
Joins ColorArgs, ColorTexts, and strings (char*) into one long string separated by it&#39;s first argumen...
Definition: colr.c:4504
char * RGB_repr(RGB rgb)
Creates a string (char*) representation for an RGB value.
Definition: colr.c:8362
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:5763
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorResults.
Definition: colr.h:2828
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:3771
void format_fg_RGB_term(char *out, RGB rgb)
Create an escape code for a true color (rgb) fore color using an RGB struct&#39;s values, approximating 256-color values.
Definition: colr.c:4421
bool colr_char_is_code_end(const char c)
Determines if a character is suitable for an escape code ending.
Definition: colr.c:977
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:3714
Holds a known color name and it&#39;s ExtendedValue.
Definition: colr.h:2744
StyleValue StyleValue_from_str(const char *arg)
Convert a named argument to actual StyleValue enum value.
Definition: colr.c:8423
ArgType
Argument types (fore, back, style).
Definition: colr.h:2672
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:7057
int width
The desired width for the final string, or 0 to use colr_term_size().
Definition: colr.h:2765
ColorText * ColorText_to_ptr(ColorText ctext)
Copies a ColorText into allocated memory and returns the pointer.
Definition: colr.c:6513
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&#39;s string result.
Definition: colr.c:2655
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:5112
bool colr_supports_rgb_static(void)
Same as colr_supports_rgb(), but the environment is only checked on the first call.
Definition: colr.c:4253
struct winsize colr_win_size_env(void)
Get window/terminal size using the environment variables LINES, COLUMNS, or COLS. ...
Definition: colr.c:4317
char * ColorValue_repr(ColorValue cval)
Creates a string (char*) representation of a ColorValue.
Definition: colr.c:7211
int ExtendedValue_from_esc(const char *s)
Convert an escape-code string (char*) to an ExtendedValue.
Definition: colr.c:7685
ColorJustify ColorJustify_new(ColorJustifyMethod method, int width, char padchar)
Creates a ColorJustify.
Definition: colr.c:5846
#define ext(x)
Casts to ExtendedValue (unsigned char).
Definition: colr.h:2158
ExtendedValue ExtendedValue_from_RGB(RGB rgb)
Convert an RGB value into the closest matching ExtendedValue.
Definition: colr.c:7751
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:2331
void ColorResult_free(ColorResult *p)
Free allocated memory for a ColorResult and it&#39;s .result member.
Definition: colr.c:6012
ColorArg ColorArg_from_RGB(ArgType type, RGB value)
Explicit version of ColorArg_from_value that only handles RGB structs.
Definition: colr.c:5249
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:4119
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:1169
StyleValue StyleValue_from_esc(const char *s)
Convert an escape-code string (char*) to an actual StyleValue enum value.
Definition: colr.c:8401
void _colr_free(void *p)
Calls Colr *_free() functions for Colr objects, otherwise just calls free().
Definition: colr.c:4447
RGB RGB_from_BasicValue(BasicValue bval)
Return an RGB value from a known BasicValue.
Definition: colr.c:7971
char * ColorJustify_repr(ColorJustify cjust)
Creates a string (char*) representation for a ColorJustify.
Definition: colr.c:5868
bool colr_char_should_escape(const char c)
Determines if an ascii character has an escape sequence in C.
Definition: colr.c:1070
ColorText ColorText_empty(void)
Creates an "empty" ColorText with pointers set to NULL.
Definition: colr.c:6179
unsigned char red
Red value for a color.
Definition: colr.h:2620
bool ColorText_has_args(ColorText ctext)
Checks to see if a ColorText has any argument values set.
Definition: colr.c:6323
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:2632
uint32_t marker
The actual uint32_t marker value.
Definition: colr.h:2773
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:8598
bool ColorValue_is_invalid(ColorValue cval)
Checks to see if a ColorValue holds an invalid value.
Definition: colr.c:7108
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&#39;s s...
Definition: colr.c:3055
#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:2036
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:4928
Holds a known color name and it&#39;s BasicValue.
Definition: colr.h:2735
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:8306
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:3256
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:6380
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:4888
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:1157
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&#39;s string ...
Definition: colr.c:3184
ColorResult * ColorResult_from_stra(const char *s)
Allocates a copy of a string, and creates an allocated ColorResult from it.
Definition: colr.c:6046
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:5557
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:2422
ColorArg ColorArg_from_value(ArgType type, ColorType colrtype, void *p)
Used with the color_arg macro to dynamically create a ColorArg based on it&#39;s argument type...
Definition: colr.c:5395
bool ColorType_eq(ColorType a, ColorType b)
Compares two ColorTypes.
Definition: colr.c:6594
bool colr_supports_rgb(void)
Determine whether the current environment support RGB (True Colors).
Definition: colr.c:4236
ColorResult ColorResult_empty(void)
Creates a ColorResult with .result=NULL and .length=-1, with the appropriate struct marker...
Definition: colr.c:5978
unsigned char green
Green value for a color.
Definition: colr.h:2622
bool ColorResult_is_ptr(void *p)
Checks a void pointer to see if it contains a ColorResult struct.
Definition: colr.c:6071
ColorJustifyMethod method
The justification method, can be JUST_NONE.
Definition: colr.h:2763
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:1762
#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:4431
char * ColorValue_to_esc(ArgType type, ColorValue cval)
Converts a ColorValue into an escape code string (char*).
Definition: colr.c:7240
char * ColorValue_example(ColorValue cval)
Create a string (char*) representation of a ColorValue with a human-friendly type/name.
Definition: colr.c:6834
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:4625
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:838
size_t colr_str_code_count(const char *s)
Return the number of escape-codes in a string (char*).
Definition: colr.c:1714
ColorType ColorType_from_str(const char *arg)
Determine which type of color value is desired by name.
Definition: colr.c:6637
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:1248
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&#39;s string resu...
Definition: colr.c:3601
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:4462
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:7738
ArgType type
Fore, back, style, invalid.
Definition: colr.h:2820
RGB RGB_monochrome(RGB rgb)
Convert an RGB value into either black or white, depending on it&#39;s average grayscale value...
Definition: colr.c:8273
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&#39;s string result.
Definition: colr.c:3925
const ColorNameData colr_name_data[]
An array that holds a known color name, it&#39;s ExtendedValue, and it&#39;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&#39;s string result...
Definition: colr.c:3836
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&#39;s string result.
Definition: colr.c:2825
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:1613
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:4820
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorTexts.
Definition: colr.h:2840
bool ColorText_is_ptr(void *p)
Checks a void pointer to see if it contains a ColorText struct.
Definition: colr.c:6360
void ColorText_free_args(ColorText *p)
Frees the ColorArg members of a ColorText.
Definition: colr.c:6216
char * ColorResult_to_str(ColorResult cres)
Convert a ColorResult into a string (char*).
Definition: colr.c:6169
char * ArgType_repr(ArgType type)
Creates a string (char*) representation of a ArgType.
Definition: colr.c:4997
bool ColorArg_is_invalid(ColorArg carg)
Checks to see if a ColorArg holds an invalid value.
Definition: colr.c:5431
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:2822
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:8655
int ExtendedValue_from_BasicValue(BasicValue bval)
Convert a BasicValue into an ExtendedValue.
Definition: colr.c:7665
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:3362
ColorArg ColorArg_from_esc(const char *s)
Parse an escape-code string (char*) into a ColorArg.
Definition: colr.c:5278
void colr_str_lower(char *s)
Converts a string (char*) into lower case in place.
Definition: colr.c:2271
Breaks down Colr struct markers, such as COLORARG_MARKER, into individual bytes.
Definition: colr.h:2771
BasicValue BasicValue_from_esc(const char *s)
Convert an escape-code string (char*) to an actual BasicValue enum value.
Definition: colr.c:7449
ColorArg * back
ColorArg for back color. Can be NULL.
Definition: colr.h:2847
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:1373
char * TermSize_repr(TermSize ts)
Create a string (char*) representation for a TermSize.
Definition: colr.c:8562
char * result
A string (char*) result from one of the colr functions.
Definition: colr.h:2830
bool ColorJustify_eq(ColorJustify a, ColorJustify b)
Compares two ColorJustify structs.
Definition: colr.c:5808
char * colr_empty_str(void)
Allocates an empty string (char*).
Definition: colr.c:1143
bool StyleValue_is_valid(StyleValue sval)
Determines whether a StyleValue is valid.
Definition: colr.c:8457
bool colr_str_ends_with(const char *restrict s, const char *restrict suffix)
Determine if one string (char*) ends with another.
Definition: colr.c:1876
void ColorText_free(ColorText *p)
Frees a ColorText and it&#39;s ColorArgs.
Definition: colr.c:6199
bool ColorValue_eq(ColorValue a, ColorValue b)
Compares two ColorValue structs.
Definition: colr.c:6812
bool ExtendedValue_is_valid(int eval)
Determines whether an integer is a valid ExtendedValue.
Definition: colr.c:7879
ColorValue ColorValue_from_str(const char *s)
Create a ColorValue from a known color name, or RGB string (char*).
Definition: colr.c:6932
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:3570
ColorArg ColorArg_empty(void)
Create a ColorArg with ARGTYPE_NONE and ColorValue.type.TYPE_NONE.
Definition: colr.c:5056
size_t length
A length in bytes for the string result.
Definition: colr.h:2834
bool ColorArg_is_ptr(void *p)
Checks a void pointer to see if it contains a ColorArg struct.
Definition: colr.c:5444
ColorResult * Colr_fmt_str(const char *fmt,...)
Allocate and format a string like asprintf, but wrap it in an allocated ColorResult.
Definition: colr.c:813
bool colr_str_is_codes(const char *s)
Determines if a string (char*) is composed entirely of escape codes.
Definition: colr.c:2157
bool StyleValue_eq(StyleValue a, StyleValue b)
Compares two StyleValues.
Definition: colr.c:8385
ColorArg ColorArg_from_StyleValue(ArgType type, StyleValue value)
Explicit version of ColorArg_from_value that only handles StyleValues.
Definition: colr.c:5366
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:8708
ColorResult * ColorResult_Colr(ColorResult *cres,...)
Colorize a ColorResult, and return a new allocated ColorResult.
Definition: colr.c:5938
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:8684
bool ColorValue_is_valid(ColorValue cval)
Checks to see if a ColorValue holds a valid value.
Definition: colr.c:7119
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:8627
ColorJustify ColorJustify_empty(void)
Creates an "empty" ColorJustify, with JUST_NONE set.
Definition: colr.c:5788
#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:8255
int RGB_from_esc(const char *s, RGB *rgb)
Convert an escape-code string (char*) to an actual RGB value.
Definition: colr.c:8049
char * ExtendedValue_to_str(ExtendedValue eval)
Creates a human-friendly string (char*) from an ExtendedValue&#39;s actual value, suitable for use with E...
Definition: colr.c:7921
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:1546
#define COLOR_INVALID_RANGE
Possible error return value for RGB_from_str().
Definition: colr.h:325
Holds a known style name and it&#39;s StyleValue.
Definition: colr.h:2753
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:5475
Holds a terminal size, usually retrieved with colr_term_size().
Definition: colr.h:2855
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:2826
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&#39;s string result.
Definition: colr.c:2854
#define basic(x)
Casts to BasicValue.
Definition: colr.h:567
void format_bg(char *out, BasicValue value)
Create an escape code for a background color.
Definition: colr.c:4344
bool ColorText_is_empty(ColorText ctext)
Checks to see if a ColorText has no usable values.
Definition: colr.c:6344
TermSize colr_term_size(void)
Attempts to retrieve the row/column size of the terminal and returns a TermSize.
Definition: colr.c:4273
#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:7522
char * ColorArgs_array_repr(ColorArg **lst)
Creates a string representation for an array of ColorArg pointers.
Definition: colr.c:5639
int RGB_from_str(const char *arg, RGB *rgb)
Convert an RGB string (char*) into an RGB value.
Definition: colr.c:8190
bool ExtendedValue_eq(ExtendedValue a, ExtendedValue b)
Compares two ExtendedValues.
Definition: colr.c:7651
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:2134
char * colr_str_strip_codes(const char *s)
Strips escape codes from a string (char*), resulting in a new allocated string.
Definition: colr.c:4168
ColorArg * ColorArg_to_ptr(ColorArg carg)
Copies a ColorArg into memory and returns the pointer.
Definition: colr.c:5578
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:2590
bool colr_is_colr_ptr(void *p)
Determines whether a void pointer is a ColorArg, ColorResult, or ColorText pointer.
Definition: colr.c:1184
Holds an ArgType, and a ColorValue.
Definition: colr.h:2816
int ExtendedValue_from_hex(const char *hexstr)
Create an ExtendedValue from a hex string (char*).
Definition: colr.c:7713
bool ColorType_is_invalid(ColorType type)
Check to see if a ColorType value is considered invalid.
Definition: colr.c:6673
RGB RGB_from_ExtendedValue(ExtendedValue eval)
Return an RGB value from a known ExtendedValue.
Definition: colr.c:8030
ColorResult * ColorResult_to_ptr(ColorResult cres)
Allocate memory for a ColorResult, fill it, and return it.
Definition: colr.c:6145
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:3993
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&#39;s string result...
Definition: colr.c:3865
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&#39;s strin...
Definition: colr.c:3153
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:6088
bool ColorType_is_valid(ColorType type)
Check to see if a ColorType value is considered valid.
Definition: colr.c:6684
int BasicValue_to_ansi(ArgType type, BasicValue bval)
Converts a fore/back BasicValue to the actual ansi code number.
Definition: colr.c:7603
Holds a string of text, and optional fore, back, and style ColorArgs.
Definition: colr.h:2838
bool RGB_eq(RGB a, RGB b)
Compare two RGB structs.
Definition: colr.c:7951
unsigned char RGB_average(RGB rgb)
Return the average for an RGB value.
Definition: colr.c:7937
Container for RGB values.
Definition: colr.h:2614
void format_bgx(char *out, unsigned char num)
Create an escape code for an extended background color.
Definition: colr.c:4355
ColorType
Color/Style code types. Used with ColorType_from_str() and ColorValue.
Definition: colr.h:2704
#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:6533
char * RGB_to_hex(RGB rgb)
Converts an RGB value into a hex string (char*).
Definition: colr.c:8288
int RGB_from_hex(const char *hexstr, RGB *rgb)
Convert a hex color into an RGB value.
Definition: colr.c:8088
bool ColorJustify_is_empty(ColorJustify cjust)
Checks to see if a ColorJustify is "empty".
Definition: colr.c:5828
ColorArg ColorArg_from_BasicValue(ArgType type, BasicValue value)
Explicit version of ColorArg_from_value that only handles BasicValues.
Definition: colr.c:5203
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:4683
void ColorArgs_array_free(ColorArg **ps)
Free an allocated array of ColorArgs, including the array itself.
Definition: colr.c:5608
RGB RGB_grayscale(RGB rgb)
Return a grayscale version of an RGB value.
Definition: colr.c:8240
unsigned char ExtendedValue
Convenience typedef for clarity when dealing with extended (256) colors.
Definition: colr.h:2611
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&#39;s str...
Definition: colr.c:3087
char * ArgType_to_str(ArgType type)
Creates a human-friendly string (char*) from an ArgType.
Definition: colr.c:5027
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:6412
bool ColorValue_has_StyleValue(ColorValue cval, StyleValue sval)
Checks to see if a ColorValue has a StyleValue set.
Definition: colr.c:7070
RGB RGB_to_term_RGB(RGB rgb)
Convert an RGB value into it&#39;s nearest terminal-friendly RGB value.
Definition: colr.c:8321
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&#39;s string r...
Definition: colr.c:3120
bool ColorResult_eq(ColorResult a, ColorResult b)
Compares two ColorResults.
Definition: colr.c:5998
bool ColorValue_has_BasicValue(ColorValue cval, BasicValue bval)
Checks to see if a ColorValue has a BasicValue set.
Definition: colr.c:7044
bool StyleValue_is_invalid(StyleValue sval)
Determines whether a StyleValue is invalid.
Definition: colr.c:8446
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:2459
BasicValue BasicValue_from_str(const char *arg)
Convert named argument to an actual BasicValue enum value.
Definition: colr.c:7473
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:6239
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:6467
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:8778
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&#39;s string result.
Definition: colr.c:3954
ColorJustify just
ColorJustify info, set to JUST_NONE by default.
Definition: colr.h:2851
bool BasicValue_is_valid(BasicValue bval)
Determines whether a BasicValue is valid.
Definition: colr.c:7507
void format_fg_RGB(char *out, RGB rgb)
Create an escape code for a true color (rgb) fore color using an RGB struct&#39;s values.
Definition: colr.c:4410
uint32_t marker
A marker used to inspect void pointers and determine if they are ColorArgs.
Definition: colr.h:2818
bool ColorValue_has_RGB(ColorValue cval, RGB rgb)
Checks to see if a ColorValue has a RGB value set.
Definition: colr.c:7083
bool ColorValue_is_empty(ColorValue cval)
Checks to see if a ColorValue is an empty placeholder.
Definition: colr.c:7097
StyleValue
Style values.
Definition: colr.h:2628
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&#39;s string result...
Definition: colr.c:3806
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:1650
void format_bg_RGB_term(char *out, RGB rgb)
Create an escape code for a true color (rgb) fore color using an RGB struct&#39;s values, approximating 256-color values.
Definition: colr.c:4378
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&#39;s argument type...
Definition: colr.c:6998
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:1846
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:2298
ColorResult ColorResult_new(char *s)
Initialize a new ColorResult with an allocated string (char*).
Definition: colr.c:6105
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:4957
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:3440
void colr_printf_register(void)
Registers COLR_FMT_CHAR to handle Colr objects in the printf-family functions.
Definition: colr.c:1417
bool BasicValue_eq(BasicValue a, BasicValue b)
Compares two BasicValues.
Definition: colr.c:7433
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:2517
void colr_str_array_free(char **ps)
Free an allocated array of strings, including the array itself.
Definition: colr.c:1505
void format_fg(char *out, BasicValue value)
Create an escape code for a fore color.
Definition: colr.c:4388
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&#39;s string r...
Definition: colr.c:3632
ColorJustifyMethod
Justification style for ColorTexts.
Definition: colr.h:2688
bool ColorText_has_arg(ColorText ctext, ColorArg carg)
Checks to see if a ColorText has a certain ColorArg value set.
Definition: colr.c:6307
char ** colr_str_get_codes(const char *s, bool unique)
Get an array of escape-codes from a string (char*).
Definition: colr.c:1939