]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: properly colorize the week number in vertical output.
authorKarel Zak <kzak@redhat.com>
Mon, 20 May 2024 13:54:37 +0000 (15:54 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 May 2024 13:54:37 +0000 (15:54 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/cal.c

index 65517512e960fdffc4795ca20225841f1d921c3a..527dc7a86cc1c4ad879d85e0bfede38829f7f8bc 100644 (file)
@@ -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