Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Brick.Widgets.Calendar
Description
This module provides a month calendar widget for Brick applications.
Usage
The widget provides:
- A render function to display the calendar
- A set of actions for navigation (moveUp, moveDown, etc.)
- Configuration options
Applications should connect the provided actions to keyboard events in their event handlers. Common navigation patterns include:
- Arrow keys: Use moveUp, moveDown, moveLeft, moveRight to navigate between days
- Month navigation: Use setMonthBefore, setMonthAfter to change months
- Year navigation: Use setYearBefore, setYearAfter to change years
When a navigation action is applied and no day is selected, the first day of the current month will be selected. When navigating between days, if moving to a date outside the current month, the view will automatically shift to that month.
Synopsis
- renderCalendar :: Ord n => CalendarState n -> Widget n
- data CalendarState n = CalendarState {
- calYear :: Integer
- calMonth :: Int
- calSelectedDay :: Maybe Day
- calConfig :: CalendarConfig
- calendarName :: CalendarResource -> n
- moveUp :: CalendarState n -> CalendarState n
- moveDown :: CalendarState n -> CalendarState n
- moveLeft :: CalendarState n -> CalendarState n
- moveRight :: CalendarState n -> CalendarState n
- setMonthBefore :: CalendarState n -> CalendarState n
- setMonthAfter :: CalendarState n -> CalendarState n
- setYearBefore :: CalendarState n -> CalendarState n
- setYearAfter :: CalendarState n -> CalendarState n
- handleCalendarEvent :: BrickEvent n e -> EventM n (CalendarState n) ()
- data CalendarConfig = CalendarConfig {
- _weekStart :: DayOfWeek
- _dayLabelStyle :: DayLabelStyle
- _showDayLabels :: Bool
- _outsideMonthDisplay :: OutsideMonthDisplay
- _dateFormat :: DateFormat
- data DayLabelStyle
- data OutsideMonthDisplay
- = Hide
- | ShowDimmed
- | ShowNormal
- defaultCalendarConfig :: CalendarConfig
- weekStart :: Lens' CalendarConfig DayOfWeek
- dayLabelStyle :: Lens' CalendarConfig DayLabelStyle
- showDayLabels :: Lens' CalendarConfig Bool
- outsideMonthDisplay :: Lens' CalendarConfig OutsideMonthDisplay
- data CalendarResource
- getFirstDayOfMonth :: Integer -> Int -> DayOfWeek
- getDayLabel :: DayLabelStyle -> DayOfWeek -> Text
- getMonthLabel :: CalendarConfig -> Integer -> Int -> Text
- getWeekDayLabels :: CalendarConfig -> [Text]
- formatDate :: CalendarConfig -> Day -> Text
- defaultCalendarAttrMap :: AttrMap
Render
renderCalendar :: Ord n => CalendarState n -> Widget n Source #
Render a month calendar widget
data CalendarState n Source #
The state of the calendar widget. Make this part of your application state.
Constructors
CalendarState | |
Fields
|
Actions
moveUp :: CalendarState n -> CalendarState n Source #
moveDown :: CalendarState n -> CalendarState n Source #
moveLeft :: CalendarState n -> CalendarState n Source #
moveRight :: CalendarState n -> CalendarState n Source #
setMonthBefore :: CalendarState n -> CalendarState n Source #
setMonthAfter :: CalendarState n -> CalendarState n Source #
setYearBefore :: CalendarState n -> CalendarState n Source #
setYearAfter :: CalendarState n -> CalendarState n Source #
Pre-built event handler
handleCalendarEvent :: BrickEvent n e -> EventM n (CalendarState n) () Source #
Configuration
data CalendarConfig Source #
Configuration for the calendar widget.
Constructors
CalendarConfig | |
Fields
|
Instances
Show CalendarConfig Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods showsPrec :: Int -> CalendarConfig -> ShowS # show :: CalendarConfig -> String # showList :: [CalendarConfig] -> ShowS # | |
Eq CalendarConfig Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods (==) :: CalendarConfig -> CalendarConfig -> Bool # (/=) :: CalendarConfig -> CalendarConfig -> Bool # |
data DayLabelStyle Source #
Style for displaying day labels.
Constructors
SingleChar | Use single characters: S M T W T F S |
DoubleChar | Use two characters: Su Mo Tu We Th Fr Sa |
DistinctInitials | Use single chars with Th for Thursday: S M T W Th F S |
Instances
Show DayLabelStyle Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods showsPrec :: Int -> DayLabelStyle -> ShowS # show :: DayLabelStyle -> String # showList :: [DayLabelStyle] -> ShowS # | |
Eq DayLabelStyle Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods (==) :: DayLabelStyle -> DayLabelStyle -> Bool # (/=) :: DayLabelStyle -> DayLabelStyle -> Bool # |
data OutsideMonthDisplay Source #
How to display days outside the current month.
Constructors
Hide | Don't show days outside current month |
ShowDimmed | Show days outside month with dimmed styling |
ShowNormal | Show days outside month with normal styling |
Instances
Show OutsideMonthDisplay Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods showsPrec :: Int -> OutsideMonthDisplay -> ShowS # show :: OutsideMonthDisplay -> String # showList :: [OutsideMonthDisplay] -> ShowS # | |
Eq OutsideMonthDisplay Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods (==) :: OutsideMonthDisplay -> OutsideMonthDisplay -> Bool # (/=) :: OutsideMonthDisplay -> OutsideMonthDisplay -> Bool # |
defaultCalendarConfig :: CalendarConfig Source #
Default calendar configuration.
Lenses
Resource name
data CalendarResource Source #
Resource name for calendar widget elements.
Constructors
CalendarDay Int Int Int | Resource for a day (year, month, day) |
CalendarMonth Int Int | Resource for month header (year, month) |
CalendarPrev | Resource for previous month button |
CalendarNext | Resource for next month button |
Instances
Show CalendarResource Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods showsPrec :: Int -> CalendarResource -> ShowS # show :: CalendarResource -> String # showList :: [CalendarResource] -> ShowS # | |
Eq CalendarResource Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods (==) :: CalendarResource -> CalendarResource -> Bool # (/=) :: CalendarResource -> CalendarResource -> Bool # | |
Ord CalendarResource Source # | |
Defined in Brick.Widgets.Calendar.Internal.Core Methods compare :: CalendarResource -> CalendarResource -> Ordering # (<) :: CalendarResource -> CalendarResource -> Bool # (<=) :: CalendarResource -> CalendarResource -> Bool # (>) :: CalendarResource -> CalendarResource -> Bool # (>=) :: CalendarResource -> CalendarResource -> Bool # max :: CalendarResource -> CalendarResource -> CalendarResource # min :: CalendarResource -> CalendarResource -> CalendarResource # |
Utilities
getFirstDayOfMonth :: Integer -> Int -> DayOfWeek Source #
Get the day of week for the first day of the given month
getDayLabel :: DayLabelStyle -> DayOfWeek -> Text Source #
Get the label for a day based on the day of week and label style
getMonthLabel :: CalendarConfig -> Integer -> Int -> Text Source #
Get the month label as text (e.g., "Apr 2025")
getWeekDayLabels :: CalendarConfig -> [Text] Source #
Get the labels for all days of the week based on configuration
formatDate :: CalendarConfig -> Day -> Text Source #
Format a date as text using the configured format
defaultCalendarAttrMap :: AttrMap Source #
Attribute map for calendar widgets.