From 329b0ee753f29fab348a189749e1d2f268e90286 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 11 Mar 2014 10:38:15 +0100 Subject: lib/colors: support .enable too Signed-off-by: Karel Zak --- lib/colors.c | 28 ++++++++++++++++------------ lib/terminal-colors.d.5 | 28 ++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/colors.c b/lib/colors.c index bf5fa855d..15123168d 100644 --- a/lib/colors.c +++ b/lib/colors.c @@ -16,23 +16,27 @@ static int ul_color_term_ok; int colors_init(int mode, const char *name) { - switch (mode) { - case UL_COLORMODE_UNDEF: - if (access(_PATH_TERMCOLORS_DISABLE, F_OK) == 0) { - ul_color_term_ok = 0; - break; - } else { - char path[PATH_MAX]; + if (mode == UL_COLORMODE_UNDEF) { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s%s%s", + _PATH_TERMCOLORS_DIR, name, ".enable"); + + if (access(path, F_OK) == 0) + mode = UL_COLORMODE_AUTO; + else { snprintf(path, sizeof(path), "%s%s%s", _PATH_TERMCOLORS_DIR, name, ".disable"); - if (access(path, F_OK) == 0) { - ul_color_term_ok = 0; - break; - } + if (access(_PATH_TERMCOLORS_DISABLE, F_OK) == 0 || + access(path, F_OK) == 0) + mode = UL_COLORMODE_NEVER; + else + mode = UL_COLORMODE_AUTO; } - /* fallthrough */ + } + + switch (mode) { case UL_COLORMODE_AUTO: ul_color_term_ok = isatty(STDOUT_FILENO); break; diff --git a/lib/terminal-colors.d.5 b/lib/terminal-colors.d.5 index 8a97af747..ea06f9682 100644 --- a/lib/terminal-colors.d.5 +++ b/lib/terminal-colors.d.5 @@ -8,16 +8,32 @@ terminal-colors.d \- Configure output colorization for various utilities .SH "SYNOPSIS" .PP -/etc/terminal-colors\&.d/[util-name\&.]disable +/etc/terminal-colors\&.d/[name\&.]disable +.sp +/etc/terminal-colors\&.d/name\&.enable .SH "DESCRIPTION" Files in this directory determine the default behaviour for utilities -when coloring output. +when coloring output. The +.B name +is an utility name. Supported files: -The file +.TP .B disable -turns off output colorization for all utilities compatible with config files in -.B /etc/terminal-colors\&.d. -.PP +Turns off output colorization for all compatible utilities. +.TP +.B name\&.disable +Turns off output colorization for specified utility. +.TP +.B name\&.enable +Turns on output colorization on terminal for specified utility, all another +.B disable +files are ignored. + +.SH COMPATIBILITY +The terminal-colors\&.d functionality is currently supported by all util-linux +utilities which provides colorized output. For more details always see the +COLORS section in the man page for the utility. + .SH AVAILABILITY terminal-colors.d is part of the util-linux package and is available from .UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/ -- cgit v1.2.3-55-g7522