ColrC  0.4.0
An easy to use C library for linux terminal colors/escape-codes.
colr.h (0.4.0)
Go to the documentation of this file.
1 
34 #ifndef COLR_H
35 #define COLR_H
36 
38 #define COLR_VERSION "0.4.0"
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 
706 
734 #define ColorText_center(text, justwidth, ...) ColorText_set_just( \
735  Colr(text, __VA_ARGS__), \
736  (ColorJustify){.method=JUST_CENTER, .width=justwidth, .padchar=' '} \
737  )
738 
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} \
769  )
770 
796 #define ColorText_ljust(text, justwidth, ...) ColorText_set_just( \
797  Colr(text, __VA_ARGS__), \
798  (ColorJustify){.method=JUST_LEFT, .width=justwidth, .padchar=' '} \
799  )
800 
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} \
830  )
831 
859 #define ColorText_rjust(text, justwidth, ...) ColorText_set_just( \
860  Colr(text, __VA_ARGS__), \
861  (ColorJustify){.method=JUST_RIGHT, .width=justwidth, .padchar=' '} \
862  )
863 
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} \
893  )
894 
912 #define ColorValue_has(cval, val) \
913  _Generic( \
914  (val), \
915  BasicValue: ColorValue_has_BasicValue, \
916  ExtendedValue: ColorValue_has_ExtendedValue, \
917  StyleValue: ColorValue_has_StyleValue, \
918  RGB: ColorValue_has_RGB \
919  )(cval, val)
920 
940 #define Colr(text, ...) ColorText_to_ptr(ColorText_from_values(text, __VA_ARGS__, _ColrLastArg))
941 
977 #define Colra(text, ...) ColorText_from_values(text, __VA_ARGS__, _ColrLastArg)
978 
994 #define Colr_cat(...) ColorResult_to_ptr(ColorResult_new(colr_cat(__VA_ARGS__)))
995 
1007 #define Colr_center(x, width) \
1008  _Generic( \
1009  (x), \
1010  char*: Colr_center_char, \
1011  const char*: Colr_center_char, \
1012  ColorResult*: Colr_center_char, \
1013  ColorText*: Colr_center_char \
1014  )(x, width, ' ')
1015 
1047 #define Colr_fmt(fmt, value, ...) \
1048  ColorResult_Colr( \
1049  Colr_fmt_str(fmt, value), \
1050  __VA_ARGS__, \
1051  _ColrLastArg \
1052  )
1053 
1082 #define Colr_join(joiner, ...) ColrResult(colr_join(joiner, __VA_ARGS__))
1083 
1095 #define Colr_ljust(x, width) \
1096  _Generic( \
1097  (x), \
1098  char*: Colr_ljust_char, \
1099  const char*: Colr_ljust_char, \
1100  ColorResult*: Colr_ljust_char, \
1101  ColorText*: Colr_ljust_char \
1102  )(x, width, ' ')
1103 
1115 #define Colr_rjust(x, width) \
1116  _Generic( \
1117  (x), \
1118  char*: Colr_rjust_char, \
1119  const char*: Colr_rjust_char, \
1120  ColorResult*: Colr_rjust_char, \
1121  ColorText*: Colr_rjust_char \
1122  )(x, width, ' ')
1123 
1134 #define ColrResult(s) ColorResult_to_ptr(ColorResult_new(s))
1135 
1159 #define ColrColorResult(cres, ...) ColorResult_Colr(cres, __VA_ARGS__, _ColrLastArg)
1160 
1180 #define colr(text, ...) colr_cat(Colr(text, __VA_ARGS__))
1181 
1222 #define colr_cat(...) _colr_join("", __VA_ARGS__, _ColrLastArg)
1223 
1239 #define colr_center(x, width) colr_center_char(x, width, ' ')
1240 
1257 #define colr_center_char(x, width, padchar) ColorResult_rip_str( \
1258  _Generic( \
1259  (x), \
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))
1265 
1273 #define colr_alloc_len(x) \
1274  _Generic( \
1275  (x), \
1276  RGB: CODE_RGB_LEN, \
1277  BasicValue: CODE_LEN, \
1278  ExtendedValue: CODEX_LEN, \
1279  StyleValue: STYLE_LEN \
1280  )
1281 
1292 #define colr_eq(a, b) \
1293  _Generic( \
1294  (a), \
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, \
1303  RGB: RGB_eq, \
1304  StyleValue: StyleValue_eq \
1305  )(a, b)
1306 
1321 #define colr_example(x) \
1322  _Generic( \
1323  (x), \
1324  ColorArg: ColorArg_example, \
1325  ColorValue: ColorValue_example \
1326  )(x)
1327 
1335 #define colr_fprint(file, ...) \
1336  do { \
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); \
1341  } while (0)
1342 
1356 #define colr_free(x) \
1357  _Generic( \
1358  (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 \
1365  )(x)
1366 
1372 #define colr_is_empty(x) \
1373  _Generic( \
1374  (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 \
1381  )(x)
1382 
1389 #define colr_is_invalid(x) \
1390  _Generic( \
1391  (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 \
1398  )(x)
1399 
1405 #define colr_is_valid(x) \
1406  _Generic( \
1407  (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 \
1414  )(x)
1415 
1424 #define colr_is_valid_mblen(x) ((x) && ((x) != (size_t)-1) && ((x) != (size_t)-2))
1425 
1435 #define colr_istr_either(s1, s2, s3) \
1436  ( \
1437  ((s1) && (s2) && (s3)) ? \
1438  (colr_istr_eq((s1), (s2)) || colr_istr_eq((s1), (s3))) : \
1439  false \
1440  )
1441 
1450 #define colr_istr_eq(s1, s2) \
1451  ( \
1452  ((s1) && (s2)) ? \
1453  !strcasecmp((s1), (s2)) : \
1454  false \
1455  )
1456 
1485 #define colr_join(joiner, ...) _colr_join(joiner, __VA_ARGS__, _ColrLastArg)
1486 
1496 #define colr_length(x) \
1497  _Generic( \
1498  (x), \
1499  ColorArg: ColorArg_length, \
1500  ColorResult: ColorResult_length, \
1501  ColorText: ColorText_length, \
1502  ColorValue: ColorValue_length, \
1503  void*: _colr_ptr_length \
1504  )(x)
1505 
1521 #define colr_ljust(x, width) colr_ljust_char(x, width, ' ')
1522 
1539 #define colr_ljust_char(x, width, padchar) ColorResult_rip_str( \
1540  _Generic( \
1541  (x), \
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))
1547 
1563 #define colr_rjust(x, width) colr_rjust_char(x, width, ' ')
1564 
1581 #define colr_rjust_char(x, width, padchar) ColorResult_rip_str( \
1582  _Generic( \
1583  (x), \
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))
1589 
1590 #ifndef DOXYGEN_SKIP
1591 // These are just some stringification macros.
1592 // The first one is the typical stringify macro.
1593 #define _colr_macro_str(x) #x
1594 #define colr_macro_str(x) _colr_macro_str(x)
1595 // This one stringifies the entire argument list as one string.
1596 #define _colr_macro_str_all(...) #__VA_ARGS__
1597 #define colr_macro_str_all(...) _colr_macro_str_all(__VA_ARGS__)
1598 // This is the standard concatenation macro.
1599 #define _colr_macro_concat(a, b) a ## b
1600 #define colr_macro_concat(a, b) _colr_macro_concat(a, b)
1601 #endif
1602 
1609 #define colr_max(a, b) (a > b ? a : b)
1610 
1617 #define colr_print(...) \
1618  do { \
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); \
1623  } while (0)
1624 
1625 
1626 #ifdef COLR_GNU
1627 
1641 #define colr_printf_macro(func, ...) \
1642  __extension__({ \
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"); \
1652  _c_p_m_ret; \
1653  })
1654 
1672 #define colr_printf(...) colr_printf_macro(printf, __VA_ARGS__)
1673 
1689 #define colr_fprintf(...) colr_printf_macro(fprintf, __VA_ARGS__)
1690 
1706 #define colr_sprintf(...) colr_printf_macro(sprintf, __VA_ARGS__)
1707 
1723 #define colr_snprintf(...) colr_printf_macro(snprintf, __VA_ARGS__)
1724 
1740 #define colr_asprintf(...) colr_printf_macro(asprintf, __VA_ARGS__)
1741 #endif // COLR_GNU
1742 
1750 #define colr_puts(...) \
1751  do { \
1752  char* _c_p_s = colr_cat(__VA_ARGS__); \
1753  if (!_c_p_s) break; \
1754  puts(_c_p_s); \
1755  colr_free(_c_p_s); \
1756  } while (0)
1757 
1835 #define colr_replace(s, target, repl) \
1836  _Generic( \
1837  (repl), \
1838  char*: _Generic( \
1839  (target), \
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 \
1844  ), \
1845  ColorArg*: _Generic( \
1846  (target), \
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 \
1851  ), \
1852  ColorResult*: _Generic( \
1853  (target), \
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 \
1858  ), \
1859  ColorText*: _Generic( \
1860  (target), \
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 \
1865  ) \
1866  )(s, target, repl)
1867 
1937 #define colr_replace_all(s, target, repl) \
1938  _Generic( \
1939  (repl), \
1940  char*: _Generic( \
1941  (target), \
1942  char* : colr_str_replace_all, \
1943  regex_t* : colr_str_replace_re_pat_all, \
1944  regmatch_t** : colr_str_replace_re_matches \
1945  ), \
1946  ColorArg*: _Generic( \
1947  (target), \
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 \
1951  ), \
1952  ColorResult*: _Generic( \
1953  (target), \
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 \
1957  ), \
1958  ColorText*: _Generic( \
1959  (target), \
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 \
1963  ) \
1964  )(s, target, repl)
1965 
2063 #define colr_replace_re(s, target, repl, flags) \
2064  _Generic( \
2065  (repl), \
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)
2071 
2168 #define colr_replace_re_all(s, target, repl, flags) \
2169  _Generic( \
2170  (repl), \
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)
2176 
2212 #define colr_repr(x) \
2213  _Generic( \
2214  (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, \
2226  RGB: RGB_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 \
2234  )(x)
2235 
2236 
2245 #define colr_str_eq(s1, s2) ( \
2246  ((s1) && (s2)) ? !strcmp((s1), (s2)) : false \
2247  )
2248 
2258 #define colr_str_either(s1, s2, s3) (colr_str_eq(s1, s2) || colr_str_eq(s1, s3))
2259 
2273 #define colr_to_str(x) \
2274  _Generic( \
2275  (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, \
2284  RGB: RGB_to_str, \
2285  void*: _colr_ptr_to_str \
2286  )(x)
2287 
2288 #ifndef DOXYGEN_SKIP
2289 #if defined(DEBUG) && defined(DBUG_H) && defined(dbug)
2290 
2304  #define dbug_repr(lbl, x) \
2305  do { \
2306  char* _dbug_repr_s = colr_repr(x); \
2307  dbug("%s: %s\n", lbl, _dbug_repr_s); \
2308  free(_dbug_repr_s); \
2309  } while(0)
2310 #else
2311  #if !defined(dbug)
2312 
2319  #define dbug(...) ((void)0)
2320  #endif
2321 
2329  #define dbug_repr(lbl, x) ((void)0)
2330 #endif
2331 #endif // DOXYGEN_SKIP
2332 
2348 #define ext(x) ((ExtendedValue)x)
2349 
2361 #define ext_hex(s) ext_hex_or(s, ext(0))
2362 
2379 #define ext_hex_or(s, default_value) ExtendedValue_from_hex_default(s, default_value)
2380 
2396 #define ext_rgb(r, g, b) ExtendedValue_from_RGB((RGB){.red=r, .green=g, .blue=b})
2397 
2410 #define ext_RGB(rgbval) ExtendedValue_from_RGB(rgbval)
2411 
2446 #define fore(x) ColorArg_to_ptr(fore_arg(x))
2447 
2465 #define fore_arg(x) \
2466  _Generic( \
2467  (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 \
2473  )(FORE, x)
2474 
2487 #define fore_str(x) ColorArg_to_esc(fore_arg(x))
2488 
2489 #ifdef COLR_GNU
2490 
2527 #define fore_str_static(x) \
2528  __extension__ ({ \
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); \
2534  _fss_codes; \
2535  })
2536  /* A Variable Length Array will not work here.
2537  The space for `_fss_codes` would be deallocated before this statement
2538  expression returns. Using `alloca` ensures that it will live at least
2539  as long as the calling function.
2540  See:
2541  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_002a_005f_005fbuiltin_005falloca
2542  */
2543 #endif // COLR_GNU
2544 
2545 
2556 #define hex(s) hex_or(s, rgb(0, 0, 0))
2557 
2569 #define hex_or(s, default_rgb) RGB_from_hex_default(s, default_rgb)
2570 
2584 #define if_not_asprintf(...) if (asprintf(__VA_ARGS__) < 1)
2585 
2596 #define rgb(r, g, b) ((RGB){.red=r, .green=g, .blue=b})
2597 
2620 #define style(x) ColorArg_to_ptr(style_arg(x))
2621 
2634 #define style_arg(x) \
2635  _Generic( \
2636  (x), \
2637  char* : ColorArg_from_str, \
2638  StyleValue: ColorArg_from_StyleValue \
2639  )(STYLE, x)
2640 
2653 #define style_str(x) ColorArg_to_esc(style_arg(x))
2654 
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" \
2705  )))))))))))))
2706 
2716 #define while_colr_va_arg(ap, vartype, x) while (x = va_arg(ap, vartype), !_colr_is_last_arg(x))
2717 
2718 
2726 typedef enum BasicValue {
2727  BASIC_INVALID_RANGE = COLOR_INVALID_RANGE,
2728  BASIC_INVALID = COLOR_INVALID,
2729  BASIC_NONE = -1,
2730  // The actual escape code value for fore colors is BasicValue + 30 == (30-39).
2731  // The actual escape code value for back colors is BasicValue + 40 == (40-49).
2732  BLACK = 0,
2733  RED = 1,
2734  GREEN = 2,
2735  YELLOW = 3,
2736  BLUE = 4,
2737  MAGENTA = 5,
2738  CYAN = 6,
2739  WHITE = 7,
2740  UNUSED = 8,
2741  RESET = 9,
2742  // The following colors are basic "bright" colors.
2743  // The actual escape code value for fore colors is BasicValue + 80 == (90-97).
2744  // The actual escape code value for back colors is BasicValue + 90 == (100-107).
2745  LIGHTBLACK = 10,
2746  LIGHTRED = 11,
2747  LIGHTGREEN = 12,
2748  LIGHTYELLOW = 13,
2749  LIGHTBLUE = 14,
2750  LIGHTMAGENTA = 15,
2751  LIGHTCYAN = 16,
2752  LIGHTWHITE = 17,
2753 } BasicValue;
2754 
2755 #ifndef DOXYGEN_SKIP
2756 // This makes enum values more friendly to _Generic, by explicitly casting
2757 // from `int` to the enum type.
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)
2778 
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
2800 
2802 typedef unsigned char ExtendedValue;
2803 
2805 typedef struct RGB {
2810  unsigned char red;
2813  unsigned char green;
2815  unsigned char blue;
2816 } RGB;
2817 
2819 typedef enum StyleValue {
2820  STYLE_INVALID_RANGE = COLOR_INVALID_RANGE,
2821  STYLE_INVALID = COLOR_INVALID,
2822  STYLE_NONE = -1,
2823  RESET_ALL = 0,
2824  BRIGHT = 1,
2825  DIM = 2,
2826  ITALIC = 3,
2827  UNDERLINE = 4,
2828  FLASH = 5, // DOS has a "rapid flash" for 6 also.
2829  HIGHLIGHT = 7,
2830  STRIKETHRU = 9,
2831  NORMAL = 22,
2832  // May not be supported.
2833  FRAME = 51,
2834  ENCIRCLE = 52,
2835  OVERLINE = 53, // Supported in Konsole.
2836 } StyleValue;
2837 
2839 #define STYLE_MAX_VALUE ((StyleValue)OVERLINE)
2840 #define STYLE_MIN_VALUE ((StyleValue)STYLE_INVALID_RANGE)
2842 
2843 #ifndef DOXYGEN_SKIP
2844 // This makes enum values more friendly to _Generic, by explicitly casting
2845 // from `int` to the enum type.
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
2862 
2864 typedef enum ArgType {
2865  ARGTYPE_NONE = -1,
2866  FORE = 0,
2867  BACK = 1,
2868  STYLE = 2,
2869 } ArgType;
2870 
2871 #ifndef DOXYGEN_SKIP
2872 // This makes enum values more friendly to _Generic, by explicitly casting
2873 // from `int` to the enum type.
2874 #define ARGTYPE_NONE ((ArgType)ARGTYPE_NONE)
2875 #define FORE ((ArgType)FORE)
2876 #define BACK ((ArgType)BACK)
2877 #define STYLE ((ArgType)STYLE)
2878 #endif
2879 typedef enum ColorJustifyMethod {
2881  JUST_NONE = -1,
2882  JUST_LEFT = 0,
2883  JUST_RIGHT = 1,
2884  JUST_CENTER = 2,
2886 
2887 #ifndef DOXYGEN_SKIP
2888 // This makes enum values more friendly to _Generic, by explicitly casting
2889 // from `int` to the enum type.
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)
2894 #endif
2895 typedef enum ColorType {
2897  TYPE_NONE = -6,
2898  TYPE_INVALID_STYLE = -5,
2899  TYPE_INVALID_RGB_RANGE = -4,
2900  TYPE_INVALID_EXT_RANGE = COLOR_INVALID_RANGE,
2901  TYPE_INVALID = COLOR_INVALID,
2902  TYPE_BASIC = 0,
2903  TYPE_EXTENDED = 1,
2904  TYPE_RGB = 2,
2905  TYPE_STYLE = 3,
2906 } ColorType;
2907 
2908 #ifndef DOXYGEN_SKIP
2909 // This makes enum values more friendly to _Generic, by explicitly casting
2910 // from `int` to the enum type.
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)
2920 #endif
2921 
2927 typedef struct BasicInfo {
2928  char* name;
2929  BasicValue value;
2930 } BasicInfo;
2936 typedef struct ExtendedInfo {
2937  char* name;
2938  ExtendedValue value;
2939 } ExtendedInfo;
2945 typedef struct StyleInfo {
2946  char* name;
2947  StyleValue value;
2948 } StyleInfo;
2949 
2951 typedef struct ColorJustify {
2953  uint32_t marker;
2957  int width;
2959  char padchar;
2960 } ColorJustify;
2961 
2963 typedef union ColorStructMarker {
2965  uint32_t marker;
2967  struct {
2968  uint8_t b1;
2969  uint8_t b2;
2970  uint8_t b3;
2971  uint8_t b4;
2972  } bytes;
2983 typedef struct ColorValue {
2984  ColorType type;
2985  BasicValue basic;
2987  RGB rgb;
2988  StyleValue style;
2989 } ColorValue;
2990 
2998 typedef struct ColorNameData {
3000  char* name;
3005 } ColorNameData;
3006 
3008 typedef struct ColorArg {
3010  uint32_t marker;
3015 } ColorArg;
3016 
3018 typedef struct ColorResult {
3020  uint32_t marker;
3022  char* result;
3026  size_t length;
3027 } ColorResult;
3028 
3030 typedef struct ColorText {
3032  uint32_t marker;
3034  char* text;
3035  // Pointers are used for compatibility with the fore(), back(), and style() macros.
3044 } ColorText;
3045 
3047 typedef struct TermSize {
3048  unsigned short rows;
3049  unsigned short columns;
3050 } TermSize;
3051 
3052 #ifndef DOXYGEN_SKIP
3053 extern const BasicInfo basic_names[];
3056 extern const size_t basic_names_len;
3058 extern const ExtendedInfo extended_names[];
3060 extern const size_t extended_names_len;
3062 extern const StyleInfo style_names[];
3064 extern const size_t style_names_len;
3065 
3067 extern const RGB ext2rgb_map[];
3069 extern const size_t ext2rgb_map_len;
3070 
3072 extern const ColorNameData colr_name_data[];
3074 extern const size_t colr_name_data_len;
3075 
3077 typedef unsigned long ColrHash;
3079 #define COLR_HASH_FMT "%lu"
3080 
3082 struct _ColrLastArg_s {
3083  uint32_t marker;
3084  unsigned short value;
3085 };
3086 
3087 static const struct _ColrLastArg_s _ColrLastArgValue = {
3088  .marker=COLORLASTARG_MARKER,
3089  .value=1337
3090 };
3091 // clang linter says it's unused, but it's used in the _colr* functions, and others.
3092 #pragma clang diagnostic ignored "-Wunused-const-variable"
3093 static const struct _ColrLastArg_s* const _ColrLastArg = &_ColrLastArgValue;
3094 #endif // DOXYGEN_SKIP
3095 
3100 #ifdef DOXYGEN_SKIP
3101  // This is strictly for Doxygen, because it doesn't know what __attribute__ is,
3102  // even if you tell it with `PREDEFINED = __attribute__(x)=`
3103  ColorResult* Colr_fmt_str(const char* fmt, ...);
3104 #else
3105  ColorResult* Colr_fmt_str(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
3106 #endif
3107 
3108 ColorResult* Colr_center_char(void* x, int width, char padchar);
3109 ColorResult* Colr_ljust_char(void* x, int width, char padchar);
3110 ColorResult* Colr_rjust_char(void* x, int width, char padchar);
3111 
3112 regmatch_t* colr_alloc_regmatch(regmatch_t match);
3113 void colr_append_reset(char* s);
3114 
3115 char colr_char_escape_char(const char c);
3116 bool colr_char_in_str(const char* s, const char c);
3117 bool colr_char_is_code_end(const char c);
3118 char* colr_char_repr(char c);
3119 bool colr_char_should_escape(const char c);
3120 
3121 bool colr_check_marker(uint32_t marker, void* p);
3122 char* colr_empty_str(void);
3123 void colr_free_argsv(va_list args);
3124 void colr_free_re_matches(regmatch_t** matches);
3125 bool colr_is_colr_ptr(void* p);
3126 size_t colr_mb_len(const char* s, size_t length);
3127 
3128 #ifdef COLR_GNU
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);
3131 // The contructor attribute isn't used because not everyone needs this.
3132 void colr_printf_register(void); // __attribute__((constructor))
3133 #endif
3134 
3135 regmatch_t** colr_re_matches(const char* s, regex_t* repattern);
3136 bool colr_set_locale(void);
3137 bool colr_supports_rgb(void);
3138 bool colr_supports_rgb_static(void);
3139 
3140 bool colr_str_array_contains(char** lst, const char* s);
3141 void colr_str_array_free(char** ps);
3142 size_t colr_str_char_count(const char* s, const char c);
3143 size_t colr_str_char_lcount(const char* s, const char c);
3144 size_t colr_str_chars_lcount(const char* restrict s, const char* restrict chars);
3145 char* colr_str_center(const char* s, int width, const char padchar);
3146 size_t colr_str_code_count(const char* s);
3147 size_t colr_str_code_len(const char* s);
3148 char* colr_str_copy(char* restrict dest, const char* restrict src, size_t length);
3149 bool colr_str_ends_with(const char* restrict s, const char* restrict suffix);
3150 char** colr_str_get_codes(const char* s, bool unique);
3151 bool colr_str_has_ColorArg(const char* s, ColorArg* carg);
3152 bool colr_str_has_codes(const char* s);
3153 ColrHash colr_str_hash(const char* s);
3154 bool colr_str_is_all(const char* s, const char c);
3155 bool colr_str_is_codes(const char* s);
3156 bool colr_str_is_digits(const char* s);
3157 bool colr_str_is_empty(const char* s);
3158 char* colr_str_ljust(const char* s, int width, const char padchar);
3159 void colr_str_lower(char* s);
3160 size_t colr_str_lstrip(char* restrict dest, const char* restrict s, size_t length, const char c);
3161 char* colr_str_lstrip_char(const char* s, const char c);
3162 char* colr_str_lstrip_chars(const char* restrict s, const char* restrict chars);
3163 size_t colr_str_mb_len(const char* s);
3164 size_t colr_str_noncode_len(const char* s);
3165 
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);
3168 char* colr_str_replace_all_ColorArg(const char* restrict s, const char* restrict target, ColorArg* repl);
3169 char* colr_str_replace_all_ColorResult(const char* restrict s, const char* restrict target, ColorResult* repl);
3170 char* colr_str_replace_all_ColorText(const char* restrict s, const char* restrict target, ColorText* repl);
3171 char* colr_str_replace_cnt(const char* restrict s, const char* restrict target, const char* restrict repl, int count);
3172 char* colr_str_replace_ColorArg(const char* restrict s, const char* restrict target, ColorArg* repl);
3173 char* colr_str_replace_ColorResult(const char* restrict s, const char* restrict target, ColorResult* repl);
3174 char* colr_str_replace_ColorText(const char* restrict s, const char* restrict target, ColorText* repl);
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);
3177 char* colr_str_replace_re_all_ColorArg(const char* restrict s, const char* restrict pattern, ColorArg* repl, int re_flags);
3178 char* colr_str_replace_re_all_ColorResult(const char* restrict s, const char* restrict pattern, ColorResult* repl, int re_flags);
3179 char* colr_str_replace_re_all_ColorText(const char* restrict s, const char* restrict pattern, ColorText* repl, int re_flags);
3180 char* colr_str_replace_re_ColorArg(const char* restrict s, const char* restrict pattern, ColorArg* repl, int re_flags);
3181 char* colr_str_replace_re_ColorResult(const char* restrict s, const char* restrict pattern, ColorResult* repl, int re_flags);
3182 char* colr_str_replace_re_ColorText(const char* restrict s, const char* restrict pattern, ColorText* repl, int re_flags);
3183 char* colr_str_replace_re_pat(const char* restrict s, regex_t* repattern, const char* restrict repl);
3184 char* colr_str_replace_re_pat_all(const char* restrict s, regex_t* repattern, const char* restrict repl);
3185 char* colr_str_replace_re_pat_all_ColorArg(const char* restrict s, regex_t* repattern, ColorArg* repl);
3186 char* colr_str_replace_re_pat_all_ColorResult(const char* restrict s, regex_t* repattern, ColorResult* repl);
3187 char* colr_str_replace_re_pat_all_ColorText(const char* restrict s, regex_t* repattern, ColorText* repl);
3188 char* colr_str_replace_re_pat_ColorArg(const char* restrict s, regex_t* repattern, ColorArg* repl);
3189 char* colr_str_replace_re_pat_ColorResult(const char* restrict s, regex_t* repattern, ColorResult* repl);
3190 char* colr_str_replace_re_pat_ColorText(const char* restrict s, regex_t* repattern, ColorText* repl);
3191 char* colr_str_replace_re_match(const char* restrict s, regmatch_t* match, const char* restrict repl);
3192 char* colr_str_replace_re_match_i(const char* restrict ref, char* target, regmatch_t* match, const char* restrict repl);
3193 char* colr_str_replace_re_match_ColorArg(const char* restrict s, regmatch_t* match, ColorArg* repl);
3194 char* colr_str_replace_re_match_ColorResult(const char* restrict s, regmatch_t* match, ColorResult* repl);
3195 char* colr_str_replace_re_match_ColorText(const char* restrict s, regmatch_t* match, ColorText* repl);
3196 char* colr_str_replace_re_matches(const char* restrict s, regmatch_t** matches, const char* restrict repl);
3197 char* colr_str_replace_re_matches_ColorArg(const char* restrict s, regmatch_t** matches, ColorArg* repl);
3198 char* colr_str_replace_re_matches_ColorResult(const char* restrict s, regmatch_t** matches, ColorResult* repl);
3199 char* colr_str_replace_re_matches_ColorText(const char* restrict s, regmatch_t** matches, ColorText* repl);
3200 
3201 char* colr_str_repr(const char* s);
3202 char* colr_str_rjust(const char* s, int width, const char padchar);
3203 bool colr_str_starts_with(const char* restrict s, const char* restrict prefix);
3204 char* colr_str_strip_codes(const char* s);
3205 char* colr_str_to_lower(const char* s);
3206 
3207 TermSize colr_term_size(void);
3208 struct winsize colr_win_size(void);
3209 struct winsize colr_win_size_env(void);
3210 void format_bgx(char* out, unsigned char num);
3211 void format_bg(char* out, BasicValue value);
3212 void format_bg_RGB(char* out, RGB rgb);
3213 void format_bg_RGB_term(char* out, RGB rgb);
3214 void format_fgx(char* out, unsigned char num);
3215 void format_fg(char* out, BasicValue value);
3216 void format_fg_RGB(char* out, RGB rgb);
3217 void format_fg_RGB_term(char* out, RGB rgb);
3218 void format_style(char* out, StyleValue style);
3229 typedef void (*RGB_fmter)(char* out, RGB rgb);
3232 typedef char* (*rainbow_creator)(const char* s, double freq, size_t offset, size_t spread);
3233 
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);
3243 RGB rainbow_step(double freq, size_t offset);
3244 
3251 void _colr_free(void* p);
3252 
3257 bool _colr_is_last_arg(void* p);
3258 size_t _colr_ptr_length(void* p);
3259 char* _colr_ptr_repr(void* p);
3260 char* _colr_ptr_to_str(void* p);
3261 
3266 char* _colr_join(void* joinerp, ...);
3267 size_t _colr_join_size(void* joinerp, va_list args);
3268 
3273 size_t _colr_join_array_length(void* ps);
3274 size_t _colr_join_arrayn_size(void* joinerp, void* ps, size_t count);
3275 char* colr_join_array(void* joinerp, void* ps);
3276 char* colr_join_arrayn(void* joinerp, void* ps, size_t count);
3277 
3282 bool ArgType_eq(ArgType a, ArgType b);
3283 char* ArgType_repr(ArgType type);
3284 char* ArgType_to_str(ArgType type);
3285 
3290 void ColorArgs_array_free(ColorArg** ps);
3291 char* ColorArgs_array_repr(ColorArg** lst);
3292 ColorArg ColorArg_empty(void);
3293 bool ColorArg_eq(ColorArg a, ColorArg b);
3294 char* ColorArg_example(ColorArg carg, bool colorized);
3295 void ColorArg_free(ColorArg* p);
3298 ColorArg ColorArg_from_RGB(ArgType type, RGB value);
3299 ColorArg ColorArg_from_esc(const char* s);
3300 ColorArg ColorArg_from_str(ArgType type, const char* colorname);
3302 ColorArg ColorArg_from_value(ArgType type, ColorType colrtype, void* p);
3303 bool ColorArg_is_empty(ColorArg carg);
3304 bool ColorArg_is_invalid(ColorArg carg);
3305 bool ColorArg_is_ptr(void* p);
3306 bool ColorArg_is_valid(ColorArg carg);
3307 size_t ColorArg_length(ColorArg carg);
3308 char* ColorArg_repr(ColorArg carg);
3310 char* ColorArg_to_esc(ColorArg carg);
3311 bool ColorArg_to_esc_s(char* dest, ColorArg carg);
3312 
3313 ColorArg** ColorArgs_from_str(const char* s, bool unique);
3314 
3322 ColorJustify ColorJustify_new(ColorJustifyMethod method, int width, char padchar);
3323 char* ColorJustify_repr(ColorJustify cjust);
3325 
3331 ColorResult* ColorResult_center(ColorResult* cres, int width, char padchar);
3334 void ColorResult_free(ColorResult* p);
3335 ColorResult ColorResult_from_str(const char* s);
3336 ColorResult* ColorResult_from_stra(const char* s);
3338 bool ColorResult_is_ptr(void* p);
3339 size_t ColorResult_length(ColorResult cres);
3340 ColorResult* ColorResult_ljust(ColorResult* cres, int width, char padchar);
3341 ColorResult ColorResult_new(char* s);
3342 char* ColorResult_repr(ColorResult cres);
3343 char* ColorResult_rip_str(ColorResult* cres);
3344 ColorResult* ColorResult_rjust(ColorResult* cres, int width, char padchar);
3346 char* ColorResult_to_str(ColorResult cres);
3347 
3354 void ColorText_free(ColorText* p);
3356 ColorText ColorText_from_values(char* text, ...);
3357 ColorText ColorText_from_valuesv(char* text, va_list args);
3358 bool ColorText_has_arg(ColorText ctext, ColorArg carg);
3359 bool ColorText_has_args(ColorText ctext);
3360 bool ColorText_is_empty(ColorText ctext);
3361 bool ColorText_is_ptr(void* p);
3362 size_t ColorText_length(ColorText ctext);
3363 char* ColorText_repr(ColorText ctext);
3364 ColorText* ColorText_set_center(ColorText* ctext, int width, char padchar);
3365 ColorText* ColorText_set_ljust(ColorText* ctext, int width, char padchar);
3367 ColorText* ColorText_set_rjust(ColorText* ctext, int width, char padchar);
3368 void ColorText_set_values(ColorText* ctext, char* text, ...);
3370 char* ColorText_to_str(ColorText ctext);
3371 
3376 bool ColorType_eq(ColorType a, ColorType b);
3377 ColorType ColorType_from_str(const char* arg);
3378 bool ColorType_is_invalid(ColorType type);
3379 bool ColorType_is_valid(ColorType type);
3380 char* ColorType_repr(ColorType type);
3381 char* ColorType_to_str(ColorType type);
3382 
3389 char* ColorValue_example(ColorValue cval);
3390 ColorValue ColorValue_from_esc(const char* s);
3391 ColorValue ColorValue_from_str(const char* s);
3396 bool ColorValue_has_RGB(ColorValue cval, RGB rgb);
3397 bool ColorValue_is_empty(ColorValue cval);
3399 bool ColorValue_is_valid(ColorValue cval);
3400 size_t ColorValue_length(ArgType type, ColorValue cval);
3401 char* ColorValue_repr(ColorValue cval);
3402 char* ColorValue_to_esc(ArgType type, ColorValue cval);
3403 bool ColorValue_to_esc_s(char* dest, ArgType type, ColorValue cval);
3404 
3410 BasicValue BasicValue_from_esc(const char* s);
3411 BasicValue BasicValue_from_str(const char* arg);
3412 bool BasicValue_is_valid(BasicValue bval);
3414 int BasicValue_to_ansi(ArgType type, BasicValue bval);
3415 char* BasicValue_to_str(BasicValue bval);
3416 char* BasicValue_repr(BasicValue bval);
3423 int ExtendedValue_from_esc(const char* s);
3424 int ExtendedValue_from_hex(const char* hexstr);
3425 ExtendedValue ExtendedValue_from_hex_default(const char* hexstr, ExtendedValue default_value);
3427 int ExtendedValue_from_str(const char* arg);
3428 bool ExtendedValue_is_invalid(int eval);
3429 bool ExtendedValue_is_valid(int eval);
3430 char* ExtendedValue_repr(int eval);
3432 
3438 StyleValue StyleValue_from_esc(const char* s);
3439 StyleValue StyleValue_from_str(const char* arg);
3441 bool StyleValue_is_valid(StyleValue sval);
3442 char* StyleValue_repr(StyleValue sval);
3443 char* StyleValue_to_str(StyleValue sval);
3448 unsigned char RGB_average(RGB rgb);
3449 bool RGB_eq(RGB a, RGB b);
3452 int RGB_from_esc(const char* s, RGB* rgb);
3453 int RGB_from_hex(const char* hexstr, RGB* rgb);
3454 RGB RGB_from_hex_default(const char* hexstr, RGB default_value);
3455 int RGB_from_str(const char* arg, RGB* rgb);
3456 RGB RGB_grayscale(RGB rgb);
3457 RGB RGB_inverted(RGB rgb);
3458 RGB RGB_monochrome(RGB rgb);
3459 char* RGB_to_hex(RGB rgb);
3460 char* RGB_to_str(RGB rgb);
3461 RGB RGB_to_term_RGB(RGB rgb);
3462 char* RGB_repr(RGB rgb);
3463 
3467 char* TermSize_repr(TermSize ts);
3468 
3473 static_assert(
3474  (
3475  ((int)COLOR_INVALID == (int)TYPE_INVALID) &&
3476  ((int)TYPE_INVALID == (int)BASIC_INVALID) &&
3477  ((int)BASIC_INVALID == (int)EXT_INVALID) &&
3478  ((int)EXT_INVALID == (int)STYLE_INVALID)
3479  ),
3480  "Return/enum values for all color/style values should match."
3481 );
3482 static_assert(
3483  (
3484  COLORARG_MARKER &&
3487  ) &&
3491  ) &&
3492  (COLORTEXT_MARKER &&
3496  ) &&
3497  (COLORRESULT_MARKER &&
3502  )
3503  ),
3504  "Markers must be positive and unique for each struct in Colr!"
3505 );
3506 
3507 #endif // COLR_H
char padchar
The desired padding character, or 0 to use the default (`&#39; &#39;`).
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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;...
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&#39;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&#39;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&#39;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&#39;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&#39;s ExtendedValue and it&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;s string result.
Definition: colr.c:4044
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: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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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&#39;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