mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Mark the current calendar event if there is one
This commit is contained in:
parent
ef10ac5d0c
commit
12e6b2a9f2
@ -60,17 +60,41 @@ func (widget *Widget) addView() {
|
||||
func (widget *Widget) contentFrom(events *calendar.Events) string {
|
||||
str := "\n"
|
||||
|
||||
for _, item := range events.Items {
|
||||
startTime, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
||||
for _, event := range events.Items {
|
||||
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
|
||||
timestamp := startTime.Format("Mon, Jan 2, 15:04")
|
||||
until := widget.until(startTime)
|
||||
|
||||
str = str + fmt.Sprintf(" [%s]%s[white]\n [%s]%s %s[white]\n\n", titleColor(item), item.Summary, descriptionColor(item), timestamp, until)
|
||||
summary := event.Summary
|
||||
if widget.eventIsNow(event) {
|
||||
summary = "π₯ " + summary
|
||||
}
|
||||
|
||||
str = str + fmt.Sprintf(" [%s]%s[white]\n [%s]%s %s[white]\n\n", titleColor(event), summary, descriptionColor(event), timestamp, until)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
// eventIsNow returns true if the event is happening now, false if it not
|
||||
func (widget *Widget) eventIsNow(event *calendar.Event) bool {
|
||||
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
|
||||
endTime, _ := time.Parse(time.RFC3339, event.End.DateTime)
|
||||
|
||||
return time.Now().After(startTime) && time.Now().Before(endTime)
|
||||
}
|
||||
|
||||
func descriptionColor(item *calendar.Event) string {
|
||||
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
||||
|
||||
color := "white"
|
||||
if ts.Before(time.Now()) {
|
||||
color = "grey"
|
||||
}
|
||||
|
||||
return color
|
||||
}
|
||||
|
||||
func titleColor(item *calendar.Event) string {
|
||||
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
||||
|
||||
@ -86,17 +110,6 @@ func titleColor(item *calendar.Event) string {
|
||||
return color
|
||||
}
|
||||
|
||||
func descriptionColor(item *calendar.Event) string {
|
||||
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
||||
|
||||
color := "white"
|
||||
if ts.Before(time.Now()) {
|
||||
color = "grey"
|
||||
}
|
||||
|
||||
return color
|
||||
}
|
||||
|
||||
// until returns the number of hours or days until the event
|
||||
// If the event is in the past, returns nil
|
||||
func (widget *Widget) until(start time.Time) string {
|
||||
|
@ -35,7 +35,7 @@ func NewWidget() *Widget {
|
||||
func (widget *Widget) Refresh() {
|
||||
data := Fetch()
|
||||
|
||||
widget.View.SetTitle(" π¦ Security ")
|
||||
widget.View.SetTitle(" π€Ί Security ")
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
|
@ -55,7 +55,7 @@ func (widget *Widget) addView() {
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom() string {
|
||||
icons := []string{"π", "π€", "π€", "π€"}
|
||||
icons := []string{"π", "π€", "π€", "π€", "π€", "π€", "β", "π€", "π", "π€"}
|
||||
next := icons[widget.Current]
|
||||
|
||||
widget.Current = widget.Current + 1
|
||||
|
Loadingβ¦
x
Reference in New Issue
Block a user