summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2019-02-04 14:14:37 +0100
committerKarel Zak2019-02-04 14:14:37 +0100
commit5db5962339dbd619a8f779961548fb667d3c9376 (patch)
tree101b32722a49a3d8a3dd1c70538870e90d26f1ba /lib
parentsfdisk: fix logical partition resize when start specified (diff)
downloadkernel-qcow2-util-linux-5db5962339dbd619a8f779961548fb667d3c9376.tar.gz
kernel-qcow2-util-linux-5db5962339dbd619a8f779961548fb667d3c9376.tar.xz
kernel-qcow2-util-linux-5db5962339dbd619a8f779961548fb667d3c9376.zip
lib/colors: force to "never" mode on non-terminal output
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/colors.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/colors.c b/lib/colors.c
index f636ecc4f..bea7bd1d7 100644
--- a/lib/colors.c
+++ b/lib/colors.c
@@ -653,9 +653,6 @@ static int colors_terminal_is_ready(void)
{
int ncolors = -1;
- if (isatty(STDOUT_FILENO) != 1)
- goto none;
-
#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW)
{
int ret;
@@ -692,11 +689,16 @@ int colors_init(int mode, const char *name)
struct ul_color_ctl *cc = &ul_colors;
cc->utilname = name;
- cc->mode = mode;
termcolors_init_debug();
- if (mode == UL_COLORMODE_UNDEF && (ready = colors_terminal_is_ready())) {
+ if (mode != UL_COLORMODE_ALWAYS && !isatty(STDOUT_FILENO))
+ cc->mode = UL_COLORMODE_NEVER;
+ else
+ cc->mode = mode;
+
+ if (cc->mode == UL_COLORMODE_UNDEF
+ && (ready = colors_terminal_is_ready())) {
int rc = colors_read_configuration(cc);
if (rc)
cc->mode = UL_COLORMODE_DEFAULT;
@@ -755,6 +757,14 @@ int colors_wanted(void)
}
/*
+ * Returns mode
+ */
+int colors_mode(void)
+{
+ return ul_colors.mode;
+}
+
+/*
* Enable @seq color
*/
void color_fenable(const char *seq, FILE *f)