diff --git a/main.go b/main.go index ae1fcf6..e25a482 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ func initWidgets(ctx context.Context, term *tcell.Terminal) { widgets.New("Date", widgets.Date()), widgets.New("Calendar", widgets.Calendar()), widgets.New("CalendarEvents", widgets.CalendarEvents()), + widgets.New("YearMood", widgets.YearMood()), widgets.New("Weather", widgets.Weather()), widgets.New("ChangeTitle", widgets.TextInput(titleUpdate, textinput.Label("Update Title: "), textinput.PlaceHolder("New Title"))), widgets.New("Wifi", widgets.WifiQRCode()), @@ -204,6 +205,15 @@ func layout() []container.Option { container.PaddingLeft(1), ), ), + grid.RowHeightFixed(39, + grid.Widget(widgets.Get["YearMood"], + container.BorderTitle("Every Day Mood"), + container.Border(linestyle.Light), + container.BorderColor(cell.ColorWhite), + container.PaddingLeft(1), + container.PaddingTop(1), + ), + ), grid.RowHeightFixed(85, grid.Widget(widgets.Get["empty"], container.Border(linestyle.Light), diff --git a/widgets/yearMood.go b/widgets/yearMood.go new file mode 100644 index 0000000..fef78ad --- /dev/null +++ b/widgets/yearMood.go @@ -0,0 +1,114 @@ +package widgets + +import ( + "ArinDash/util" + "context" + "fmt" + "time" + + "github.com/mum4k/termdash/cell" + "github.com/mum4k/termdash/terminal/terminalapi" + "github.com/mum4k/termdash/widgetapi" + "github.com/mum4k/termdash/widgets/text" +) + +type YearMoodOptions struct { +} + +func YearMood() YearMoodOptions { + widgetOptions["YearMoodOptions"] = createYearMood + return YearMoodOptions{} +} + +var days = map[int]map[int]map[int]int{ + 2025: { + 1: { + 1: -1, + 2: 1, + 3: 3, + 4: 2, + }, + }, +} + +func createYearMood(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget { + widget := util.PanicOnErrorWithResult(text.New()) + var selectedMonth = time.Now().Month() + var selectedDay = time.Now().Day() + + go util.Periodic(ctx, 1*time.Hour, func() error { + widget.Reset() + + if err := widget.Write(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec \n\n", text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil { + return err + } + + for day := range 31 { + for month := range 12 { + date := time.Date(time.Now().Year(), time.Month(month+1), day+1, 0, 0, 0, 0, time.UTC) + if date.Month() != time.Month(month+1) { + if err := widget.Write(" "); err != nil { + return err + } + continue + } + cellOptions := make([]cell.Option, 0) + weekday := time.Date(time.Now().Year(), time.Month(month+1), day+1, 0, 0, 0, 0, time.UTC).Weekday() + if weekday == time.Saturday || weekday == time.Sunday { + cellOptions = append(cellOptions, cell.Dim()) + } + cellOptions = append(cellOptions, cell.FgColor(cell.ColorWhite)) + cellOptions = append(cellOptions, cell.Bold()) + mood := days[time.Now().Year()][month+1][day+1] + if mood == -1 { + cellOptions = append(cellOptions, cell.BgColor(cell.ColorRed)) + } else if mood == 1 { + cellOptions = append(cellOptions, cell.BgColor(cell.ColorPurple)) + } else if mood == 2 { + cellOptions = append(cellOptions, cell.BgColor(cell.ColorYellow)) + } else if mood == 3 { + cellOptions = append(cellOptions, cell.BgColor(cell.ColorGreen)) + } else { + cellOptions = append(cellOptions, cell.BgColor(cell.ColorGray)) + } + + if day+1 == selectedDay && time.Month(month+1) == selectedMonth { + if err := widget.Write(">", text.WriteCellOpts(append(cellOptions, cell.Blink())...)); err != nil { + return err + } + if err := widget.Write(fmt.Sprintf("%3d", day+1), text.WriteCellOpts(cellOptions...)); err != nil { + return err + } + } else { + if err := widget.Write(fmt.Sprintf(" %3d", day+1), text.WriteCellOpts(cellOptions...)); err != nil { + return err + } + } + if time.Now().Day() == day+1 && time.Now().Month() == time.Month(month+1) { + if err := widget.Write("<", text.WriteCellOpts(cellOptions...)); err != nil { + return err + } + } else { + if err := widget.Write(" ", text.WriteCellOpts(cellOptions...)); err != nil { + return err + } + } + + if err := widget.Write(" "); err != nil { + return err + } + } + if err := widget.Write("\n"); err != nil { + return err + } + } + + if err := widget.Write("\nKeys:\nd=delete 1=idk(purple) 2=meh(yellow) 3=great(green) other=bad(red)", text.WriteCellOpts(cell.FgColor(cell.ColorGray))); err != nil { + return err + } + + return nil + }) + + return widget +}