class RatatuiRuby::Widgets::Calendar
Displays a monthly calendar grid.
Dates are complex. Rendering them in a grid requires calculation of leap years, month lengths, and day-of-week offsets. Use this widget to skip the boilerplate.
This widget renders a standard monthly view. It highlights the current date. It structures time.
Use it for date pickers, schedulers, or logs.
Example
Run the interactive demo from the terminal:
ruby examples/widget_calendar/app.rb
Attributes
Optional wrapping block.
Style for the days.
A Hash mapping Dates to Styles for event highlighting. Keys must be ‘Date` objects (or objects responding to `day`, `month`, `year`). Values must be `Style` objects.
Style for the month name header.
The month to display (1–12).
Style for dates from surrounding months. If nil, surrounding dates are hidden.
Whether to show the weekday header (Mon, Tue, etc.).
The year to display (Integer).
Public Class Methods
Source
# File lib/ratatui_ruby/widgets/calendar.rb, line 73 def initialize(year:, month:, events: {}, default_style: nil, header_style: nil, block: nil, show_weekdays_header: true, show_surrounding: nil, show_month_header: false) super( year: Integer(year), month: Integer(month), events:, default_style:, header_style:, block:, show_weekdays_header:, show_surrounding:, show_month_header: ) end
Creates a new Calendar.
- year
-
Integer.
- month
-
Integer.
- events
-
Hash<Date, Style>. Optional.
default_styleheader_style- block
show_weekdays_header-
Boolean. Whether to show the weekday header.
show_surrounding
