`cal` (but better!) in rust

Related tags

Command-line cal-rs
Overview

cal-rs

cal-rs is a simple command-line calendar application written in Rust. It allows you to display a calendar for a specific month and year, with options to customize the first day of the week.

     April 2024     
Mo Tu We Th Fr Sa Su
 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               

Features

  • Display a calendar for a given month and year
  • Customize the first day of the week (Sunday or Monday)
  • On macOS the first day of the week is determined by the system preference (via System Settings > General > Language & Region > First day of week)
  • Automatically defaults to the current month and year if not specified
  • Supports simplified date inputs like Q1, FY2024, FY24Q2, FY24, FYQ2, and more.
  • Supports two digit year for ease of use (assumes current century)
  • Supports the concept of fiscal years (currently hardcoded to those that run July through June)

Installation

If you use homebrew, you can install via:

brew install rwjblue/tap/cal

Otherwise, you can install by manually cloning and running cargo install.

Usage

Usage: cal [OPTIONS] [DATE_INPUT]

Arguments:
  [DATE_INPUT]
          Display a specific year, quarter, or month.
          
          Examples: 2024, 24, Q1, 24Q1, FY2024, FY24, FYQ2, FY2024Q1, FY24Q1
          
          Disables usage of `--year` and `--month` flags.

Options:
  -f, --first-day-of-week <FIRST_DAY_OF_WEEK>
          Sets the first day of the week. If not set, defaults to the system preference
          
          [possible values: sunday, monday]

  -y, --year <YEAR>
          The year to display

  -m, --month <MONTH>
          The month to display

  -A, --months-after <MONTHS_AFTER>
          Display the number of months after the current month

  -B, --months-before <MONTHS_BEFORE>
          Display the number of months before the current month

      --color[=<WHEN>]
          Enable or disable colored output
          
          [default: auto]
          [possible values: always, auto, never]

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

Examples

Display the calendar for the current month:

> cal
     April 2024     
Mo Tu We Th Fr Sa Su
 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               

Display the calendar for the current month, and include one month before and after:

> cal -A 1 -B 1
     March 2024            April 2024             May 2024      
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
             1  2  3   1  2  3  4  5  6  7         1  2  3  4  5
 4  5  6  7  8  9 10   8  9 10 11 12 13 14   6  7  8  9 10 11 12
11 12 13 14 15 16 17  15 16 17 18 19 20 21  13 14 15 16 17 18 19
18 19 20 21 22 23 24  22 23 24 25 26 27 28  20 21 22 23 24 25 26
25 26 27 28 29 30 31  29 30                 27 28 29 30 31      

Display the calendar for the Q2 of the current year:

> cal Q2
     April 2024             May 2024             June 2024      
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7         1  2  3  4  5                  1  2
 8  9 10 11 12 13 14   6  7  8  9 10 11 12   3  4  5  6  7  8  9
15 16 17 18 19 20 21  13 14 15 16 17 18 19  10 11 12 13 14 15 16
22 23 24 25 26 27 28  20 21 22 23 24 25 26  17 18 19 20 21 22 23
29 30                 27 28 29 30 31        24 25 26 27 28 29 30

Display the calendar for the FYQ3 of the current fiscal year:

> cal FYQ4
     April 2024             May 2024             June 2024      
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7         1  2  3  4  5                  1  2
 8  9 10 11 12 13 14   6  7  8  9 10 11 12   3  4  5  6  7  8  9
15 16 17 18 19 20 21  13 14 15 16 17 18 19  10 11 12 13 14 15 16
22 23 24 25 26 27 28  20 21 22 23 24 25 26  17 18 19 20 21 22 23
29 30                 27 28 29 30 31        24 25 26 27 28 29 30

Display the calendar for a specific month and year:

> cal -y 2024 -m 3
     March 2024     
Mo Tu We Th Fr Sa Su
             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

Set the first day of the week to Sunday:

> cal -f sunday
     April 2024     
Su Mo Tu We Th Fr Sa
    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            

Development

This project is primarily a learning exercise for exploring Rust programming. It utilizes several Rust libraries and concepts, including:

  • clap for parsing command-line arguments
  • chrono for date and time handling
  • insta for snapshot testing
  • Rust's module system and project structure
  • Rust's ownership and borrowing system
  • Rust's Option and Result types for handling absence and errors

Feel free to explore the code, suggest improvements, or use it as a reference for your own Rust learning journey!

License

This project is open-source and available under the MIT License.

Comments
  • Add `--color` command line option

    Add `--color` command line option

    Supports auto (default), always, and never. Also includes support for checking FORCE_COLOR environment variable (0 is the same as never, and 1 is the same as always).

    Works towards #2

    opened by rwjblue 0
  • Refactor

    Refactor "today" determination

    Instead of using lazy_static to declare the TODAY static ref, this splits things up so that main defaults to the current date but the new print function accepts a substitute "current date".

    This allows the acceptance tests to be refactored to be much much closer to reality (e.g. they actually go through the args parsing).

    opened by rwjblue 0
  • Add support for positional argument.

    Add support for positional argument.

    Supports a number of calling patterns:

    cal Q3
    cal 24
    cal 24Q2
    cal 2024-Q3
    cal 2024
    cal 2024-01
    cal FY24Q3
    cal FY2024
    cal FY2024Q1
    cal FY2024-Q1
    cal FYQ3
    

    Resolves #7

    opened by rwjblue 0
  • Add support for taking a positional argument

    Add support for taking a positional argument

    Right now, I'd like to support things like:

    • cal Q1 to print Jan, Feb, March of the current year
    • cal FYQ1 to print June, July, August of the current fiscal year
    • cal 2024 to print the full year out
    • cal 2024-02 to be the same as --year 2024 --month 2
    • cal FY2024 to print the full fiscal year out
    • cal FY2024Q4 to print FY2024's Q4
    • cal 2024Q2 to print 2024's calendar Q2
    opened by rwjblue 0
  • Add support for `-A` and `-B` arguments

    Add support for `-A` and `-B` arguments

    ❯ cargo run -- -A 1 -B 1 --first-day-of-week=sunday
         March 2024            April 2024             May 2024      
    Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
                    1  2      1  2  3  4  5  6            1  2  3  4
     3  4  5  6  7  8  9   7  8  9 10 11 12 13   5  6  7  8  9 10 11
    10 11 12 13 14 15 16  14 15 16 17 18 19 20  12 13 14 15 16 17 18
    17 18 19 20 21 22 23  21 22 23 24 25 26 27  19 20 21 22 23 24 25
    24 25 26 27 28 29 30  28 29 30              26 27 28 29 30 31   
    31                                                              
    
    
    ❯ cargo run -- -A 1 -B 1                           
         March 2024            April 2024             May 2024      
    Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
                 1  2  3   1  2  3  4  5  6  7         1  2  3  4  5
     4  5  6  7  8  9 10   8  9 10 11 12 13 14   6  7  8  9 10 11 12
    11 12 13 14 15 16 17  15 16 17 18 19 20 21  13 14 15 16 17 18 19
    18 19 20 21 22 23 24  22 23 24 25 26 27 28  20 21 22 23 24 25 26
    25 26 27 28 29 30 31  29 30                 27 28 29 30 31      
    
    
    

    Closes #1

    opened by rwjblue 0
  • Support

    Support "X days from now"

    Add some command line flags to support seeing X days from now (or other semi natural language system like "x weeks from now", etc) and showing that month with the specific day highlighted.

    opened by rwjblue 0
  • Add support for loading a config file

    Add support for loading a config file

    This could be used for a few different things:

    • Determine the default first day of week (would work on all platforms, instead of the current implementation which only works on macOS)
    • Support specifying custom "holidays" (pairing with #2)
    • Configure automatic -A / -B values (e.g. always print a month before and after the currently displayed month)
    • Support configuring custom date range categories. Imagine being able to create your own idea of FY (e.g. H1).

    Should likely be done in a TOML file around ~/.config/cal/config.toml.

    opened by rwjblue 0
  • Add colorized output support

    Add colorized output support

    Need to think about this one a bit, but having colorized output would be neat.

    Off the top of my head, I think the following might work:

    • Headers (month + year, and day abbreviations) could be green or yellow
    • Weekdays could be "bright white"
    • Weekends could be a light grey color
    opened by rwjblue 0
Owner
Robert Jackson
Robert Jackson
A system clipboard command line tools which inspired by pbcopy & pbpaste but better to use.

rclip A command line tool which supports copy a file contents to the system clipboard or copy the contents of the system clipboard to a file. Install

yahaa 3 May 30, 2022
A better customization password dictionary generator implementation by Rust.

abcdict A better customization password dictionary generator implementation by Rust. Features Cli Faster Customize Rules Build & Installation $> cargo

b23r0 6 Jun 2, 2022
Faster and better alternative to Vtop written in Rust.

Rtop Faster and better alternative to Vtop written in Rust. Work in Progress Features Lightweight < 1MB Responsive UI Sort Process by Memory, CPU Usag

Squitch 7 Nov 18, 2022
A better rust version of pokeget.

pokeget-rs A better rust version of pokeget. Usage pokeget <pokemon> for more info, run pokeget --help Also, if you're using pokeget in your bashrc, t

Tal 11 Aug 14, 2023
"Better" tab and stack navigation for Sway WM.

sway_bfocus "Better" tab and stack navigation for Sway WM. Proof of concept. This program lets you create one set of keybinds exclusively for cycling

null 42 Oct 23, 2022
nothing::[Probably] is a better [Option].

nothing::[Probably] is a better [Option].

Btwiuse Arch 0 Sep 22, 2022
A localized open-source AI server that is better than ChatGPT.

??AI00 RWKV Server English | 中文 | 日本語 AI00 RWKV Server is an inference API server based on the RWKV model. It supports VULKAN inference acceleration a

顾真牛 142 Aug 23, 2023
World's first, but possibly worst, blinky for the pico in Rust

pico-blink-rs Running Rust code on the Raspberry Pi Pico Booting The RP2040 has external QSPI flash. There is an internal mask-ROM bootloader which ca

rp-rs 129 Dec 24, 2022
du + rust = dust. Like du but more intuitive.

Dust du + rust = dust. Like du but more intuitive. Why Because I want an easy way to see where my disk is being used. Demo Install Cargo cargo install

andy.boot 5.4k Jan 4, 2023
Rmatrix is similar to the cmatrix, but it wrote it in Rust.

Rmatrix is similar to the cmatrix, but it wrote it in Rust. Get up to 75% performance improvement compared to cmatrix.

null 8 Apr 8, 2022
A cli based pastebin in Rust, but very insecure

pasta A cli based pastebin in Rust, but very insecure Use nightly toolchain to build rustup override set nightly When this program is running, you can

Snehit Sah 3 Mar 25, 2022
A trash-cli copy, but this time in Rust.

trash-rs A trash-cli copy, but this time in Rust. TODO Deletion Relative paths * functionality List files Include in Metadata: Original directory Date

null 1 Nov 23, 2021
Hilbert curve but in Rust for j2kun/pmpf-code

About this code This repository contains code for matrix multiplication using Hilbert Curves. The original code (2) is part of @j2kun's code for his n

Christoph Siedentop 1 Jan 10, 2022
Just a UNIX's cat copy, but less bloated and in Rust.

RAT The opposite of UNIX's cat, less bloated, and in Rust. About the project The idea of this CLI is "A CLI program that is basically UNIX's cat comma

Renan Fernandes 2 Mar 5, 2022
Store your transfer.sh links, so you can remember them later and know when they will expire, but now written in Rust.

Transfer.sh helper Rusted The idea of the script is to store your transfer.sh links and simplify its usage, so you can remember them later and know wh

Reinaldo Rozato Junior 10 Nov 30, 2022
Like Lua, but in Rust, and different

AirScript It's like Lua, but in Rust, and different. Introduction AirScript is a dynamically typed, interpreted language inspired by Lua and written i

David Delassus 5 Jun 28, 2022
Rust, but longer

Rusticle Do Rust's short keywords confuse you? Are you tired of Rust not being verbose enough? Or worrying you are not using your new shiny mechanical

Federico Damián Schonborn 2 Oct 22, 2022
Simple but convenient CLI-based Matrix client app for sending and receiving (in Rust)

matrix-commander-rs simple but convenient CLI-based Matrix client app for sending and receiving Help create this Rust program! This project is current

null 19 Dec 30, 2022
Gamehacking.Academy but made with Rust

Just the programs etc. i made following the lessons on gamehacking.academy but instead of using the cpp i tried translating it to Rust

Sara 9 Nov 28, 2022