From f9c0c1bf23e713c622239a68fd36d30a87574567 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 20 May 2024 15:07:24 +0200 Subject: [PATCH 1/4] cal: fix --week use and colors * don't overwrite --week= by the current date, default only to the current year, if the year is not specified * introduce "weeks" color sequence to colorize all week numbers. Note that the man page suggests using "weeknumber" to colorize all week numbers, but the code only uses this sequence for the week requested by the --week option. This commit maintains backward compatibility, although it would be better to use "weeknumber" for all week numbers and "weekwanted" for the desired week. Signed-off-by: Karel Zak --- misc-utils/cal.1.adoc | 10 +++++++++- misc-utils/cal.c | 46 ++++++++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/misc-utils/cal.1.adoc b/misc-utils/cal.1.adoc index fd508bc02c1..fe4f7e6708a 100644 --- a/misc-utils/cal.1.adoc +++ b/misc-utils/cal.1.adoc @@ -112,7 +112,12 @@ Display a calendar for the whole year. Display a calendar for the next twelve months. *-w*, *--week*[=_number_]:: -Display week numbers in the calendar (US or ISO-8601). See the *NOTES* section for more details. +Display week numbers in the calendar according to the US or ISO-8601 format. If +a _number_ is specified, the requested week will be printed in the desired or +current year. The _number_ may be overwritten if _day_ and _month_ are also +specified. ++ +See the *NOTES* section for more details. *--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. @@ -154,6 +159,9 @@ The logical color names supported by *cal* are: The current day. *weeknumber*:: +The week number requested by the --week= command line option. + +*weeks*:: The number of the week. *header*:: diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 900f7277da6..65517512e96 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -85,15 +85,17 @@ enum { CAL_COLOR_TODAY, CAL_COLOR_HEADER, CAL_COLOR_WEEKNUMBER, + CAL_COLOR_WEEKS, CAL_COLOR_WORKDAY, CAL_COLOR_WEEKEND }; static const struct { const char * const scheme; const char * dflt; } colors[] = { - [CAL_COLOR_TODAY] = { "today", UL_COLOR_REVERSE }, - [CAL_COLOR_WEEKNUMBER] = { "weeknumber", UL_COLOR_REVERSE }, - [CAL_COLOR_HEADER] = { "header", "" }, + [CAL_COLOR_TODAY] = { "today", UL_COLOR_REVERSE }, + [CAL_COLOR_WEEKNUMBER] = { "weeknumber", UL_COLOR_REVERSE }, /* requested week */ + [CAL_COLOR_WEEKS] = { "weeks", "" }, /* week numbers */ + [CAL_COLOR_HEADER] = { "header", "" }, [CAL_COLOR_WORKDAY] = { "workday", "" }, [CAL_COLOR_WEEKEND] = { "weekend", "" } }; @@ -407,6 +409,8 @@ int main(int argc, char **argv) break; case 'w': if (optarg) { + if (*optarg == '=') + optarg++; ctl.req.week = strtos32_or_err(optarg, _("invalid week argument")); if (ctl.req.week < 1 || 54 < ctl.req.week) @@ -517,10 +521,13 @@ int main(int argc, char **argv) } break; case 0: - ctl.req.day = local_time.tm_yday + 1; + if (!ctl.req.week) { + ctl.req.day = local_time.tm_yday + 1; + if (!ctl.req.month) + ctl.req.month = local_time.tm_mon + 1; + } ctl.req.year = local_time.tm_year + 1900; - if (!ctl.req.month) - ctl.req.month = local_time.tm_mon + 1; + break; default: warnx(_("bad usage")); @@ -859,6 +866,13 @@ static void cal_output_months(struct cal_month *month, const struct cal_control const char *seq_we_start = cal_get_color_sequence(CAL_COLOR_WEEKEND); const char *seq_we_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKEND); + const char *seq_ws_start = NULL, *seq_ws_end = NULL; + + if (ctl->weektype) { + seq_ws_start = cal_get_color_sequence(CAL_COLOR_WEEKS); + seq_ws_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKS); + } + for (week_line = 0; week_line < MAXDAYS / DAYS_IN_WEEK; week_line++) { for (i = month; i; i = i->next) { /* Determine the day that should be highlighted. */ @@ -874,11 +888,21 @@ static void cal_output_months(struct cal_month *month, const struct cal_control if (ctl->weektype) { if (0 < i->weeks[week_line]) { - if ((ctl->weektype & WEEK_NUM_MASK) == i->weeks[week_line]) - printf("%s%2d%s", - cal_get_color_sequence(CAL_COLOR_WEEKNUMBER), - i->weeks[week_line], - cal_get_color_disable_sequence(CAL_COLOR_WEEKNUMBER)); + const char *seq_start, *seq_end; + + /* colorize by requested week-number or generic weeks color */ + if (ctl->req.week && + ctl->req.week == i->weeks[week_line]) { + seq_start = cal_get_color_sequence(CAL_COLOR_WEEKNUMBER); + seq_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKNUMBER); + } else { + seq_start = seq_ws_start; + seq_end = seq_ws_end; + } + + if (seq_start && *seq_start) + printf("%s%2d%s", seq_start, + i->weeks[week_line], seq_end); else printf("%2d", i->weeks[week_line]); } else From 70080ecf39e70e6b4d0aef1c1eecd75614e32390 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 20 May 2024 15:54:37 +0200 Subject: [PATCH 2/4] cal: properly colorize the week number in vertical output. Signed-off-by: Karel Zak --- misc-utils/cal.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 65517512e96..527dc7a86cc 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -992,16 +992,31 @@ cal_vert_output_months(struct cal_month *month, const struct cal_control *ctl) if (!ctl->weektype) return; + const char *seq_ws_start = cal_get_color_sequence(CAL_COLOR_WEEKS); + const char *seq_ws_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKS); + printf("%*s", (int)ctl->day_width - 1, ""); for (m = month; m; m = m->next) { for (week = 0; week < MAXDAYS / DAYS_IN_WEEK; week++) { if (0 < m->weeks[week]) { - if ((ctl->weektype & WEEK_NUM_MASK) == m->weeks[week]) - printf("%s%*d%s", - cal_get_color_sequence(CAL_COLOR_WEEKNUMBER), - skip - (ctl->julian ? 3 : 2), - m->weeks[week], - cal_get_color_disable_sequence(CAL_COLOR_WEEKNUMBER)); + const char *seq_start = NULL, *seq_end = NULL; + + /* colorize by requested week-number or generic weeks color */ + if (ctl->req.week && + ctl->req.week == m->weeks[week]) { + seq_start = cal_get_color_sequence(CAL_COLOR_WEEKNUMBER); + seq_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKNUMBER); + } else { + seq_start = seq_ws_start; + seq_end = seq_ws_end; + } + + if (seq_start && *seq_start) + printf("%*s%s%*d%s", + skip - (ctl->julian ? 3 : 2), "", + seq_start, + (ctl->julian ? 3 : 2), m->weeks[week], + seq_end); else printf("%*d", skip, m->weeks[week]); } else From 9abbe9e800ccb9b2d6ff58091811cce73e2b5319 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 21 May 2024 09:29:08 +0200 Subject: [PATCH 3/4] cal: colorize --vertical output. Let's use the same colors as we currently use for regular output. Signed-off-by: Karel Zak --- misc-utils/cal.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 527dc7a86cc..89bce405151 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -822,6 +822,8 @@ static void cal_vert_output_header(struct cal_month *month, struct cal_month *m; int month_width; + cal_enable_color(CAL_COLOR_HEADER); + month_width = ctl->day_width * (MAXDAYS / DAYS_IN_WEEK); /* Padding for the weekdays */ @@ -848,6 +850,8 @@ static void cal_vert_output_header(struct cal_month *month, left(out, month_width, ctl->gutter_width); } } + + cal_disable_color(CAL_COLOR_HEADER); fputc('\n', stdout); } @@ -951,10 +955,32 @@ cal_vert_output_months(struct cal_month *month, const struct cal_control *ctl) int i, reqday, week, d; int skip; struct cal_month *m; + int firstwork = ctl->weekstart == SUNDAY ? 1 : 0; /* first workday in week */ + + const char *seq_wo_start = cal_get_color_sequence(CAL_COLOR_WORKDAY); + const char *seq_wo_end = cal_get_color_disable_sequence(CAL_COLOR_WORKDAY); + const char *seq_we_start = cal_get_color_sequence(CAL_COLOR_WEEKEND); + const char *seq_we_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKEND); + const char *seq_hd_start = cal_get_color_sequence(CAL_COLOR_HEADER); + const char *seq_hd_end = cal_get_color_disable_sequence(CAL_COLOR_HEADER); skip = ctl->day_width; for (i = 0; i < DAYS_IN_WEEK; i++) { + const char *seq_start = seq_wo_start, + *seq_end = seq_wo_end; + + /* Day name */ + fput_seq(seq_hd_start); left(ctl->weekdays[i], ctl->day_width - 1, 0); + fput_seq(seq_hd_end); + + /* Workday/Weekend color */ + if (i < firstwork || i > firstwork + 4) { + seq_start = seq_we_start; + seq_end = seq_we_end; + } + + /* Day digits */ for (m = month; m; m = m->next) { reqday = 0; if (m->month == ctl->req.month && m->year == ctl->req.year) { @@ -967,7 +993,9 @@ cal_vert_output_months(struct cal_month *month, const struct cal_control *ctl) } for (week = 0; week < MAXDAYS / DAYS_IN_WEEK; week++) { d = i + DAYS_IN_WEEK * week; + if (0 < m->days[d]) { + fput_seq(seq_start); if (reqday == m->days[d]) { printf("%*s%s%*d%s", skip - (ctl->julian ? 3 : 2), @@ -979,6 +1007,7 @@ cal_vert_output_months(struct cal_month *month, const struct cal_control *ctl) } else { printf("%*d", skip, m->days[d]); } + fput_seq(seq_end); } else { printf("%*s", skip, ""); } @@ -992,6 +1021,7 @@ cal_vert_output_months(struct cal_month *month, const struct cal_control *ctl) if (!ctl->weektype) return; + /* Week numbers */ const char *seq_ws_start = cal_get_color_sequence(CAL_COLOR_WEEKS); const char *seq_ws_end = cal_get_color_disable_sequence(CAL_COLOR_WEEKS); From 10ce2af422fc2465a6d5210a4f616b1b8d8ee3d3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 23 May 2024 13:13:34 +0200 Subject: [PATCH 4/4] tests: add color schema to cal(1) tests Signed-off-by: Karel Zak --- tests/expected/cal/color-first-day | 16 +++---- tests/expected/cal/color-last-day | 16 +++---- .../cal/color-reformation-corner-cases-1 | 10 ++-- .../cal/color-reformation-corner-cases-2 | 10 ++-- .../cal/color-reformation-corner-cases-3 | 10 ++-- .../cal/color-reformation-corner-cases-4 | 10 ++-- tests/expected/cal/color-vertical | 16 +++---- tests/expected/cal/color-vertical-week | 18 +++---- .../cal/colorw-first-day-week-numbers | 16 +++---- .../expected/cal/colorw-last-day-week-numbers | 16 +++---- ...rw-reformation-corner-cases-1-week-numbers | 10 ++-- ...rw-reformation-corner-cases-2-week-numbers | 10 ++-- ...rw-reformation-corner-cases-3-week-numbers | 10 ++-- ...rw-reformation-corner-cases-4-week-numbers | 10 ++-- tests/ts/cal/color | 47 ++++++------------- tests/ts/cal/colorw | 37 +++++---------- tests/ts/cal/terminal-colors.d/cal.scheme | 6 +++ 17 files changed, 123 insertions(+), 145 deletions(-) create mode 100644 tests/ts/cal/terminal-colors.d/cal.scheme diff --git a/tests/expected/cal/color-first-day b/tests/expected/cal/color-first-day index 446f4fd93e0..229681d6aab 100644 --- a/tests/expected/cal/color-first-day +++ b/tests/expected/cal/color-first-day @@ -1,8 +1,8 @@ - January 0001 -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 31 + January 0001 +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 31 diff --git a/tests/expected/cal/color-last-day b/tests/expected/cal/color-last-day index ec7793c6b5f..b7020ab3ffd 100644 --- a/tests/expected/cal/color-last-day +++ b/tests/expected/cal/color-last-day @@ -1,8 +1,8 @@ - November 9999 December 9999 January 10000 -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 1 2 3 4 1 - 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 -14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15 -21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 -28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 - 30 31 + November 9999 December 9999 January 10000 +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  1 2 3 4  1 + 7 8 9 10 11 12 13  5 6 7 8 9 10 11  2 3 4 5 6 7 8 +14 15 16 17 18 19 20 12 13 14 15 16 17 18  9 10 11 12 13 14 15 +21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 +28 29 30 26 27 28 29 30 [31 23 24 25 26 27 28 29 + 30 31 diff --git a/tests/expected/cal/color-reformation-corner-cases-1 b/tests/expected/cal/color-reformation-corner-cases-1 index 4b26465bbe0..af9e2bd81a5 100644 --- a/tests/expected/cal/color-reformation-corner-cases-1 +++ b/tests/expected/cal/color-reformation-corner-cases-1 @@ -1,8 +1,8 @@ - September 1752 -Su Mo Tu We Th Fr Sa - 1  2 14 15 16 -17 18 19 20 21 22 23 -24 25 26 27 28 29 30 + September 1752 +Su Mo Tu We Th Fr Sa +  1 [ 2 14 15 16 +17 18 19 20 21 22 23 +24 25 26 27 28 29 30 diff --git a/tests/expected/cal/color-reformation-corner-cases-2 b/tests/expected/cal/color-reformation-corner-cases-2 index db29a7f424b..75402e99a92 100644 --- a/tests/expected/cal/color-reformation-corner-cases-2 +++ b/tests/expected/cal/color-reformation-corner-cases-2 @@ -1,8 +1,8 @@ - September 1752 -Su Mo Tu We Th Fr Sa - 1 2 14 15 16 -17 18 19 20 21 22 23 -24 25 26 27 28 29 30 + September 1752 +Su Mo Tu We Th Fr Sa +  1 2 14 15 16 +17 18 19 20 21 22 23 +24 25 26 27 28 29 30 diff --git a/tests/expected/cal/color-reformation-corner-cases-3 b/tests/expected/cal/color-reformation-corner-cases-3 index db29a7f424b..75402e99a92 100644 --- a/tests/expected/cal/color-reformation-corner-cases-3 +++ b/tests/expected/cal/color-reformation-corner-cases-3 @@ -1,8 +1,8 @@ - September 1752 -Su Mo Tu We Th Fr Sa - 1 2 14 15 16 -17 18 19 20 21 22 23 -24 25 26 27 28 29 30 + September 1752 +Su Mo Tu We Th Fr Sa +  1 2 14 15 16 +17 18 19 20 21 22 23 +24 25 26 27 28 29 30 diff --git a/tests/expected/cal/color-reformation-corner-cases-4 b/tests/expected/cal/color-reformation-corner-cases-4 index 6c5571458e0..dbf47a90858 100644 --- a/tests/expected/cal/color-reformation-corner-cases-4 +++ b/tests/expected/cal/color-reformation-corner-cases-4 @@ -1,8 +1,8 @@ - September 1752 -Su Mo Tu We Th Fr Sa - 1 2 14 15 16 -17 18 19 20 21 22 23 -24 25 26 27 28 29 30 + September 1752 +Su Mo Tu We Th Fr Sa +  1 2 [14 15 16 +17 18 19 20 21 22 23 +24 25 26 27 28 29 30 diff --git a/tests/expected/cal/color-vertical b/tests/expected/cal/color-vertical index bf5c6094135..f4ffac6a5d4 100644 --- a/tests/expected/cal/color-vertical +++ b/tests/expected/cal/color-vertical @@ -1,8 +1,8 @@ - February 2023 -Su 5 12 19 26 -Mo 6 13 20 27 -Tu 7 14 21 28 -We 1 8 15 22 -Th 2 9 16 23 -Fr 3 10 17 24 -Sa 4 11 18 25 + February 2023  +Su  5 12 19 26 +Mo  6 13 20 27 +Tu  7 14 21 28 +We 1 8 [15 22 +Th 2 9 16 23 +Fr 3 10 17 24 +Sa 4 11 18 25 diff --git a/tests/expected/cal/color-vertical-week b/tests/expected/cal/color-vertical-week index d69866e1f1a..70603618538 100644 --- a/tests/expected/cal/color-vertical-week +++ b/tests/expected/cal/color-vertical-week @@ -1,9 +1,9 @@ - February 2023 -Su 5 12 19 26 -Mo 6 13 20 27 -Tu 7 14 21 28 -We 1 8 15 22 -Th 2 9 16 23 -Fr 3 10 17 24 -Sa 4 11 18 25 - 5 6 7 8 9 + February 2023  +Su  5 12 19 26 +Mo  6 13 20 27 +Tu  7 14 21 28 +We 1 8 [15 22 +Th 2 9 16 23 +Fr 3 10 17 24 +Sa 4 11 18 25 +  5  6  7  8  9 diff --git a/tests/expected/cal/colorw-first-day-week-numbers b/tests/expected/cal/colorw-first-day-week-numbers index e14aaf3a398..f3117d89b26 100644 --- a/tests/expected/cal/colorw-first-day-week-numbers +++ b/tests/expected/cal/colorw-first-day-week-numbers @@ -1,8 +1,8 @@ - January 0001 - Su Mo Tu We Th Fr Sa - 1  1 - 2 2 3 4 5 6 7 8 - 3 9 10 11 12 13 14 15 - 4 16 17 18 19 20 21 22 - 5 23 24 25 26 27 28 29 - 6 30 31 + January 0001 + Su Mo Tu We Th Fr Sa + 1  [ 1 + 2 2 3 4 5 6 7 8 + 3 9 10 11 12 13 14 15 + 4 16 17 18 19 20 21 22 + 5 23 24 25 26 27 28 29 + 6 30 31 diff --git a/tests/expected/cal/colorw-last-day-week-numbers b/tests/expected/cal/colorw-last-day-week-numbers index d0d49cc2920..dd081fdfc65 100644 --- a/tests/expected/cal/colorw-last-day-week-numbers +++ b/tests/expected/cal/colorw-last-day-week-numbers @@ -1,8 +1,8 @@ - November 9999 December 9999 January 10000 - Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa -45 1 2 3 4 5 6 49 1 2 3 4 1 1 -46 7 8 9 10 11 12 13 50 5 6 7 8 9 10 11 2 2 3 4 5 6 7 8 -47 14 15 16 17 18 19 20 51 12 13 14 15 16 17 18 3 9 10 11 12 13 14 15 -48 21 22 23 24 25 26 27 52 19 20 21 22 23 24 25 4 16 17 18 19 20 21 22 -49 28 29 30 53 26 27 28 29 30 31 5 23 24 25 26 27 28 29 - 6 30 31 + November 9999 December 9999 January 10000 + Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa +45  1 2 3 4 5 6 49  1 2 3 4  1  1 +46 7 8 9 10 11 12 13 50 5 6 7 8 9 10 11  2 2 3 4 5 6 7 8 +47 14 15 16 17 18 19 20 51 12 13 14 15 16 17 18  3 9 10 11 12 13 14 15 +48 21 22 23 24 25 26 27 52 19 20 21 22 23 24 25  4 16 17 18 19 20 21 22 +49 28 29 30 53 26 27 28 29 30 [31  5 23 24 25 26 27 28 29 +  6 30 31 diff --git a/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers b/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers index 98fa041f682..a94a28e549e 100644 --- a/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers +++ b/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers @@ -1,8 +1,8 @@ - September 1752 - Su Mo Tu We Th Fr Sa -36 1  2 14 15 16 -37 17 18 19 20 21 22 23 -38 24 25 26 27 28 29 30 + September 1752 + Su Mo Tu We Th Fr Sa +36  1 [ 2 14 15 16 +37 17 18 19 20 21 22 23 +38 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers b/tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers index fdbc1997034..701eb91fe83 100644 --- a/tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers +++ b/tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers @@ -1,8 +1,8 @@ - September 1752 - Su Mo Tu We Th Fr Sa -36 1 2 14 15 16 -37 17 18 19 20 21 22 23 -38 24 25 26 27 28 29 30 + September 1752 + Su Mo Tu We Th Fr Sa +36  1 2 14 15 16 +37 17 18 19 20 21 22 23 +38 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers b/tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers index fdbc1997034..701eb91fe83 100644 --- a/tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers +++ b/tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers @@ -1,8 +1,8 @@ - September 1752 - Su Mo Tu We Th Fr Sa -36 1 2 14 15 16 -37 17 18 19 20 21 22 23 -38 24 25 26 27 28 29 30 + September 1752 + Su Mo Tu We Th Fr Sa +36  1 2 14 15 16 +37 17 18 19 20 21 22 23 +38 24 25 26 27 28 29 30 diff --git a/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers b/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers index 307b5398e56..e35901a0f3c 100644 --- a/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers +++ b/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers @@ -1,8 +1,8 @@ - September 1752 - Su Mo Tu We Th Fr Sa -36 1 2 14 15 16 -37 17 18 19 20 21 22 23 -38 24 25 26 27 28 29 30 + September 1752 + Su Mo Tu We Th Fr Sa +36  1 2 [14 15 16 +37 17 18 19 20 21 22 23 +38 24 25 26 27 28 29 30 diff --git a/tests/ts/cal/color b/tests/ts/cal/color index 90840ea4d53..2dffefed38e 100755 --- a/tests/ts/cal/color +++ b/tests/ts/cal/color @@ -31,64 +31,47 @@ fi # --color output depends on terminal type export TERM=linux +function call_cal { + if [ "$USETERM" == "yes" ]; then + XDG_CONFIG_HOME="$TS_SELF" $TS_CMD_CAL --color=always "$@" + fi + XDG_CONFIG_HOME="$TS_SELF" $TS_CMD_CAL --color=always "$@" >> $TS_OUTPUT +} + USETERM=$( ts_has_option "useterm" "$*" ) [ "$USETERM" == "yes" ] && TS_VERBOSE="yes" ts_init_subtest "first-day" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 1 1 1 -fi -$TS_CMD_CAL --color=always 1 1 1 >> $TS_OUTPUT +call_cal --color=always 1 1 1 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-1" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 2 9 1752 -fi -$TS_CMD_CAL --color=always 2 9 1752 >> $TS_OUTPUT +call_cal --color=always 2 9 1752 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-2" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 3 9 1752 -fi -$TS_CMD_CAL --color=always 3 9 1752 >> $TS_OUTPUT +call_cal --color=always 3 9 1752 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-3" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 13 9 1752 -fi -$TS_CMD_CAL --color=always 13 9 1752 >> $TS_OUTPUT +call_cal --color=always 13 9 1752 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-4" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 14 9 1752 -fi -$TS_CMD_CAL --color=always 14 9 1752 >> $TS_OUTPUT +call_cal --color=always 14 9 1752 ts_finalize_subtest ts_init_subtest "last-day" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 31 12 9999 -fi -$TS_CMD_CAL --color=always -3 31 12 9999 >> $TS_OUTPUT +call_cal --color=always -3 31 12 9999 ts_finalize_subtest ts_init_subtest "vertical" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 15 2 2023 -fi -$TS_CMD_CAL --color=always --vertical 15 2 2023 >> $TS_OUTPUT +call_cal --color=always --vertical 15 2 2023 ts_finalize_subtest ts_init_subtest "vertical-week" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL --color=always 15 2 2023 -fi -$TS_CMD_CAL --color=always --vertical --week=15 15 2 2023 >> $TS_OUTPUT +call_cal --color=always --vertical --week=15 15 2 2023 ts_finalize_subtest diff --git a/tests/ts/cal/colorw b/tests/ts/cal/colorw index 96e6e0a34ae..541e2f44546 100755 --- a/tests/ts/cal/colorw +++ b/tests/ts/cal/colorw @@ -35,46 +35,35 @@ USETERM=$( ts_has_option "useterm" "$*" ) [ "$USETERM" == "yes" ] && TS_VERBOSE="yes" +function call_cal { + if [ "$USETERM" == "yes" ]; then + XDG_CONFIG_HOME="$TS_SELF" $TS_CMD_CAL --color=always "$@" + fi + XDG_CONFIG_HOME="$TS_SELF" $TS_CMD_CAL --color=always "$@" >> $TS_OUTPUT +} + ts_init_subtest "first-day-week-numbers" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL -w --color=always 1 1 1 -fi -$TS_CMD_CAL -w --color=always 1 1 1 >> $TS_OUTPUT +call_cal -w --color=always 1 1 1 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-1-week-numbers" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL -w --color=always 2 9 1752 -fi -$TS_CMD_CAL -w --color=always 2 9 1752 >> $TS_OUTPUT +call_cal -w --color=always 2 9 1752 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-2-week-numbers" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL -w --color=always 3 9 1752 -fi -$TS_CMD_CAL -w --color=always 3 9 1752 >> $TS_OUTPUT +call_cal -w --color=always 3 9 1752 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-3-week-numbers" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL -w --color=always 13 9 1752 -fi -$TS_CMD_CAL -w --color=always 13 9 1752 >> $TS_OUTPUT +call_cal -w --color=always 13 9 1752 ts_finalize_subtest ts_init_subtest "reformation-corner-cases-4-week-numbers" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL -w --color=always 14 9 1752 -fi -$TS_CMD_CAL -w --color=always 14 9 1752 >> $TS_OUTPUT +call_cal -w --color=always 14 9 1752 ts_finalize_subtest ts_init_subtest "last-day-week-numbers" -if [ "$USETERM" == "yes" ]; then - $TS_CMD_CAL -w --color=always 31 12 9999 -fi -$TS_CMD_CAL -w --color=always -3 31 12 9999 >> $TS_OUTPUT +call_cal -w --color=always -3 31 12 9999 ts_finalize_subtest ts_finalize diff --git a/tests/ts/cal/terminal-colors.d/cal.scheme b/tests/ts/cal/terminal-colors.d/cal.scheme new file mode 100644 index 00000000000..4f959622fee --- /dev/null +++ b/tests/ts/cal/terminal-colors.d/cal.scheme @@ -0,0 +1,6 @@ +workday yellow +weekend red +today \e[48;5;160m\e[38;5;221 +header magenta +weeks green +weeknumber blue