mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:47:35 +00:00
cal: Correctly identify current day
This fixes cal not highlighting the current day. After this commit `cal` will show something like this among its output for the 23rd day of the month 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23*24 25 26 27 28
This commit is contained in:
parent
b57c718418
commit
812225a70c
1 changed files with 7 additions and 9 deletions
|
@ -19,10 +19,9 @@ int const column_width = 22;
|
||||||
char print_buffer[line_width * line_count];
|
char print_buffer[line_width * line_count];
|
||||||
char temp_buffer[line_width * 8];
|
char temp_buffer[line_width * 8];
|
||||||
|
|
||||||
int target_day;
|
|
||||||
|
|
||||||
int current_year;
|
int current_year;
|
||||||
int current_month;
|
int current_month;
|
||||||
|
int current_day;
|
||||||
|
|
||||||
static void append_to_print(char* buffer, int row, int column, char* text)
|
static void append_to_print(char* buffer, int row, int column, char* text)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +53,7 @@ static void insert_month_to_print(int column, int month, int year)
|
||||||
if (i - 1 < first_day_of_week_for_month) {
|
if (i - 1 < first_day_of_week_for_month) {
|
||||||
last_written_chars += sprintf(temp_buffer + last_written_chars, " ");
|
last_written_chars += sprintf(temp_buffer + last_written_chars, " ");
|
||||||
} else {
|
} else {
|
||||||
if (year == current_year && month == current_month && target_day == day_to_print) {
|
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 *.
|
// 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.
|
// However, doing that messes up the layout.
|
||||||
last_written_chars += sprintf(temp_buffer + last_written_chars, "%2d*", day_to_print);
|
last_written_chars += sprintf(temp_buffer + last_written_chars, "%2d*", day_to_print);
|
||||||
|
@ -106,6 +105,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
auto* tm = localtime(&now);
|
auto* tm = localtime(&now);
|
||||||
|
current_year = tm->tm_year + 1900;
|
||||||
|
current_month = tm->tm_mon + 1;
|
||||||
|
current_day = tm->tm_mday;
|
||||||
|
|
||||||
// Hack: workaround one value parsing as a month
|
// Hack: workaround one value parsing as a month
|
||||||
if (month && !year) {
|
if (month && !year) {
|
||||||
|
@ -116,13 +118,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
bool year_mode = !month && year;
|
bool year_mode = !month && year;
|
||||||
|
|
||||||
if (!year)
|
if (!year)
|
||||||
year = tm->tm_year + 1900;
|
year = current_year;
|
||||||
if (!month)
|
if (!month)
|
||||||
month = tm->tm_mon + 1;
|
month = current_month;
|
||||||
|
|
||||||
// FIXME: Those are really _target_ year and month values - not current ones
|
|
||||||
current_year = year;
|
|
||||||
current_month = month;
|
|
||||||
|
|
||||||
clean_buffers();
|
clean_buffers();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue