*--color*[=_when_]::
Colorize the output. The optional argument _when_ can be *auto*, *never* or *always*. If the _when_ argument is omitted, it defaults to *auto*. The colors can be disabled; for the current built-in default see the *--help* output. See also the *COLORS* section.
+*-c, --columns*[=_columns_]::
+Number of columns to use. *auto* uses as many as fit the terminal.
+
include::man-common/help-version.adoc[]
== PARAMETERS
WEEK_NUM_US=0x200,
};
+enum {
+ COLUMNS_MAX_THREE = -1,
+ COLUMNS_AUTO = -2,
+};
+
/* utf-8 can have up to 6 bytes per char; and an extra byte for ending \0 */
static char day_headings[(WEEK_LEN + 1) * 6 + 1];
struct tm local_time;
char *term;
time_t now;
- int ch = 0, yflag = 0, Yflag = 0;
+ int ch = 0, yflag = 0, Yflag = 0, cols = COLUMNS_MAX_THREE;
static struct cal_control ctl = {
.reform_year = DEFAULT_REFORM_YEAR,
{"twelve", no_argument, NULL, 'Y'},
{"help", no_argument, NULL, 'h'},
{"vertical", no_argument, NULL,'v'},
+ {"column", required_argument, NULL,'c'},
{NULL, 0, NULL, 0}
};
ctl.weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % DAYS_IN_WEEK;
}
#endif
- while ((ch = getopt_long(argc, argv, "13mjn:sSywYvVh", longopts, NULL)) != -1) {
+ while ((ch = getopt_long(argc, argv, "13mjn:sSywYvc:Vh", longopts, NULL)) != -1) {
err_exclusive_options(ch, longopts, excl, excl_st);
case 'v':
ctl.vertical = 1;
break;
+ case 'c':
+ if (strcmp(optarg, "auto") == 0)
+ cols = COLUMNS_AUTO;
+ else
+ cols = strtosize_or_err(optarg, "foo");
+ break;
case 'V':
print_version(EXIT_SUCCESS);
case 'h':
if (ctl.num_months > 1 && ctl.months_in_row == 0) {
ctl.months_in_row = MONTHS_IN_YEAR_ROW; /* default */
- if (isatty(STDOUT_FILENO)) {
+ if (cols > 0)
+ ctl.months_in_row = cols;
+ else if (isatty(STDOUT_FILENO)) {
int w, mw, extra, new_n;
w = get_terminal_width(80);
extra = ((w / mw) - 1) * ctl.gutter_width;
new_n = (w - extra) / mw;
- if (new_n < MONTHS_IN_YEAR_ROW)
+ switch (cols) {
+ case COLUMNS_MAX_THREE:
+ if (new_n < MONTHS_IN_YEAR_ROW)
+ ctl.months_in_row = new_n > 0 ? new_n : 1;
+ break;
+ case COLUMNS_AUTO:
ctl.months_in_row = new_n > 0 ? new_n : 1;
+ break;
+ }
}
} else if (!ctl.months_in_row)
ctl.months_in_row = 1;
fputs(_(" -Y, --twelve show the next twelve months\n"), out);
fputs(_(" -w, --week[=<num>] show US or ISO-8601 week numbers\n"), out);
fputs(_(" -v, --vertical show day vertically instead of line\n"), out);
+ fputs(_(" -c, --columns <width> amount of columns to use\n"), out);
fprintf(out,
_(" --color[=<when>] colorize messages (%s, %s or %s)\n"), "auto", "always", "never");
fprintf(out,
--- /dev/null
+5 columns
+ 2006
+
+ January February March April May
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4 1 1 2 3 4 5 6
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
+29 30 31 26 27 28 26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
+ 30
+ June July August September October
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 1 1 2 3 4 5 1 2 1 2 3 4 5 6 7
+ 4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
+11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
+18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
+25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
+ 30 31
+ November
+Su Mo Tu We Th Fr Sa
+ 1 2 3 4
+ 5 6 7 8 9 10 11
+12 13 14 15 16 17 18
+19 20 21 22 23 24 25
+26 27 28 29 30
+
--- /dev/null
+6 columns
+ 2006
+
+ January February March April May June
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4 1 1 2 3 4 5 6 1 2 3
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
+29 30 31 26 27 28 26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
+ 30
+ July August September October November December
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 1 2 3 4 5 1 2 1 2 3 4 5 6 7 1 2 3 4 1 2
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
+23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
+30 31 31
--- /dev/null
+auto columns
+ 2006
+
+ January February March
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25
+29 30 31 26 27 28 26 27 28 29 30 31
+
+ April May June
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 1 2 3 4 5 6 1 2 3
+ 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
+ 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
+16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
+23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
+30
+ July August September
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 1 2 3 4 5 1 2
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23
+23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30
+30 31
+ October November December
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5 6 7 1 2 3 4 1 2
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
+29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
+ 31
--- /dev/null
+#!/bin/bash
+
+#
+# Copyright (C) 2007-2018 Karel Zak <kzak@redhat.com>
+# Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="year"
+
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_CAL"
+
+export TERM=linux
+
+USETERM=$( ts_has_option "useterm" "$*" )
+MYTIME="29 11 2006"
+
+function call_cal {
+
+ ts_init_subtest "$(echo "$1" | cut -d ' ' -f 1)"
+ ts_log "$1"
+ shift
+ if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL "$@"
+ fi
+ $TS_CMD_CAL "$@" >> $TS_OUTPUT
+ ts_finalize_subtest
+}
+
+call_cal "6 columns" --year --column 6 $MYTIME
+call_cal "5 columns" --year --column 5 $MYTIME
+call_cal "auto columns" --year --column auto $MYTIME
+
+ts_finalize
+