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

Remove extraneous app.Draw() calls by having app.Draw() in its own routine

This commit is contained in:
Chris Cummer 2019-04-23 20:33:03 -07:00
parent f60ce6967d
commit a18625f427
5 changed files with 25 additions and 8 deletions

25
main.go
View File

@ -342,6 +342,30 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) []wtf.Wtfable {
return widgets return widgets
} }
func enableAppRefresh(app *tview.Application) {
defaultInterval := 100
refreshInterval := Config.UInt("wtf.refreshInterval", defaultInterval)
if refreshInterval < defaultInterval {
refreshInterval = defaultInterval
}
interval := time.Duration(refreshInterval) * time.Millisecond
tick := time.NewTicker(interval)
quit := make(chan struct{})
for {
select {
case <-tick.C:
app.Draw()
case <-quit:
tick.Stop()
return
}
}
}
/* -------------------- Main -------------------- */ /* -------------------- Main -------------------- */
func main() { func main() {
@ -376,6 +400,7 @@ func main() {
app.SetInputCapture(keyboardIntercept) app.SetInputCapture(keyboardIntercept)
go watchForConfigChanges(app, flags.Config, display.Grid, pages) go watchForConfigChanges(app, flags.Config, display.Grid, pages)
go enableAppRefresh(app)
if err := app.SetRoot(pages, true).Run(); err != nil { if err := app.SetRoot(pages, true).Run(); err != nil {
fmt.Printf("Error: %v\n", err) fmt.Printf("Error: %v\n", err)

View File

@ -265,7 +265,6 @@ func (widget *Widget) modalFocus(form *tview.Form) {
frame := widget.modalFrame(form) frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true) widget.pages.AddPage("modal", frame, false, true)
widget.app.SetFocus(frame) widget.app.SetFocus(frame)
widget.app.Draw()
} }
func (widget *Widget) modalForm(lbl, text string) *tview.Form { func (widget *Widget) modalForm(lbl, text string) *tview.Form {

View File

@ -150,9 +150,7 @@ func (tracker *FocusTracker) focus(idx int) {
view := widget.TextView() view := widget.TextView()
view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focused", "gray"))) view.SetBorderColor(ColorFor(Config.UString("wtf.colors.border.focused", "gray")))
tracker.App.SetFocus(view) tracker.App.SetFocus(view)
tracker.App.Draw()
} }
func (tracker *FocusTracker) focusables() []Wtfable { func (tracker *FocusTracker) focusables() []Wtfable {

View File

@ -33,5 +33,4 @@ func (widget *HelpfulWidget) ShowHelp() {
widget.pages.AddPage("help", modal, false, true) widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal) widget.app.SetFocus(modal)
widget.app.Draw()
} }

View File

@ -45,10 +45,6 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable
widget.View = widget.addView() widget.View = widget.addView()
widget.View.SetChangedFunc(func() {
app.Draw()
})
return widget return widget
} }