[pacman-dev] [Patch] Disable colors and progress bars if TERM=dumb

Ivy Foster ivy.foster at gmail.com
Fri Mar 25 04:13:13 UTC 2016


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 at 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 at 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


More information about the pacman-dev mailing list