summaryrefslogtreecommitdiffstats
path: root/misc-utils/cal.c
diff options
context:
space:
mode:
authorSami Kerola2013-05-07 22:34:57 +0200
committerSami Kerola2013-05-26 10:59:19 +0200
commit7b353df28d2d1bc8497a801602c3128ee3cca2d2 (patch)
tree83f56757039a087f3d1ded554282f03b3922aa85 /misc-utils/cal.c
parentcal: de-duplicate julian specific functions (diff)
downloadkernel-qcow2-util-linux-7b353df28d2d1bc8497a801602c3128ee3cca2d2.tar.gz
kernel-qcow2-util-linux-7b353df28d2d1bc8497a801602c3128ee3cca2d2.tar.xz
kernel-qcow2-util-linux-7b353df28d2d1bc8497a801602c3128ee3cca2d2.zip
cal: support --color[={auto,always,never}]
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>
Diffstat (limited to 'misc-utils/cal.c')
-rw-r--r--misc-utils/cal.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 665dbcdb7..9d9f357d0 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -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);