aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2025-11-12 12:09:26 +0100
committerKarel Zak <kzak@redhat.com>2025-11-12 12:09:26 +0100
commit9f85e399871525ca071bfdc0f5a49e6f15e2fa60 (patch)
tree0784fac2463ca3662ba7929e4582a55a70395d47
parent1d1d9cd8ae2e86ed3206b12be3c61905f7a140de (diff)
parent8653af2499e47c03ec29f622f840b01e823a1ac1 (diff)
downloadutil-linux-9f85e399871525ca071bfdc0f5a49e6f15e2fa60.tar.gz
Merge branch 'PR/cal-header-colors' of https://github.com/karelzak/util-linux-work
* 'PR/cal-header-colors' of https://github.com/karelzak/util-linux-work: tests: update cal color outputs cal: improve header color printing
-rw-r--r--misc-utils/cal.c21
-rw-r--r--tests/expected/cal/color-first-day4
-rw-r--r--tests/expected/cal/color-last-day4
-rw-r--r--tests/expected/cal/color-reformation-corner-cases-14
-rw-r--r--tests/expected/cal/color-reformation-corner-cases-24
-rw-r--r--tests/expected/cal/color-reformation-corner-cases-34
-rw-r--r--tests/expected/cal/color-reformation-corner-cases-44
-rw-r--r--tests/expected/cal/color-vertical2
-rw-r--r--tests/expected/cal/color-vertical-week2
-rw-r--r--tests/expected/cal/colorw-first-day-week-numbers4
-rw-r--r--tests/expected/cal/colorw-last-day-week-numbers4
-rw-r--r--tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers4
-rw-r--r--tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers4
-rw-r--r--tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers4
-rw-r--r--tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers4
15 files changed, 44 insertions, 29 deletions
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 09622165a4..c264610671 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -778,27 +778,35 @@ static void cal_output_header(struct cal_month *month, const struct cal_control
char out[FMT_ST_CHARS];
struct cal_month *i;
- cal_enable_color(CAL_COLOR_HEADER);
if (ctl->header_hint || ctl->header_year) {
+ cal_enable_color(CAL_COLOR_HEADER);
for (i = month; i; i = i->next) {
snprintf(out, sizeof(out), "%s", ctl->full_month[i->month - 1]);
center(out, ctl->week_width, i->next == NULL ? 0 : ctl->gutter_width);
}
+ cal_disable_color(CAL_COLOR_HEADER);
+
if (!ctl->header_year) {
fputc('\n', stdout);
+ cal_enable_color(CAL_COLOR_HEADER);
for (i = month; i; i = i->next) {
snprintf(out, sizeof(out), "%04d", i->year);
center(out, ctl->week_width, i->next == NULL ? 0 : ctl->gutter_width);
}
+ cal_disable_color(CAL_COLOR_HEADER);
}
} else {
+ cal_enable_color(CAL_COLOR_HEADER);
for (i = month; i; i = i->next) {
snprintf(out, sizeof(out), "%s %04d", ctl->full_month[i->month - 1], i->year);
center(out, ctl->week_width, i->next == NULL ? 0 : ctl->gutter_width);
}
+ cal_disable_color(CAL_COLOR_HEADER);
}
fputc('\n', stdout);
+
+ cal_enable_color(CAL_COLOR_HEADER);
for (i = month; i; i = i->next) {
if (ctl->weektype) {
if (ctl->julian)
@@ -821,20 +829,25 @@ 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 */
+ cal_enable_color(CAL_COLOR_HEADER);
printf("%*s", (int)ctl->day_width + 1, "");
+ cal_disable_color(CAL_COLOR_HEADER);
if (ctl->header_hint || ctl->header_year) {
+ cal_enable_color(CAL_COLOR_HEADER);
for (m = month; m; m = m->next) {
snprintf(out, sizeof(out), "%s", ctl->full_month[m->month - 1]);
left(out, month_width, ctl->gutter_width);
}
+ cal_disable_color(CAL_COLOR_HEADER);
+
if (!ctl->header_year) {
fputc('\n', stdout);
+ cal_enable_color(CAL_COLOR_HEADER);
/* Padding for the weekdays */
printf("%*s", (int)ctl->day_width + 1, "");
@@ -842,15 +855,17 @@ static void cal_vert_output_header(struct cal_month *month,
snprintf(out, sizeof(out), "%04d", m->year);
left(out, month_width, ctl->gutter_width);
}
+ cal_disable_color(CAL_COLOR_HEADER);
}
} else {
+ cal_enable_color(CAL_COLOR_HEADER);
for (m = month; m; m = m->next) {
snprintf(out, sizeof(out), "%s %04d", ctl->full_month[m->month - 1], m->year);
left(out, month_width, ctl->gutter_width);
}
+ cal_disable_color(CAL_COLOR_HEADER);
}
- cal_disable_color(CAL_COLOR_HEADER);
fputc('\n', stdout);
}
diff --git a/tests/expected/cal/color-first-day b/tests/expected/cal/color-first-day
index 229681d6aa..f0a836dc1b 100644
--- a/tests/expected/cal/color-first-day
+++ b/tests/expected/cal/color-first-day
@@ -1,5 +1,5 @@
- January 0001
-Su Mo Tu We Th Fr Sa
+ January 0001 
+Su Mo Tu We Th Fr Sa
 [ 1
 2 3 4 5 6 7 8
 9 10 11 12 13 14 15
diff --git a/tests/expected/cal/color-last-day b/tests/expected/cal/color-last-day
index b7020ab3ff..622839167d 100644
--- a/tests/expected/cal/color-last-day
+++ b/tests/expected/cal/color-last-day
@@ -1,5 +1,5 @@
- 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
+ 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
diff --git a/tests/expected/cal/color-reformation-corner-cases-1 b/tests/expected/cal/color-reformation-corner-cases-1
index af9e2bd81a..56448187e5 100644
--- a/tests/expected/cal/color-reformation-corner-cases-1
+++ b/tests/expected/cal/color-reformation-corner-cases-1
@@ -1,5 +1,5 @@
- September 1752
-Su Mo Tu We Th Fr Sa
+ 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 75402e99a9..afe0f864a5 100644
--- a/tests/expected/cal/color-reformation-corner-cases-2
+++ b/tests/expected/cal/color-reformation-corner-cases-2
@@ -1,5 +1,5 @@
- September 1752
-Su Mo Tu We Th Fr Sa
+ 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 75402e99a9..afe0f864a5 100644
--- a/tests/expected/cal/color-reformation-corner-cases-3
+++ b/tests/expected/cal/color-reformation-corner-cases-3
@@ -1,5 +1,5 @@
- September 1752
-Su Mo Tu We Th Fr Sa
+ 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 dbf47a9085..52dd9ce97e 100644
--- a/tests/expected/cal/color-reformation-corner-cases-4
+++ b/tests/expected/cal/color-reformation-corner-cases-4
@@ -1,5 +1,5 @@
- September 1752
-Su Mo Tu We Th Fr Sa
+ 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 f4ffac6a5d..0d7e2596b2 100644
--- a/tests/expected/cal/color-vertical
+++ b/tests/expected/cal/color-vertical
@@ -1,4 +1,4 @@
- February 2023 
+ February 2023 
Su  5 12 19 26
Mo  6 13 20 27
Tu  7 14 21 28
diff --git a/tests/expected/cal/color-vertical-week b/tests/expected/cal/color-vertical-week
index 7060361853..dfaad2b771 100644
--- a/tests/expected/cal/color-vertical-week
+++ b/tests/expected/cal/color-vertical-week
@@ -1,4 +1,4 @@
- February 2023 
+ February 2023 
Su  5 12 19 26
Mo  6 13 20 27
Tu  7 14 21 28
diff --git a/tests/expected/cal/colorw-first-day-week-numbers b/tests/expected/cal/colorw-first-day-week-numbers
index f3117d89b2..f1fb66f9a9 100644
--- a/tests/expected/cal/colorw-first-day-week-numbers
+++ b/tests/expected/cal/colorw-first-day-week-numbers
@@ -1,5 +1,5 @@
- January 0001
- Su Mo Tu We Th Fr Sa
+ 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
diff --git a/tests/expected/cal/colorw-last-day-week-numbers b/tests/expected/cal/colorw-last-day-week-numbers
index dd081fdfc6..ddf8f54b22 100644
--- a/tests/expected/cal/colorw-last-day-week-numbers
+++ b/tests/expected/cal/colorw-last-day-week-numbers
@@ -1,5 +1,5 @@
- 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
+ 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
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 a94a28e549..9144c72db9 100644
--- a/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers
+++ b/tests/expected/cal/colorw-reformation-corner-cases-1-week-numbers
@@ -1,5 +1,5 @@
- September 1752
- Su Mo Tu We Th Fr Sa
+ 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 701eb91fe8..88955a4935 100644
--- a/tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers
+++ b/tests/expected/cal/colorw-reformation-corner-cases-2-week-numbers
@@ -1,5 +1,5 @@
- September 1752
- Su Mo Tu We Th Fr Sa
+ 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 701eb91fe8..88955a4935 100644
--- a/tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers
+++ b/tests/expected/cal/colorw-reformation-corner-cases-3-week-numbers
@@ -1,5 +1,5 @@
- September 1752
- Su Mo Tu We Th Fr Sa
+ 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 e35901a0f3..fc4fb46946 100644
--- a/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers
+++ b/tests/expected/cal/colorw-reformation-corner-cases-4-week-numbers
@@ -1,5 +1,5 @@
- September 1752
- Su Mo Tu We Th Fr Sa
+ 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