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 {
|
func (widget *Widget) contentFrom(events *calendar.Events) string {
|
||||||
str := "\n"
|
str := "\n"
|
||||||
|
|
||||||
for _, item := range events.Items {
|
for _, event := range events.Items {
|
||||||
startTime, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
|
||||||
timestamp := startTime.Format("Mon, Jan 2, 15:04")
|
timestamp := startTime.Format("Mon, Jan 2, 15:04")
|
||||||
until := widget.until(startTime)
|
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
|
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 {
|
func titleColor(item *calendar.Event) string {
|
||||||
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
||||||
|
|
||||||
@ -86,17 +110,6 @@ func titleColor(item *calendar.Event) string {
|
|||||||
return color
|
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
|
// until returns the number of hours or days until the event
|
||||||
// If the event is in the past, returns nil
|
// If the event is in the past, returns nil
|
||||||
func (widget *Widget) until(start time.Time) string {
|
func (widget *Widget) until(start time.Time) string {
|
||||||
|
@ -35,7 +35,7 @@ func NewWidget() *Widget {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
data := Fetch()
|
data := Fetch()
|
||||||
|
|
||||||
widget.View.SetTitle(" π¦ Security ")
|
widget.View.SetTitle(" π€Ί Security ")
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
@ -55,7 +55,7 @@ func (widget *Widget) addView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom() string {
|
func (widget *Widget) contentFrom() string {
|
||||||
icons := []string{"π", "π€", "π€", "π€"}
|
icons := []string{"π", "π€", "π€", "π€", "π€", "π€", "β", "π€", "π", "π€"}
|
||||||
next := icons[widget.Current]
|
next := icons[widget.Current]
|
||||||
|
|
||||||
widget.Current = widget.Current + 1
|
widget.Current = widget.Current + 1
|
||||||
|
Loadingβ¦
x
Reference in New Issue
Block a user