calendar

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultActiveColor = gloss.AdaptiveColor{Light: "#3E5AFA", Dark: "#7DD6FA"}

	// ╭───┬
	// │Sun│
	// ├───┼
	DefaultLeftHeaderBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "╭",
		TopRight:    "┬",
		BottomLeft:  "├",
		BottomRight: "┼",
	}
	//  ┬───┬
	//  │Mon│
	//  ┼───┼
	DefaultMiddleHeaderBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "┬",
		TopRight:    "┬",
		BottomLeft:  "┼",
		BottomRight: "┼",
	}
	//  ┬───╮
	//  │Sat│
	//  ┼───┤
	DefaultRightHeaderBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "┬",
		TopRight:    "╮",
		BottomLeft:  "┼",
		BottomRight: "┤",
	}

	//  ├───┼
	//  │12 │
	//  ├───┼
	DefaultMiddleLeftDayBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "├",
		TopRight:    "┼",
		BottomLeft:  "├",
		BottomRight: "┼",
	}
	//  ┼───┼
	//  │12 │
	//  ┼───┼
	DefaultMiddleDayBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "┼",
		TopRight:    "┼",
		BottomLeft:  "┼",
		BottomRight: "┼",
	}

	//  ┼───┤
	//  │12 │
	//  ┼───┤
	DefaultMiddleRightDayBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "┼",
		TopRight:    "┤",
		BottomLeft:  "┼",
		BottomRight: "┤",
	}

	//  ├───┼
	//  │12 │
	//  ╰───┴
	DefaultBottomLeftDayBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "├",
		TopRight:    "┼",
		BottomLeft:  "╰",
		BottomRight: "┴",
	}
	//  ┼───┼
	//  │12 │
	//  ┴───┴
	DefaultBottomDayBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "┼",
		TopRight:    "┼",
		BottomLeft:  "┴",
		BottomRight: "┴",
	}

	//  ┼───┤
	//  │12 │
	//  ┴───╯
	DefaultBottomRightDayBorder = gloss.Border{
		Top:         "─",
		Bottom:      "─",
		Left:        "│",
		Right:       "│",
		TopLeft:     "┼",
		TopRight:    "┤",
		BottomLeft:  "┴",
		BottomRight: "╯",
	}
)

Functions

func CalendarRowsInMonth

func CalendarRowsInMonth(year int, month time.Month, startOfWeek time.Weekday) int

CalendarRowsInMonth calculates the number of calendar rows for a month.

func DaysInMonth

func DaysInMonth(year int, month time.Month) int

DaysInMonth calculates the number of days in a given month and year.

func FirstWeekdayOfMonth

func FirstWeekdayOfMonth(year int, month time.Month) time.Weekday

FirstWeekdayOfMonth calculates the weekday of the first day of the month.

Types

type ActiveDateMsg

type ActiveDateMsg struct {
	// The day to update
	Date time.Time
}

ActiveDateMsg notifies to other models which date is set as the active date.

type DateStyles

type DateStyles struct {
	// Width of the date block
	Width int

	// Height of the date block
	Height int

	// Date number style
	NumberStyle gloss.Style

	ActiveNumberStyle gloss.Style

	// Contents style
	BodyStyle gloss.Style
}

Styles for date block rendering.

func DefaultDateStyles

func DefaultDateStyles() DateStyles

DefaultStyles provides default styles for the date block.

type DayContentMsg

type DayContentMsg struct {
	// The day to update
	Date time.Time

	// The day model
	Content tea.Model
}

DayContentMsg enables updates for the content of a single day.

type KeyMap

type KeyMap struct {
	Left  key.Binding
	Right key.Binding
	Up    key.Binding
	Down  key.Binding
}

KeyMap contains relevant keys for tab navigation.

func DefaultMonthKeyMap

func DefaultMonthKeyMap() KeyMap

DefaultMonthKeyMap contains default key mappings for monthly navigation.

func DefaultWeekKeyMap

func DefaultWeekKeyMap() KeyMap

DefaultWeekKeyMap contains default key mappings for weekly navigation.

type MonthModel

type MonthModel struct {
	// contains filtered or unexported fields
}

MonthModel represents a full calendar month.

func NewMonth

func NewMonth(year int, month time.Month) MonthModel

NewMonth creates a new MonthModel.

func (MonthModel) Init

func (m MonthModel) Init() tea.Cmd

Init the MonthModel.

func (MonthModel) StartOfFirstFullWeek

func (m MonthModel) StartOfFirstFullWeek() time.Time

StartOfFirstFullWeek calculates the first day of the first full week of the month.

func (MonthModel) StartOfWeek

func (m MonthModel) StartOfWeek(weekday time.Weekday) MonthModel

StartOfWeek sets the first day of a week.

func (MonthModel) Styles

func (m MonthModel) Styles(styles MonthStyles) MonthModel

Styles sets custom styling.

func (MonthModel) Title

func (m MonthModel) Title(includeYear bool) string

Title generates a title for the calendar that may be used during rendering.

func (MonthModel) Update

