diff options
Diffstat (limited to 'color.c')
-rw-r--r-- | color.c | 37 |
1 files changed, 17 insertions, 20 deletions
@@ -161,11 +161,6 @@ int color_parse(const char *value, char *dst) return color_parse_mem(value, strlen(value), dst); } -void color_set(char *dst, const char *color_bytes) -{ - xsnprintf(dst, COLOR_MAXLEN, "%s", color_bytes); -} - /* * Write the ANSI color codes for "c" to "out"; the string should * already have the ANSI escape code in it. "out" should have enough @@ -179,7 +174,7 @@ static char *color_output(char *out, int len, const struct color *c, char type) break; case COLOR_ANSI: if (len < 2) - die("BUG: color parsing ran out of space"); + BUG("color parsing ran out of space"); *out++ = type; *out++ = '0' + c->value; break; @@ -261,7 +256,7 @@ int color_parse_mem(const char *value, int value_len, char *dst) #undef OUT #define OUT(x) do { \ if (dst == end) \ - die("BUG: color parsing ran out of space"); \ + BUG("color parsing ran out of space"); \ *dst++ = (x); \ } while(0) @@ -324,19 +319,20 @@ int git_config_colorbool(const char *var, const char *value) return GIT_COLOR_AUTO; } -static int check_auto_color(void) +static int check_auto_color(int fd) { - if (color_stdout_is_tty < 0) - color_stdout_is_tty = isatty(1); - if (color_stdout_is_tty || (pager_in_use() && pager_use_color)) { - char *term = getenv("TERM"); - if (term && strcmp(term, "dumb")) + static int color_stderr_is_tty = -1; + int *is_tty_p = fd == 1 ? &color_stdout_is_tty : &color_stderr_is_tty; + if (*is_tty_p < 0) + *is_tty_p = isatty(fd); + if (*is_tty_p || (fd == 1 && pager_in_use() && pager_use_color)) { + if (!is_terminal_dumb()) return 1; } return 0; } -int want_color(int var) +int want_color_fd(int fd, int var) { /* * NEEDSWORK: This function is sometimes used from multiple threads, and @@ -345,15 +341,18 @@ int want_color(int var) * is listed in .tsan-suppressions for the time being. */ - static int want_auto = -1; + static int want_auto[3] = { -1, -1, -1 }; + + if (fd < 1 || fd >= ARRAY_SIZE(want_auto)) + BUG("file descriptor out of range: %d", fd); if (var < 0) var = git_use_color_default; if (var == GIT_COLOR_AUTO) { - if (want_auto < 0) - want_auto = check_auto_color(); - return want_auto; + if (want_auto[fd] < 0) + want_auto[fd] = check_auto_color(fd); + return want_auto[fd]; } return var; } @@ -400,8 +399,6 @@ static int color_vfprintf(FILE *fp, const char *color, const char *fmt, return r; } - - int color_fprintf(FILE *fp, const char *color, const char *fmt, ...) { va_list args; |