1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Seperate calendar coloring code from widget code

This commit is contained in:
Chris Cummer 2018-03-29 03:38:22 -07:00 committed by Chris Cummer
parent 0b86262560
commit bb71396291

View File

@ -6,6 +6,7 @@ import (
"time"
"github.com/rivo/tview"
"google.golang.org/api/calendar/v3"
)
func Widget() tview.Primitive {
@ -21,14 +22,7 @@ func Widget() tview.Primitive {
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
timestamp := ts.Format("Mon Jan _2 15:04:05 2006")
color := "red"
if strings.Contains(item.Summary, "1on1") {
color = "green"
}
if ts.Before(time.Now()) {
color = "grey"
}
color := colorize(item, ts)
str := fmt.Sprintf(" [%s]%s[white]\n %s\n\n", color, item.Summary, timestamp)
data = data + str
@ -38,3 +32,16 @@ func Widget() tview.Primitive {
return widget
}
func colorize(item *calendar.Event, ts time.Time) string {
color := "red"
if strings.Contains(item.Summary, "1on1") {
color = "green"
}
if ts.Before(time.Now()) {
color = "grey"
}
return color
}