annotated main

This commit is contained in:
steven carpenter 2025-06-28 23:08:27 -04:00
parent bbbd0d60b6
commit 3071ce4250
5 changed files with 26 additions and 10 deletions

View file

@ -1,5 +1,6 @@
package main
//Table definition constants
const (
numRows = 6
numCols = 7

View file

@ -9,8 +9,11 @@ import (
)
func main() {
// Get the current datetime
now := time.Now()
// Set the start date used for opening the current month instead of 1/1/1970
start := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
// This gets the weekday of the first of the month so that we have the correct day with the correct date
offset := int(start.Weekday())
p := tea.NewProgram(model{
year: now.Year(),

View file

@ -1,7 +1,7 @@
package main
import tea "github.com/charmbracelet/bubbletea"
// viewMode is used to store which view is being currently seen (i.e. month or hour)
type viewMode int
const (
@ -10,20 +10,21 @@ const (
)
type model struct {
cursorRow int
cursorCol int
monthIndex int
year int
cursorRow int // which row the cursor is sitting on used for cursor highlight
cursorCol int // which col the cursor is sitiing on used for cursor highlight
monthIndex int // what month 1-12 that is being displayed
year int // the current year being displayed
startOffset int // weekday offset where day 1 starts
daysInMonth int
daysInMonth int // a count of how many days there are in the month to account for 30,31,or 28
mode viewMode
// For hourly view
selectedDay int
selectedDay int // which day we are looking at in hourly view
hourCursor int // which hour (0-23) is selected in hourly view
}
//No init state
func (m model) Init() tea.Cmd {
return nil
}

View file

@ -46,3 +46,5 @@ Controls:
- [Esc]: Return to month view.
- [q] / Ctrl+C: Quit.
## TODO: anotate the update and view files

View file

@ -4,16 +4,25 @@ import "github.com/charmbracelet/lipgloss"
// Styles for calendar cells and headers
var (
// this is the style thats used as the default style for the month view
cellStyle = lipgloss.NewStyle().Width(cellW).Height(cellH).Align(lipgloss.Center)
selectedStyle = cellStyle.Copy().Bold(true).Background(lipgloss.Color("12")).Foreground(lipgloss.Color("15")) // Blue bg
// this is the style that sets the current selected hours bg to orange and text to white
selectedStyle = cellStyle.Copy().Bold(true).Background(lipgloss.Color("12")).Foreground(lipgloss.Color("15"))
// this is the style that sets the color of cells that are not in use for a given month
unselectedStyle = cellStyle.Copy().Background(lipgloss.Color("236")).Foreground(lipgloss.Color("250"))
todayStyle = cellStyle.Copy().Background(lipgloss.Color("99")).Foreground(lipgloss.Color("15")).Bold(true) // Purple bg + white text
// this is the style that sets the color of todays cell to purple bg white text
todayStyle = cellStyle.Copy().Background(lipgloss.Color("99")).Foreground(lipgloss.Color("15")).Bold(true)
// this is the style that defines the header where the current months name goes
headerStyle = lipgloss.NewStyle().Width(numCols * cellW).Align(lipgloss.Center).Bold(true)
// this is the style that defines the DoW header where mon-sun go
daysOfWeekStyle = lipgloss.NewStyle().Width(cellW).Align(lipgloss.Center).Bold(true)
// Styles for hourly view cells
// this is the style thats used as the default for the hours view
hourCellStyle = lipgloss.NewStyle().Width(cellW * 3).Height(cellH).Align(lipgloss.Left).PaddingLeft(1)
// This is the style that sets the current selected hours style to orange bg white text
hourSelectedStyle = hourCellStyle.Copy().Bold(true).Background(lipgloss.Color("12")).Foreground(lipgloss.Color("15"))
currentHourStyle = hourCellStyle.Copy().Background(lipgloss.Color("99")).Foreground(lipgloss.Color("15")).Bold(true) // Purple bg + white text
// this is the style that sets the current hour to purple bg and white text
currentHourStyle = hourCellStyle.Copy().Background(lipgloss.Color("99")).Foreground(lipgloss.Color("15")).Bold(true)
)