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

Can set custom calendar title colors from config

This commit is contained in:
Chris Cummer 2018-05-04 16:31:10 -07:00
parent 6e179de0c4
commit b5e88d5c16

View File

@ -2,6 +2,7 @@ package gcal
import ( import (
"fmt" "fmt"
"regexp"
"strings" "strings"
"time" "time"
@ -42,6 +43,30 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
// conflicts returns TRUE if this event conflicts with another, FALSE if it does not
func (widget *Widget) conflicts(event *calendar.Event, events *calendar.Events) bool {
conflict := false
for _, otherEvent := range events.Items {
if event == otherEvent {
continue
}
eventStart, _ := time.Parse(time.RFC3339, event.Start.DateTime)
eventEnd, _ := time.Parse(time.RFC3339, event.End.DateTime)
otherEnd, _ := time.Parse(time.RFC3339, otherEvent.End.DateTime)
otherStart, _ := time.Parse(time.RFC3339, otherEvent.Start.DateTime)
if eventStart.Before(otherEnd) && eventEnd.After(otherStart) {
conflict = true
break
}
}
return conflict
}
func (widget *Widget) contentFrom(events *calendar.Events) string { func (widget *Widget) contentFrom(events *calendar.Events) string {
if events == nil { if events == nil {
return "" return ""
@ -83,11 +108,10 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
} }
func (widget *Widget) descriptionColor(event *calendar.Event) string { func (widget *Widget) descriptionColor(event *calendar.Event) string {
ts, _ := time.Parse(time.RFC3339, event.Start.DateTime) color := Config.UString("wtf.mods.gcal.colors.description", "white")
color := "white" if widget.eventIsPast(event) {
if (widget.eventIsNow(event) == false) && ts.Before(time.Now()) { color = Config.UString("wtf.mods.gcal.colors.past", "gray")
color = "grey"
} }
return color return color
@ -124,44 +148,29 @@ func (widget *Widget) eventIsNow(event *calendar.Event) bool {
return time.Now().After(startTime) && time.Now().Before(endTime) return time.Now().After(startTime) && time.Now().Before(endTime)
} }
// conflicts returns TRUE if this event conflicts with another, FALSE if it does not func (widget *Widget) eventIsPast(event *calendar.Event) bool {
func (widget *Widget) conflicts(event *calendar.Event, events *calendar.Events) bool { ts, _ := time.Parse(time.RFC3339, event.Start.DateTime)
conflict := false return (widget.eventIsNow(event) == false) && ts.Before(time.Now())
for _, otherEvent := range events.Items {
if event == otherEvent {
continue
}
eventStart, _ := time.Parse(time.RFC3339, event.Start.DateTime)
eventEnd, _ := time.Parse(time.RFC3339, event.End.DateTime)
otherEnd, _ := time.Parse(time.RFC3339, otherEvent.End.DateTime)
otherStart, _ := time.Parse(time.RFC3339, otherEvent.Start.DateTime)
if eventStart.Before(otherEnd) && eventEnd.After(otherStart) {
conflict = true
break
}
}
return conflict
}
func (widget *Widget) isOneOnOne(event *calendar.Event) bool {
return strings.Contains(event.Summary, "1on1") || strings.Contains(event.Summary, "1/1")
} }
func (widget *Widget) titleColor(event *calendar.Event) string { func (widget *Widget) titleColor(event *calendar.Event) string {
ts, _ := time.Parse(time.RFC3339, event.Start.DateTime) color := Config.UString("wtf.mods.gcal.colors.title", "white")
color := "red" for _, untypedArr := range Config.UList("wtf.mods.gcal.colors.highlights") {
if widget.isOneOnOne(event) { highlightElements := wtf.ToStrs(untypedArr.([]interface{}))
color = "green"
match, _ := regexp.MatchString(
strings.ToLower(highlightElements[0]),
strings.ToLower(event.Summary),
)
if match == true {
color = highlightElements[1]
}
} }
if (widget.eventIsNow(event) == false) && ts.Before(time.Now()) { if widget.eventIsPast(event) {
color = "grey" color = Config.UString("wtf.mods.gcal.colors.past", "gray")
} }
return color return color