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

Add Ctrl-R to manually force a widget refresh

This commit is contained in:
Chris Cummer 2018-04-12 15:15:11 -07:00 committed by Chris Cummer
parent 00ec46bfed
commit da27ad60a9
2 changed files with 50 additions and 25 deletions

72
wtf.go
View File

@ -1,9 +1,11 @@
package main package main
import ( import (
//"fmt"
"os" "os"
"time" "time"
"github.com/gdamore/tcell"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/senorprogrammer/wtf/bamboohr" "github.com/senorprogrammer/wtf/bamboohr"
"github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/gcal"
@ -18,21 +20,6 @@ import (
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
) )
func refresher(stat *status.Widget, app *tview.Application) {
tick := time.NewTicker(time.Duration(Config.UInt("wtf.refreshInterval", 1)) * time.Second)
quit := make(chan struct{})
for {
select {
case <-tick.C:
app.Draw()
case <-quit:
tick.Stop()
return
}
}
}
func addToApp(grid *tview.Grid, widget wtf.TextViewer) { func addToApp(grid *tview.Grid, widget wtf.TextViewer) {
if widget.Disabled() { if widget.Disabled() {
return return
@ -50,9 +37,37 @@ func addToApp(grid *tview.Grid, widget wtf.TextViewer) {
) )
} }
func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
// Ctrl-R: force-refreshes every widget
if event.Key() == tcell.KeyCtrlR {
for _, module := range Modules {
go module.Refresh()
}
}
return event
}
func refresher(stat *status.Widget, app *tview.Application) {
tick := time.NewTicker(time.Duration(Config.UInt("wtf.refreshInterval", 1)) * time.Second)
quit := make(chan struct{})
for {
select {
case <-tick.C:
app.Draw()
case <-quit:
tick.Stop()
return
}
}
}
var result = wtf.CreateConfigDir() var result = wtf.CreateConfigDir()
var Config = wtf.LoadConfigFile() var Config = wtf.LoadConfigFile()
var Modules []wtf.TextViewer
/* -------------------- Main -------------------- */ /* -------------------- Main -------------------- */
func main() { func main() {
@ -105,18 +120,25 @@ func main() {
weather := weather.NewWidget() weather := weather.NewWidget()
go wtf.Schedule(weather) go wtf.Schedule(weather)
addToApp(grid, bamboo) Modules = []wtf.TextViewer{
addToApp(grid, cal) bamboo,
addToApp(grid, git) cal,
addToApp(grid, github) git,
addToApp(grid, newrelic) github,
addToApp(grid, weather) jira,
addToApp(grid, sec) newrelic,
addToApp(grid, opsgenie) opsgenie,
addToApp(grid, jira) sec,
addToApp(grid, stat) stat,
weather,
}
for _, module := range Modules {
addToApp(grid, module)
}
app := tview.NewApplication() app := tview.NewApplication()
app.SetInputCapture(keyboardIntercept)
// Loop in a routine to redraw the screen // Loop in a routine to redraw the screen
go refresher(stat, app) go refresher(stat, app)

View File

@ -6,7 +6,10 @@ import (
type TextViewer interface { type TextViewer interface {
Enabler Enabler
Refresh()
TextView() *tview.TextView TextView() *tview.TextView
Top() int Top() int
Left() int Left() int
Width() int Width() int