The branch main has been updated by phk:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=49224311fe6d850e5c25a7e79328c87029df6be8

commit 49224311fe6d850e5c25a7e79328c87029df6be8
Author:     Poul-Henning Kamp <p...@freebsd.org>
AuthorDate: 2024-12-12 07:22:14 +0000
Commit:     Poul-Henning Kamp <p...@freebsd.org>
CommitDate: 2024-12-12 07:22:14 +0000

    ncal: make -h toggle highlighting of today.
---
 usr.bin/ncal/ncal.1 |  3 ++-
 usr.bin/ncal/ncal.c | 14 ++++++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/usr.bin/ncal/ncal.1 b/usr.bin/ncal/ncal.1
index 8ece31b79cc1..2c7c82fd318e 100644
--- a/usr.bin/ncal/ncal.1
+++ b/usr.bin/ncal/ncal.1
@@ -79,7 +79,8 @@ the current month is displayed.
 The options are as follows:
 .Bl -tag -width indent
 .It Fl h
-Turns off highlighting of today.
+Toggle highlighting of today.
+By default highlighting is enabled if stdout is a TTY.
 .It Fl J
 Display Julian Calendar, if combined with the
 .Fl e
diff --git a/usr.bin/ncal/ncal.c b/usr.bin/ncal/ncal.c
index 2829caf8a6a0..dc50dd60bf0b 100644
--- a/usr.bin/ncal/ncal.c
+++ b/usr.bin/ncal/ncal.c
@@ -158,7 +158,7 @@ static char jdaystr[] = "       1   2   3   4   5   6   7   
8   9"
                        " 350 351 352 353 354 355 356 357 358 359"
                        " 360 361 362 363 364 365 366";
 
-static int flag_nohighlight;   /* user doesn't want a highlighted today */
+static int flag_highlight;     /* highlighted today */
 static int flag_weeks;         /* user wants number of week */
 static int nswitch;            /* user defined switch date */
 static int nswitchb;           /* switch date for backward compatibility */
@@ -216,7 +216,7 @@ main(int argc, char *argv[])
        int     before, after;
        const char    *locale;          /* locale to get country code */
 
-       flag_nohighlight = 0;
+       flag_highlight = isatty(STDOUT_FILENO);
        flag_weeks = 0;
        flag_monday = false;
 
@@ -299,7 +299,7 @@ main(int argc, char *argv[])
                        flag_highlightdate = optarg;
                        break;
                case 'h':
-                       flag_nohighlight = 1;
+                       flag_highlight = !flag_highlight;
                        break;
                case 'e':
                        if (flag_backward)
@@ -834,8 +834,7 @@ mkmonthr(int y, int m, int jd_flag, struct monthlines 
*mlines)
                                        dt.d = j - jan1 + 1;
                                else
                                        sdater(j, &dt);
-                               if (j == highlightdate && !flag_nohighlight
-                                && isatty(STDOUT_FILENO))
+                               if (j == highlightdate && flag_highlight)
                                        highlight(mlines->lines[i] + k,
                                            ds + dt.d * dw, dw, &l);
                                else
@@ -942,8 +941,7 @@ mkmonthb(int y, int m, int jd_flag, struct monthlines 
*mlines)
                                        dt.d = j - jan1 + 1;
                                else
                                        sdateb(j, &dt);
-                               if (j == highlightdate && !flag_nohighlight
-                                && isatty(STDOUT_FILENO))
+                               if (j == highlightdate && flag_highlight)
                                        highlight(mlines->lines[i] + k,
                                            ds + dt.d * dw, dw, &l);
                                else
@@ -1143,7 +1141,7 @@ highlight(char *dst, char *src, int len, int *extralen)
         * This check is not necessary, should have been handled before calling
         * this function.
         */
-       if (flag_nohighlight) {
+       if (!flag_highlight) {
                memcpy(dst, src, len);
                return;
        }

Reply via email to