From 119dc042ab9f53db10d91052003af8e126277431 Mon Sep 17 00:00:00 2001 From: Karol Baraniecki Date: Sun, 12 Mar 2023 09:46:58 +0100 Subject: [PATCH] cal: Mark the current day as inverted text ...instead of putting a star `*` next to it. This makes `cal`s output much prettier, and gets rid of one FIXME. :^) Don't use the escape sequence from the deleted FIXME - \e[30;47m would set the background to white and foreground to black - which presumably wouldn't do much on a light-theme terminal. Instead use \e[7m which sets the color as "inverted". --- Base/usr/share/man/man1/cal.md | 2 ++ Userland/Utilities/cal.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Base/usr/share/man/man1/cal.md b/Base/usr/share/man/man1/cal.md index 175fa05cb0..b3bb8cbbf4 100644 --- a/Base/usr/share/man/man1/cal.md +++ b/Base/usr/share/man/man1/cal.md @@ -13,6 +13,8 @@ $ cal [[month] year] This program displays a simple calendar. If no arguments are specified, the current month is displayed with the current day highlighted. An overview of a whole year is displayed when a `year` is passed without a `month`. +The current day is always highlighted. + Days, months and years are specified with numbers. Week starts at Sunday. ## Examples diff --git a/Userland/Utilities/cal.cpp b/Userland/Utilities/cal.cpp index cd73381f87..7340d6cd0d 100644 --- a/Userland/Utilities/cal.cpp +++ b/Userland/Utilities/cal.cpp @@ -13,6 +13,9 @@ #include #include +#define ANSI_INVERT_OUTPUT "\e[7m" +#define ANSI_RESET_OUTPUT "\e[0m" + int const line_width = 70; int const line_count = 8; int const column_width = 22; @@ -41,9 +44,7 @@ static ErrorOr> month_lines_to_print(int month, int year) row.append(" "sv); } else { if (year == current_year && month == current_month && day_to_print == current_day) { - // FIXME: To replicate Unix cal it would be better to use "\x1b[30;47m%2d\x1b[0m " in here instead of *. - // However, doing that messes up the layout. - row.appendff("{:02}*", day_to_print); + row.appendff(ANSI_INVERT_OUTPUT "{:02}" ANSI_RESET_OUTPUT " ", day_to_print); } else { row.appendff("{:02} ", day_to_print); }