mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Widgetized Google Calendar
This commit is contained in:
parent
6cfa0ef632
commit
951da43f99
@ -9,26 +9,55 @@ import (
|
||||
"google.golang.org/api/calendar/v3"
|
||||
)
|
||||
|
||||
func Widget() tview.Primitive {
|
||||
type Widget struct {
|
||||
RefreshedAt time.Time
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
RefreshedAt: time.Now(),
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
events := Fetch()
|
||||
|
||||
widget := tview.NewTextView()
|
||||
widget.SetBorder(true)
|
||||
widget.SetDynamicColors(true)
|
||||
widget.SetTitle(" 🐸 Calendar ")
|
||||
widget.View.SetTitle(" 🐸 Calendar ")
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom(events))
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) addView() {
|
||||
view := tview.NewTextView()
|
||||
|
||||
view.SetBorder(true)
|
||||
view.SetDynamicColors(true)
|
||||
view.SetTitle(" Calendar ")
|
||||
|
||||
widget.View = view
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom(events *calendar.Events) string {
|
||||
str := ""
|
||||
|
||||
data := ""
|
||||
for _, item := range events.Items {
|
||||
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
|
||||
timestamp := ts.Format("Mon Jan _2 15:04:05 2006")
|
||||
|
||||
str := fmt.Sprintf(" [%s]%s[white]\n [%s]%s[white]\n\n", titleColor(item), item.Summary, descriptionColor(item), timestamp)
|
||||
data = data + str
|
||||
str = str + fmt.Sprintf(" [%s]%s[white]\n [%s]%s[white]\n\n", titleColor(item), item.Summary, descriptionColor(item), timestamp)
|
||||
}
|
||||
|
||||
fmt.Fprintf(widget, "%s", data)
|
||||
|
||||
return widget
|
||||
return str
|
||||
}
|
||||
|
||||
func titleColor(item *calendar.Event) string {
|
||||
|
10
wtf.go
10
wtf.go
@ -14,6 +14,12 @@ func main() {
|
||||
bamboo := bamboohr.NewWidget()
|
||||
bamboo.Refresh()
|
||||
|
||||
cal := gcal.NewWidget()
|
||||
cal.Refresh()
|
||||
|
||||
stat := status.NewWidget()
|
||||
stat.Refresh()
|
||||
|
||||
weather := weather.NewWidget()
|
||||
weather.Refresh()
|
||||
|
||||
@ -25,8 +31,8 @@ func main() {
|
||||
grid.SetBorder(false)
|
||||
|
||||
grid.AddItem(bamboo.View, 0, 0, 1, 1, 0, 0, false)
|
||||
grid.AddItem(gcal.Widget(), 1, 0, 1, 1, 0, 0, false)
|
||||
grid.AddItem(status.Widget(), 2, 0, 2, 3, 0, 0, false)
|
||||
grid.AddItem(cal.View, 1, 0, 1, 1, 0, 0, false)
|
||||
grid.AddItem(stat.View, 2, 0, 2, 3, 0, 0, false)
|
||||
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
|
||||
|
||||
if err := app.SetRoot(grid, true).Run(); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user