summaryrefslogtreecommitdiffstats
path: root/lib/colors.c
diff options
context:
space:
mode:
authorKarel Zak2014-03-12 09:27:10 +0100
committerKarel Zak2014-03-12 09:27:10 +0100
commitc1a54286677e8fe0d44337e3acfacc3585c78a6e (patch)
tree71a6ec76ebf86cfbf3300dfc07ca646b74080e5b /lib/colors.c
parentlibblkid: improve comment (diff)
downloadkernel-qcow2-util-linux-c1a54286677e8fe0d44337e3acfacc3585c78a6e.tar.gz
kernel-qcow2-util-linux-c1a54286677e8fe0d44337e3acfacc3585c78a6e.tar.xz
kernel-qcow2-util-linux-c1a54286677e8fe0d44337e3acfacc3585c78a6e.zip
lib/colors: care about colors only on tty()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/colors.c')
-rw-r--r--lib/colors.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/colors.c b/lib/colors.c
index 03ac7118f..8b6f089e1 100644
--- a/lib/colors.c
+++ b/lib/colors.c
@@ -16,7 +16,9 @@ static int ul_color_term_ok;
int colors_init(int mode, const char *name)
{
- if (mode == UL_COLORMODE_UNDEF) {
+ int atty = -1;
+
+ if (mode == UL_COLORMODE_UNDEF && (atty = isatty(STDOUT_FILENO))) {
char path[PATH_MAX];
snprintf(path, sizeof(path), "%s%s%s",
@@ -38,7 +40,7 @@ int colors_init(int mode, const char *name)
switch (mode) {
case UL_COLORMODE_AUTO:
- ul_color_term_ok = isatty(STDOUT_FILENO);
+ ul_color_term_ok = atty == -1 ? isatty(STDOUT_FILENO) : atty;
break;
case UL_COLORMODE_ALWAYS:
ul_color_term_ok = 1;