]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: support --color[={auto,always,never}]
authorKarel Zak <kzak@redhat.com>
Mon, 6 May 2013 17:11:28 +0000 (19:11 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 6 May 2013 17:11:28 +0000 (19:11 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/dmesg.1
sys-utils/dmesg.c

index f2dcc1c24d4169f209c86e3e1c1e2c2c32a491dc..c0606884af6b402a8ed759d966ef94bb9f3c1299 100644 (file)
@@ -63,8 +63,9 @@ and \fB\-\-nopager\fR.
 Print a help text and exit.
 .IP "\fB\-k\fR, \fB\-\-kernel\fR"
 Print kernel messages.
-.IP "\fB\-L\fR, \fB\-\-color\fR"
-Colorize important messages.
+.IP "\fB\-L\fR, \fB\-\-color\fR [=\fIwhen\fP]"
+Colorize important messages, the optional argumet \fIwhen\fP is 'auto', 'never'
+or 'always'. If the \fIwhen\fP argument is omitted then the default is 'auto'.
 .IP  "\fB\-l\fR, \fB\-\-level \fIlist\fR"
 Restrict output to defined (comma separated)
 .I list
index a89fb6c753ec407367317914e15a04dd4bbc24cf..89bf06f125bd739ce9407b3e5b402be0dd1f523b 100644 (file)
@@ -236,7 +236,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -f, --facility <list>       restrict output to defined facilities\n"), out);
        fputs(_(" -H, --human                 human readable output\n"), out);
        fputs(_(" -k, --kernel                display kernel messages\n"), out);
-       fputs(_(" -L, --color                 colorize messages\n"), out);
+       fputs(_(" -L, --color[=<when>]        colorize messages (auto, always or never)\n"), out);
        fputs(_(" -l, --level <list>          restrict output to defined levels\n"), out);
        fputs(_(" -n, --console-level <level> set level of messages printed to console\n"), out);
        fputs(_(" -P, --nopager               do not pipe output into a pager\n"), out);
@@ -1149,11 +1149,12 @@ int main(int argc, char *argv[])
                .method = DMESG_METHOD_KMSG,
                .kmsg = -1,
        };
+       int colormode = UL_COLORMODE_NEVER;
 
        static const struct option longopts[] = {
                { "buffer-size",   required_argument, NULL, 's' },
                { "clear",         no_argument,       NULL, 'C' },
-               { "color",         no_argument,       NULL, 'L' },
+               { "color",         optional_argument, NULL, 'L' },
                { "console-level", required_argument, NULL, 'n' },
                { "console-off",   no_argument,       NULL, 'D' },
                { "console-on",    no_argument,       NULL, 'E' },
@@ -1192,7 +1193,7 @@ int main(int argc, char *argv[])
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((c = getopt_long(argc, argv, "CcDdEeF:f:HhkLl:n:iPrSs:TtuVwx",
+       while ((c = getopt_long(argc, argv, "CcDdEeF:f:HhkL::l:n:iPrSs:TtuVwx",
                                longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
@@ -1239,7 +1240,13 @@ int main(int argc, char *argv[])
                        setbit(ctl.facilities, FAC_BASE(LOG_KERN));
                        break;
                case 'L':
-                       ctl.color = 1;
+                       colormode = UL_COLORMODE_AUTO;
+                       if (optarg) {
+                               char *p = *optarg == '=' ? optarg + 1 : optarg;
+                               colormode = colormode_from_string(p);
+                               if (colormode < 0)
+                                       errx(EXIT_FAILURE, _("unsupported color mode: '%s'"), p);
+                       }
                        break;
                case 'l':
                        ctl.fltr_lev= 1;
@@ -1315,8 +1322,8 @@ int main(int argc, char *argv[])
                if (!ctl.boot_time)
                        ctl.reltime = 0;
        }
-       if (ctl.color)
-               ctl.color = colors_init() ? 1 : 0;
+
+       ctl.color = colors_init(colormode) ? 1 : 0;
 
        ctl.pager = nopager ? 0 : ctl.pager;
        if (ctl.pager)