diff options
Diffstat (limited to 'color.h')
-rw-r--r-- | color.h | 31 |
1 files changed, 18 insertions, 13 deletions
@@ -3,26 +3,24 @@ struct strbuf; -/* 2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */ -/* "\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\0" */ /* * The maximum length of ANSI color sequence we would generate: * - leading ESC '[' 2 - * - attr + ';' 2 * 8 (e.g. "1;") - * - fg color + ';' 9 (e.g. "38;5;2xx;") - * - fg color + ';' 9 (e.g. "48;5;2xx;") + * - attr + ';' 2 * num_attr (e.g. "1;") + * - no-attr + ';' 3 * num_attr (e.g. "22;") + * - fg color + ';' 17 (e.g. "38;2;255;255;255;") + * - bg color + ';' 17 (e.g. "48;2;255;255;255;") * - terminating 'm' NUL 2 * - * The above overcounts attr (we only use 5 not 8) and one semicolon - * but it is close enough. + * The above overcounts by one semicolon but it is close enough. + * + * The space for attributes is also slightly overallocated, as + * the negation for some attributes is the same (e.g., nobold and nodim). + * + * We allocate space for 7 attributes. */ -#define COLOR_MAXLEN 40 +#define COLOR_MAXLEN 75 -/* - * IMPORTANT: Due to the way these color codes are emulated on Windows, - * write them only using printf(), fprintf(), and fputs(). In particular, - * do not use puts() or write(). - */ #define GIT_COLOR_NORMAL "" #define GIT_COLOR_RESET "\033[m" #define GIT_COLOR_BOLD "\033[1m" @@ -75,6 +73,13 @@ extern int color_stdout_is_tty; int git_color_config(const char *var, const char *value, void *cb); int git_color_default_config(const char *var, const char *value, void *cb); +/* + * Set the color buffer (which must be COLOR_MAXLEN bytes) + * to the raw color bytes; this is useful for initializing + * default color variables. + */ +void color_set(char *dst, const char *color_bytes); + int git_config_colorbool(const char *var, const char *value); int want_color(int var); int color_parse(const char *value, char *dst); |