cli: disable colors on dumb terminals
authorLubomir Rintel <lkundrak@v3.sk>
Wed, 17 Feb 2016 16:57:21 +0000 (17:57 +0100)
committerLubomir Rintel <lkundrak@v3.sk>
Wed, 17 Feb 2016 18:04:39 +0000 (19:04 +0100)
Nothing too sophisticated; just a simple way to get an color-less output on a
pty that wouldn't confuse the test suite.

clients/cli/utils.c

index 898e7f2..287778b 100644 (file)
@@ -362,8 +362,13 @@ use_colors (NmCli *nmc)
        if (nmc == NULL)
                return FALSE;
 
-       if (nmc->use_colors == NMC_USE_COLOR_AUTO)
-               nmc->use_colors = isatty (fileno (stdout)) ? NMC_USE_COLOR_YES : NMC_USE_COLOR_NO;
+       if (nmc->use_colors == NMC_USE_COLOR_AUTO) {
+               if (   g_strcmp0 (g_getenv ("TERM"), "dumb") == 0
+                   || !isatty (fileno (stdout)))
+                       nmc->use_colors = NMC_USE_COLOR_NO;
+               else
+                       nmc->use_colors = NMC_USE_COLOR_YES;
+       }
 
        return nmc->use_colors == NMC_USE_COLOR_YES;
 }