mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
All widgets now refresh their own data using their own internal go routine. This allows them to set their own update schedule (where RefreshInterval is the time in seconds between refreshes). The app uses a goroutine to redraw itself once a second.
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/rivo/tview"
|
|
"github.com/senorprogrammer/wtf/bamboohr"
|
|
"github.com/senorprogrammer/wtf/gcal"
|
|
"github.com/senorprogrammer/wtf/status"
|
|
"github.com/senorprogrammer/wtf/weather"
|
|
)
|
|
|
|
func refresher(stat *status.Widget, app *tview.Application) {
|
|
tick := time.NewTicker(1 * time.Second)
|
|
quit := make(chan struct{})
|
|
|
|
for {
|
|
select {
|
|
case <-tick.C:
|
|
app.Draw()
|
|
case <-quit:
|
|
tick.Stop()
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
bamboo := bamboohr.NewWidget()
|
|
bamboo.Refresh()
|
|
|
|
cal := gcal.NewWidget()
|
|
cal.Refresh()
|
|
|
|
stat := status.NewWidget()
|
|
stat.Refresh()
|
|
|
|
weather := weather.NewWidget()
|
|
weather.Refresh()
|
|
|
|
grid := tview.NewGrid()
|
|
grid.SetRows(14, 36, 4) // How _high_ the row is, in terminal rows
|
|
grid.SetColumns(40, 40) // How _wide_ the column is, in terminal columns
|
|
grid.SetBorder(false)
|
|
|
|
grid.AddItem(bamboo.View, 0, 0, 1, 1, 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)
|
|
|
|
app := tview.NewApplication()
|
|
|
|
// Loop in a routine to redraw the screen
|
|
go refresher(stat, app)
|
|
|
|
if err := app.SetRoot(grid, true).Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|