diff options
author | Karel Zak | 2014-03-11 10:38:15 +0100 |
---|---|---|
committer | Karel Zak | 2014-03-11 10:38:15 +0100 |
commit | 329b0ee753f29fab348a189749e1d2f268e90286 (patch) | |
tree | 00af9e349ed669a8d9b6b1f1683e6c160a370063 /lib | |
parent | lib/colors: add info to man pages, add terminal-colors.d.5 (diff) | |
download | kernel-qcow2-util-linux-329b0ee753f29fab348a189749e1d2f268e90286.tar.gz kernel-qcow2-util-linux-329b0ee753f29fab348a189749e1d2f268e90286.tar.xz kernel-qcow2-util-linux-329b0ee753f29fab348a189749e1d2f268e90286.zip |
lib/colors: support <name>.enable too
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/colors.c | 28 | ||||
-rw-r--r-- | lib/terminal-colors.d.5 | 28 |
2 files changed, 38 insertions, 18 deletions
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/ |