Commit Graph

20 Commits

Author SHA1 Message Date
Karol Baraniecki
94e14bbe65 cal: Get default week start day from Calendar
Making it configurable in system settings :^)
The --start-day option can still overwrite this global default.

This change makes it no longer possible to use unveil: as we have
to load the Calendar config file, which might be in a dynamic location.

It's also neccessary to add `cpath` to the pledge, as opening a
nonexistent config file with Core::ConfigFile::open_for_app creates it.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
114da3a275 cal: Make start of the week configurable
Making all the other parts of the world happier :^)

Add a `--starting-day` (`-s`) option to be compatible with GNU cal,
which has a similar option. The GNU option takes allows passing either
an int or a day name. Let's do something similar using weekdays we
already have in AK/DateConstants.h.

Also add myself to the copyright header, as by now I've modified most of
the lines in this file.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
b4bec4dd2f cal: Pad days on the left with spaces instead of zeroes
I think this looks a lot prettier:
          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 29 30 31

than that:
         01 02 03 04
05 06 07 08 09 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
2023-04-25 01:54:53 -06:00
Karol Baraniecki
af2a606f25 cal: Only show year next to each month in one-month-mode
Additionally rename a loop variable in serenity_main() because
after introducing the `Header` enum IMO it's less readable with `i`.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
a3e6b18efc cal: Fix width calculation by not leaving an extra space at month's end
Do this by constructing month rows from a Vector of Strings.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
1d47d5bb8b cal: Display month names
For now let's use them from AK/DateConstants.h, in accordance with the
FIXME those propably should be provided by the locale.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
79f5fb798a cal: Use global string widths instead of hardcoding them
...in the format strings. Additionally, get rid of magic numbers,
and make them `constexpr`.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
905f2ca152 cal: Center the month-year text
For now this only has an effect when displaying two-digit years, but
when month names get implemented this will be helpful.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
119dc042ab 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".
2023-04-25 01:54:53 -06:00
Karol Baraniecki
71cc35ae40 cal: Rewrite cal to use new Strings and handle errors
This additionally fixes a couple of code quality issues in `cal`,
removes reading from unset variables and writing to variables which are
never read.
2023-04-25 01:54:53 -06:00
Karol Baraniecki
812225a70c 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
2023-04-25 01:54:53 -06:00
Karol Baraniecki
b57c718418 cal: Don't accept passing a [day]
Every other cal implementation just highlights the current day instead
of letting you specify a custom one to highlight. It doesn't seem to be
that useful, and is currently broken - no day gets highlighted at all,
because the `target_day` global is never written to.

Moreover, this complicates parsing the arguments. This commit also fixes
parsing a case where just a year is provided to `cal` - for example `cal
2023`.
2023-04-25 01:54:53 -06:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Timothy Flynn
bcf4ec9c61 Userland: Add promises to programs that will read /etc/timezone
This will require unveiling /etc/timezone itself for reading, as well as
the rpath pledge promise.
2022-01-23 12:48:26 +00:00
David Lindbom
9d7a862509 cal: Add unveil and pledge promises 2022-01-21 02:00:53 +01:00
Kenneth Myhra
6b6d7286b5 cal: Port to LibMain :^) 2021-12-11 15:10:42 -08:00
Linus Groh
f5c35fccca Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
Linus Groh
304752fccb cal: Remove unused variable declarations 2021-05-31 18:02:48 +01:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
ececac65c2 Userland: Move command-line utilities to Userland/Utilities/ 2021-01-12 12:04:09 +01:00