func (m MonthModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update the MonthModel.

func (MonthModel) View

func (m MonthModel) View() string

View renders the MonthModel.

func (MonthModel) ViewDay

func (m MonthModel) ViewDay(weekday time.Weekday, day int, body string, lastRow bool) string

ViewDay renders a single day.

If zero is passed in for the day, an empty date block will be rendered.

func (MonthModel) ViewHeaders

func (m MonthModel) ViewHeaders() string

ViewHeaders renders the weekday headers.

func (MonthModel) ViewWeeks

func (m MonthModel) ViewWeeks() string

ViewWeeks renders the calendar main block.

func (MonthModel) Weekdays

func (m MonthModel) Weekdays(weekdays Weekdays) MonthModel

Weekdays sets custom weekday labels.

type MonthStyles

type MonthStyles struct {
	// Days-of-the-week header
	LeftHeaderStyle   gloss.Style
	MiddleHeaderStyle gloss.Style
	RightHeaderStyle  gloss.Style

	// Month block interior
	MiddleLeftDayStyle  gloss.Style
	MiddleDayStyle      gloss.Style
	MiddleRightDayStyle gloss.Style

	// Month block bottom row
	BottomLeftDayStyle  gloss.Style
	BottomDayStyle      gloss.Style
	BottomRightDayStyle gloss.Style

	// Date interior
	DateStyles DateStyles
}

Styles for rendering the calendar.

func DefaultMonthStyles

func DefaultMonthStyles() MonthStyles

DefaultMonthStyles provides default month styles.

type WeekModel

type WeekModel struct {
	// contains filtered or unexported fields
}

WeekModel represents a calendar week.

func NewWeek

func NewWeek(sampleDate time.Time) WeekModel

NewWeek creates a new WeekModel.

func (WeekModel) Init

func (m WeekModel) Init() tea.Cmd

Init the WeekModel.

func (WeekModel) NextDate

func (m WeekModel) NextDate() WeekModel

NextDate sets the activeDate to the next visible date.

Notes:

  • The Weekdays map is used to determine the next date that has a day label and should therefore be visible.
  • If moving forwards from the last visible day, the method rolls over to the first visible day of the week.
  • If the active date is unset (initial state), this method will set the first visible weekday as the "next" date.

func (WeekModel) PreviousDate

func (m WeekModel) PreviousDate() WeekModel

PreviousDate sets the activeDate to the previous visible date.

Notes:

  • The Weekdays map is used to determine the previous date that has a day label and should therefore be visible.
  • If moving backwards from the first visible day, the method rolls over to the last visible day of the week.
  • If the active date is unset (initial state), this method will set the last visible weekday as the "previous" date.

func (WeekModel) StartOfWeek

func (m WeekModel) StartOfWeek(weekday time.Weekday) WeekModel

StartOfWeek sets the first day of the week.

func (WeekModel) Styles

func (m WeekModel) Styles(styles WeekStyles) WeekModel

Styles sets custom styling.

func (WeekModel) Update

func (m WeekModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update the WeekModel.

func (WeekModel) View

func (m WeekModel) View() string

View renders the WeekModel.

func (WeekModel) ViewDates

func (m WeekModel) ViewDates() string

ViewDates renders the individual dates.

func (WeekModel) ViewHeaders

func (m WeekModel) ViewHeaders() string

ViewHeaders renders the weekday headers.

func (WeekModel) Weekdays

func (m WeekModel) Weekdays(weekdays Weekdays) WeekModel

Weekdays sets custom weekday labels.

type WeekStyles

type WeekStyles struct {
	// Days-of-the-week header
	LeftHeaderStyle   gloss.Style
	MiddleHeaderStyle gloss.Style
	RightHeaderStyle  gloss.Style

	// Style to indicate a day is the active day from the header
	ActiveHeaderStyle gloss.Style

	// Month block bottom row
	LeftDayStyle   gloss.Style
	MiddleDayStyle gloss.Style
	RightDayStyle  gloss.Style

	// Date interior
	//
	// Note: NumberStyle and ActiveNumber styles are ignored for WeekModel.
	DateStyles DateStyles
	DateFormat string
}

Styles for rendering the calendar.

func DefaultWeekStyles

func DefaultWeekStyles() WeekStyles

type Weekdays

type Weekdays map[time.Weekday]string

Weekdays maps weekdays to their labels.

func DefaultWeekdays

func DefaultWeekdays() Weekdays

DefaultWeekdays returns default weekday labels.

func DefaultWeekdaysShort

func DefaultWeekdaysShort() Weekdays

DefaultWeekdaysShort returns default short weekday labels.

func (Weekdays) First

func (w Weekdays) First(startDate time.Time) time.Weekday

First returns the first visible weekday based on the start date.

func (Weekdays) Get

func (w Weekdays) Get(day time.Weekday) (string, bool)

Get the label for a weekday if it exists in the map.

func (Weekdays) IsVisible

func (w Weekdays) IsVisible(weekday time.Weekday) bool

IsVisible determines whether the weekday has a label, and should therefore be visible.

func (Weekdays) Last

func (w Weekdays) Last(startDate time.Time) time.Weekday

Last returns the last visible weekday based on the start date.

func (Weekdays) Next

func (w Weekdays) Next(startDate time.Time) time.Weekday

Next returns the next visible weekday based on the start date.

func (Weekdays) Previous

func (w Weekdays) Previous(startDate time.Time) time.Weekday

Previous returns the prior visible weekday based on the start date.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL