]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/colors: support <name>.enable too
authorKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 09:38:15 +0000 (10:38 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 09:38:15 +0000 (10:38 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/colors.c
lib/terminal-colors.d.5

index bf5fa855db359b4bf26ed2f7cecc8ce1d5e5341e..15123168d38633bf829e64c42d85de9a4c80fd00 100644 (file)
@@ -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;
index 8a97af74764283e6a3c0569f326faa0d3e36b497..ea06f968283da3985a74e9ce162cb01a704c794b 100644 (file)
@@ -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/