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
import (
//"fmt"
"os"
"time"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/bamboohr"
"github.com/senorprogrammer/wtf/gcal"
@ -18,21 +20,6 @@ import (
"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) {
if widget.Disabled() {
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 Config = wtf.LoadConfigFile()
var Modules []wtf.TextViewer
/* -------------------- Main -------------------- */
func main() {
@ -105,18 +120,25 @@ func main() {
weather := weather.NewWidget()
go wtf.Schedule(weather)
addToApp(grid, bamboo)
addToApp(grid, cal)
addToApp(grid, git)
addToApp(grid, github)
addToApp(grid, newrelic)
addToApp(grid, weather)
addToApp(grid, sec)
addToApp(grid, opsgenie)
addToApp(grid, jira)
addToApp(grid, stat)
Modules = []wtf.TextViewer{
bamboo,
cal,
git,
github,
jira,
newrelic,
opsgenie,
sec,
stat,
weather,
}
for _, module := range Modules {
addToApp(grid, module)
}
app := tview.NewApplication()
app.SetInputCapture(keyboardIntercept)
// Loop in a routine to redraw the screen
go refresher(stat, app)

View File

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