]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: support --color[={auto,always,never}]
authorSami Kerola <kerolasa@iki.fi>
Tue, 7 May 2013 20:34:57 +0000 (21:34 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sun, 26 May 2013 08:59:19 +0000 (09:59 +0100)
Similar with dmesg commit 9bc2b51a06dc9cf6244106ac489ab08a91fd4360.

CC: Pádraig Brady <P@draigBrady.com>
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/Makemodule.am
misc-utils/cal.c

index 0dc2161043e21caca58906076c7f4a9886458358..dc0686b73b8b51361f162556bff7ac3dc468fcfb 100644 (file)
@@ -10,7 +10,7 @@ if !HAVE_LANGINFO
 cal_SOURCES += lib/langinfo.c
 endif
 
-cal_LDADD = $(LDADD)
+cal_LDADD = $(LDADD) libcommon.la
 
 if HAVE_TINFO
 cal_LDADD += -ltinfo @NCURSES_LIBS@
index 665dbcdb7bf8210b6af8dc23fa54356d0baf0eac..9d9f357d0eefb5030203ee8e526fb10c4946c472 100644 (file)
@@ -68,6 +68,7 @@
 
 #include "c.h"
 #include "closestream.h"
+#include "colors.h"
 #include "nls.h"
 #include "mbsalign.h"
 #include "strutils.h"
@@ -255,6 +256,11 @@ main(int argc, char **argv) {
        time_t now;
        int ch, day = 0, month = 0, year = 0, yflag = 0;
        int num_months = NUM_MONTHS;
+       int colormode = UL_COLORMODE_AUTO;
+
+       enum {
+               OPT_COLOR = CHAR_MAX + 1
+       };
 
        static const struct option longopts[] = {
                {"one", no_argument, NULL, '1'},
@@ -263,6 +269,7 @@ main(int argc, char **argv) {
                {"monday", no_argument, NULL, 'm'},
                {"julian", no_argument, NULL, 'j'},
                {"year", no_argument, NULL, 'y'},
+               {"color", optional_argument, NULL, OPT_COLOR},
                {"version", no_argument, NULL, 'V'},
                {"help", no_argument, NULL, 'h'},
                {NULL, 0, NULL, 0}
@@ -340,6 +347,14 @@ main(int argc, char **argv) {
                case 'y':
                        yflag = 1;
                        break;
+               case OPT_COLOR:
+                       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 'V':
                        printf(UTIL_LINUX_VERSION);
                        return EXIT_SUCCESS;
@@ -391,8 +406,8 @@ main(int argc, char **argv) {
        }
        headers_init(julian);
 
-       if (!isatty(STDOUT_FILENO))
-               day = 0; /* don't highlight */
+       if (!colors_init(colormode))
+               day = 0;
 
        if (yflag)
                yearly(day, year, julian);