mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
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".
This commit is contained in:
parent
71cc35ae40
commit
119dc042ab
2 changed files with 6 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include <LibMain/Main.h>
|
||||
#include <time.h>
|
||||
|
||||
#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<Vector<String>> 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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue