26 "Virtual memory exhausted",
28 "Invalid color provided",
29 "Color was not terminated with '}'"
77 int foreground,
int background) {
85 #define __APPEND(c) do { \
87 if (j >= dstn) return TermColorErrorNone; \
122 if (foreground != -1) {
123 j += snprintf(dst + j, dstn - j,
"%d;", foreground);
126 if (background != -1) {
127 j += snprintf(dst + j, dstn - j,
"%d;", background + 10);
131 if (dst[j - 1] ==
';') {
150 if (k == 1 && *color ==
'0') {
166 for (i = 0; i < k; i++) {
232 for (i = 0; i < srcn && j < dstn; i++) {
237 if (i + 1 < srcn && src[i + 1] ==
'{') {
246 while (i < srcn && src[i] !=
'}') {
259 color[k++] = src[i++];
296 const size_t l = strlen(
fmt);
297 const size_t n = l * 2 + 16;
300 char *buffer = malloc(n);
301 if (buffer == NULL) {
311 if (vsnprintf(stream, N, buffer, ap) < 0) {
327 const size_t l = strlen(
fmt);
328 const size_t n = l * 2 + 16;
331 char *buffer = malloc(n);
332 if (buffer == NULL) {
340 #ifdef TERMCOLOR_OS_WIN
341 HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
343 GetConsoleMode(output, &mode);
344 mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
345 mode |= ENABLE_PROCESSED_OUTPUT;
346 WINBOOL set = !SetConsoleMode(output, mode);
352 if (vfprintf(stream, buffer, ap) < 0) {
const char * tcol_errorstr(const enum term_color_error_t err)
int tcol_fprintf(FILE *stream, const char *fmt,...)
static int tcol_vsnprintf(char *stream, size_t N, const char *fmt, va_list ap)
const char * tcol_errorstrs[TERM_COLOR_ERROR_COUNT]
int tcol_printf(const char *fmt,...)
int _tcol_color_generate(char *dst, size_t dstn, size_t *len, int rep, int foreground, int background)
_termcolor_internal_color
@ _termcolor_internal_color_FANT
@ _termcolor_internal_color_BOLD
@ _termcolor_internal_color_UNDR
@ _termcolor_internal_color_STRK
@ _termcolor_internal_color_BLNK
@ _termcolor_internal_color_ITLC
void tcol_override_color_checks(bool enable_color)
int tcol_snprintf(char *stream, size_t N, const char *fmt,...)
static int tcol_fmt_parse(char *dst, size_t dstn, const char *src, size_t srcn)
int _termcolor_internal_lookup(const char color_name)
int tcol_color_parse(char *dst, size_t dstn, char color[16], size_t k, size_t *len)
bool tcol_has_color(void)
static int tcol_vfprintf(FILE *stream, const char *fmt, va_list ap)
@ TermColorErrorInvalidColor
@ TermColorErrorUnterminatedColor
@ TermColorErrorAllocationFailed
@ TermColorErrorPrintingFailed