115 lines
3.2 KiB
Go
115 lines
3.2 KiB
Go
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
|
|
}
|