mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	Re-work calendar view
As discussed in issue #223 (which has pictures that better explain the changes here), this change: - Removes the date from individual events, instead centering a title at the start of each day with the date (which uses a new configurable color, `wtf.mods.gcal.colors.day`) - Consolidates 3 lines per event down to 2, moving timestamp to front of each event - Makes the time-until-event text turn red when under 30 minutes (wasn't discussed in the issue but was another thing I added locally for this, feel free to discard if unwanted) New format is: ``` Monday, Jun 25 x 13:00 Super Cool Meeting Title 2h Event location x 14:00 Also Super Cool Meeting 3h Event location Tuesday, Jun 26 ... ```
This commit is contained in:
		
							parent
							
								
									4b9c42844b
								
							
						
					
					
						commit
						0ffbf66f88
					
				@ -93,16 +93,27 @@ func (widget *Widget) contentFrom(events *calendar.Events) string {
 | 
				
			|||||||
	for _, event := range events.Items {
 | 
						for _, event := range events.Items {
 | 
				
			||||||
		conflict := widget.conflicts(event, events)
 | 
							conflict := widget.conflicts(event, events)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		str = str + fmt.Sprintf(
 | 
							dayDivider := widget.dayDivider(event, prevEvent)
 | 
				
			||||||
			"%s %s[%s]%s[white]\n %s[%s]%s %s[white]\n\n",
 | 
							responseIcon := widget.responseIcon(event)
 | 
				
			||||||
			widget.dayDivider(event, prevEvent),
 | 
							timestamp := fmt.Sprintf("[%s]%s",
 | 
				
			||||||
			widget.responseIcon(event),
 | 
					 | 
				
			||||||
			widget.titleColor(event),
 | 
					 | 
				
			||||||
			widget.eventSummary(event, conflict),
 | 
					 | 
				
			||||||
			widget.location(event),
 | 
					 | 
				
			||||||
			widget.descriptionColor(event),
 | 
								widget.descriptionColor(event),
 | 
				
			||||||
			widget.eventTimestamp(event),
 | 
								widget.eventTimestamp(event))
 | 
				
			||||||
			widget.until(event),
 | 
							title := fmt.Sprintf("[%s]%s",
 | 
				
			||||||
 | 
								widget.titleColor(event),
 | 
				
			||||||
 | 
								widget.eventSummary(event, conflict))
 | 
				
			||||||
 | 
							until := widget.until(event)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							lineOne := fmt.Sprintf(
 | 
				
			||||||
 | 
								"%s %s %s %s %s[white]",
 | 
				
			||||||
 | 
								dayDivider,
 | 
				
			||||||
 | 
								responseIcon,
 | 
				
			||||||
 | 
								timestamp,
 | 
				
			||||||
 | 
								title,
 | 
				
			||||||
 | 
								until,
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
							str = str + fmt.Sprintf("%s%s\n\n",
 | 
				
			||||||
 | 
								lineOne,
 | 
				
			||||||
 | 
								widget.location(event), // prefixes newline if non-empty
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		prevEvent = event
 | 
							prevEvent = event
 | 
				
			||||||
@ -112,13 +123,17 @@ func (widget *Widget) contentFrom(events *calendar.Events) string {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
 | 
					func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
 | 
				
			||||||
 | 
						var prevStartTime time.Time
 | 
				
			||||||
	if prevEvent != nil {
 | 
						if prevEvent != nil {
 | 
				
			||||||
		prevStartTime, _ := time.Parse(time.RFC3339, prevEvent.Start.DateTime)
 | 
							prevStartTime, _ = time.Parse(time.RFC3339, prevEvent.Start.DateTime)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	currStartTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
 | 
						currStartTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if currStartTime.Day() != prevStartTime.Day() {
 | 
						if currStartTime.Day() != prevStartTime.Day() {
 | 
				
			||||||
			return "\n"
 | 
							_, _, width, _ := widget.View.GetInnerRect()
 | 
				
			||||||
		}
 | 
							return fmt.Sprintf("[%s]", wtf.Config.UString("wtf.mods.gcal.colors.day", "forestgreen")) +
 | 
				
			||||||
 | 
								wtf.CenterText(currStartTime.Format(wtf.FullDateFormat), width) +
 | 
				
			||||||
 | 
								"\n"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ""
 | 
						return ""
 | 
				
			||||||
@ -158,7 +173,7 @@ func (widget *Widget) eventTimestamp(event *calendar.Event) string {
 | 
				
			|||||||
		return startTime.Format(wtf.FriendlyDateFormat)
 | 
							return startTime.Format(wtf.FriendlyDateFormat)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
 | 
							startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
 | 
				
			||||||
		return startTime.Format(wtf.FriendlyDateTimeFormat)
 | 
							return startTime.Format(wtf.MinimumTimeFormat)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -208,7 +223,7 @@ func (widget *Widget) location(event *calendar.Event) string {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return fmt.Sprintf(
 | 
						return fmt.Sprintf(
 | 
				
			||||||
		"[%s]%s\n ",
 | 
							"\n [%s]%s",
 | 
				
			||||||
		widget.descriptionColor(event),
 | 
							widget.descriptionColor(event),
 | 
				
			||||||
		event.Location,
 | 
							event.Location,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
@ -232,15 +247,15 @@ func (widget *Widget) responseIcon(event *calendar.Event) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	switch response {
 | 
						switch response {
 | 
				
			||||||
	case "accepted":
 | 
						case "accepted":
 | 
				
			||||||
		icon = icon + "✔︎ "
 | 
							icon = icon + "✔︎"
 | 
				
			||||||
	case "declined":
 | 
						case "declined":
 | 
				
			||||||
		icon = icon + "✘ "
 | 
							icon = icon + "✘"
 | 
				
			||||||
	case "needsAction":
 | 
						case "needsAction":
 | 
				
			||||||
		icon = icon + "? "
 | 
							icon = icon + "?"
 | 
				
			||||||
	case "tentative":
 | 
						case "tentative":
 | 
				
			||||||
		icon = icon + "~ "
 | 
							icon = icon + "~"
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		icon = icon + ""
 | 
							icon = icon + " "
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return icon
 | 
						return icon
 | 
				
			||||||
@ -268,15 +283,19 @@ func (widget *Widget) until(event *calendar.Event) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	untilStr := ""
 | 
						untilStr := ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var color = "[lightblue]"
 | 
				
			||||||
	if days > 0 {
 | 
						if days > 0 {
 | 
				
			||||||
		untilStr = fmt.Sprintf("%dd", days)
 | 
							untilStr = fmt.Sprintf("%dd", days)
 | 
				
			||||||
	} else if hours > 0 {
 | 
						} else if hours > 0 {
 | 
				
			||||||
		untilStr = fmt.Sprintf("%dh", hours)
 | 
							untilStr = fmt.Sprintf("%dh", hours)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		untilStr = fmt.Sprintf("%dm", mins)
 | 
							untilStr = fmt.Sprintf("%dm", mins)
 | 
				
			||||||
 | 
							if mins < 30 {
 | 
				
			||||||
 | 
								color = "[red]"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return "[lightblue]" + untilStr + "[white]"
 | 
						return color + untilStr + "[white]"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func updateLoop(widget *Widget) {
 | 
					func updateLoop(widget *Widget) {
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,8 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const SimpleDateFormat = "Jan 2"
 | 
					const SimpleDateFormat = "Jan 2"
 | 
				
			||||||
const SimpleTimeFormat = "15:04 MST"
 | 
					const SimpleTimeFormat = "15:04 MST"
 | 
				
			||||||
 | 
					const MinimumTimeFormat = "15:04"
 | 
				
			||||||
 | 
					const FullDateFormat = "Monday, Jan 2"
 | 
				
			||||||
const FriendlyDateFormat = "Mon, Jan 2"
 | 
					const FriendlyDateFormat = "Mon, Jan 2"
 | 
				
			||||||
const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
 | 
					const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
 | 
				
			||||||
const TimestampFormat = "2006-01-02T15:04:05-0700"
 | 
					const TimestampFormat = "2006-01-02T15:04:05-0700"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user