[pacman-dev] [Patch] Disable colors and progress bars if TERM=dumb
I recently noticed that if colors and progress bars are enabled, pacman will faithfully attempt to print them even to dumb terminals that cannot handle them. This patch fixes that. Cheers, iff
From 08d67cd6bbfd1bc29ebfae8eff80ffbf9e24fdf5 Mon Sep 17 00:00:00 2001 From: Ivy Foster <ivy.foster@gmail.com> Date: Thu, 24 Mar 2016 22:57:10 -0500 Subject: [PATCH] Disable colors and progress bars if TERM=dumb
Signed-off-by: Ivy Foster <ivy.foster@gmail.com> --- src/pacman/conf.c | 2 +- src/pacman/pacman.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 25de7af..39ea1ab 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -67,7 +67,7 @@ void enable_colors(int colors) { colstr_t *colstr = &config->colstr; - if(colors == PM_COLOR_ON) { + if(colors == PM_COLOR_ON && strcmp(getenv("TERM"), "dumb") != 0) { colstr->colon = BOLDBLUE "::" BOLD " "; colstr->title = BOLD; colstr->repo = BOLDMAGENTA; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index be52d1b..1d6d20f 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -1110,7 +1110,7 @@ int main(int argc, char *argv[]) install_soft_interrupt_handler(); - if(!isatty(fileno(stdout))) { + if(!isatty(fileno(stdout)) || strcmp(getenv("TERM"), "dumb") == 0) { /* disable progressbar if the output is redirected */ config->noprogressbar = 1; } else { -- 2.7.4
On 25/03/16 14:13, Ivy Foster wrote:
I recently noticed that if colors and progress bars are enabled, pacman will faithfully attempt to print them even to dumb terminals that cannot handle them. This patch fixes that.
I don't think we can detect every terminal that does not support colours properly without using has_colors() from ncurses. I really don't want to start a hardcoded list... Is there a case where people switch between terminals with differing colour support on such a regular basis that NoColor in pacman.conf is not enough? Or --color never? A
On 26 Mar 2016, at 1:58 pm +1000, Allan McRae wrote:
On 25/03/16 14:13, Ivy Foster wrote:
I recently noticed that if colors and progress bars are enabled, pacman will faithfully attempt to print them even to dumb terminals that cannot handle them. This patch fixes that.
I don't think we can detect every terminal that does not support colours properly without using has_colors() from ncurses. I really don't want to start a hardcoded list...
Oh, definitely. I was under the impression that if a term couldn't handle escape sequences gracefully (whether or not it actually uses them for formatting being a different question), it was expected to report as the catch-all "dumb"; and if it could then it could report its capabilities through ncurses/terminfo. If that's not the case, then...my bad!
Is there a case where people switch between terminals with differing colour support on such a regular basis that NoColor in pacman.conf is not enough? Or --color never?
That's a good point. Ah, well. Cheers, and thanks for considering it! iff
participants (2)
-
Allan McRae
-
Ivy Foster