restructured main

This commit is contained in:
steven carpenter 2025-06-28 22:42:27 -04:00
parent e59765bfc6
commit bbbd0d60b6
5 changed files with 272 additions and 0 deletions

89
view.go Normal file
View file

@ -0,0 +1,89 @@
package main
import (
"fmt"
"time"
)
func (m model) View() string {
switch m.mode {
case monthView:
return m.viewMonth()
case hourlyView:
return m.viewHourly()
default:
return ""
}
}
func (m model) viewMonth() string {
var out string
monthTime := time.Date(m.year, time.Month(m.monthIndex+1), 1, 0, 0, 0, 0, time.UTC)
header := headerStyle.Render(monthTime.Format("January 2006"))
out += header + "\n"
weekdays := []string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
for _, day := range weekdays {
out += daysOfWeekStyle.Render(day)
}
out += "\n"
day := 1
for r := 0; r < numRows; r++ {
for c := 0; c < numCols; c++ {
cellNum := r*numCols + c
var content string
if cellNum >= m.startOffset && day <= m.daysInMonth {
content = fmt.Sprintf("%2d", day)
if r == m.cursorRow && c == m.cursorCol {
out += selectedStyle.Render(content)
} else {
today := time.Now()
isToday := m.year == today.Year() &&
m.monthIndex == int(today.Month())-1 &&
day == today.Day()
if isToday {
out += todayStyle.Render(content)
} else {
out += unselectedStyle.Render(content)
}
}
day++
} else {
out += cellStyle.Render("")
}
}
out += "\n"
}
out += "\n[a]/[d] to change month, arrows to move, enter to select a day, q to quit."
return out
}
func (m model) viewHourly() string {
var out string
dateHeader := fmt.Sprintf("Schedule for %04d-%02d-%02d", m.year, m.monthIndex+1, m.selectedDay)
out += headerStyle.Render(dateHeader) + "\n\n"
nowHour := time.Now().Hour()
for hour := 0; hour < 24; hour++ {
label := fmt.Sprintf("%02d:00 - %02d:00", hour, hour+1)
switch {
case hour == m.hourCursor:
out += hourSelectedStyle.Render(label) + "\n"
case hour == nowHour:
out += currentHourStyle.Render(label) + "\n"
default:
out += hourCellStyle.Render(label) + "\n"
}
}
out += "\nPress ESC to return to month view, q to quit."
return out
}