diff --git a/bargraph/widget.go b/bargraph/widget.go index 84a1d5bc..e006e469 100644 --- a/bargraph/widget.go +++ b/bargraph/widget.go @@ -18,12 +18,16 @@ var ok = true // Widget define wtf widget to register widget later type Widget struct { wtf.BarGraph + + app *tview.Application } // NewWidget Make new instance of widget func NewWidget(app *tview.Application) *Widget { widget := Widget{ BarGraph: wtf.NewBarGraph(app, "Sample Bar Graph", "bargraph", false), + + app: app, } widget.View.SetWrap(true) @@ -66,7 +70,9 @@ func (widget *Widget) Refresh() { widget.View.Clear() - display(widget) + widget.app.QueueUpdateDraw(func() { + display(widget) + }) } diff --git a/generator/textwidget.tpl b/generator/textwidget.tpl index f1fe45b4..278e0387 100644 --- a/generator/textwidget.tpl +++ b/generator/textwidget.tpl @@ -17,6 +17,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application settings *Settings } @@ -25,6 +26,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -43,7 +45,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * func (widget *Widget) Refresh() { // The last call should always be to the display function - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/bamboohr/widget.go b/modules/bamboohr/widget.go index c132a719..53a3af6a 100644 --- a/modules/bamboohr/widget.go +++ b/modules/bamboohr/widget.go @@ -12,6 +12,7 @@ const APIURI = "https://api.bamboohr.com/api/gateway.php" type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -19,6 +20,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -40,9 +42,10 @@ func (widget *Widget) Refresh() { wtf.Now().Format(wtf.DateFormat), ) - widget.View.SetTitle(widget.ContextualTitle(widget.Name())) - - widget.View.SetText(widget.contentFrom(todayItems)) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(widget.Name())) + widget.View.SetText(widget.contentFrom(todayItems)) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/circleci/widget.go b/modules/circleci/widget.go index 4016a25e..83b00255 100644 --- a/modules/circleci/widget.go +++ b/modules/circleci/widget.go @@ -11,6 +11,7 @@ type Widget struct { wtf.TextWidget *Client + app *tview.Application settings *Settings } @@ -19,6 +20,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { TextWidget: wtf.NewTextWidget(app, settings.common, false), Client: NewClient(settings.apiKey), + app: app, settings: settings, } @@ -34,8 +36,6 @@ func (widget *Widget) Refresh() { builds, err := widget.Client.BuildsFor() - widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name())) - var content string if err != nil { widget.View.SetWrap(true) @@ -45,7 +45,10 @@ func (widget *Widget) Refresh() { content = widget.contentFrom(builds) } - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name())) + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index 1742234e..83cd37fc 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -15,10 +15,10 @@ type Widget struct { app *tview.Application args []string cmd string - result string settings *Settings } +// NewWidget creates a new instance of the widget func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), @@ -34,17 +34,20 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { return &widget } +// Refresh executes the command and updates the view with the results func (widget *Widget) Refresh() { - widget.execute() + result := widget.execute() - widget.CommonSettings.Title = widget.String() + ansiTitle := tview.TranslateANSI(widget.String()) + ansiResult := tview.TranslateANSI(result) widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(tview.TranslateANSI(widget.CommonSettings.Title)) - widget.View.SetText(widget.result) + widget.View.SetTitle(ansiTitle) + widget.View.SetText(ansiResult) }) } +// String returns the string representation of the widget func (widget *Widget) String() string { args := strings.Join(widget.args, " ") @@ -55,7 +58,9 @@ func (widget *Widget) String() string { return fmt.Sprintf(" %s ", widget.cmd) } -func (widget *Widget) execute() { +/* -------------------- Unexported Functions -------------------- */ + +func (widget *Widget) execute() string { cmd := exec.Command(widget.cmd, widget.args...) - widget.result = tview.TranslateANSI(wtf.ExecuteCommand(cmd)) + return wtf.ExecuteCommand(cmd) } diff --git a/modules/cryptoexchanges/bittrex/widget.go b/modules/cryptoexchanges/bittrex/widget.go index 49949389..0d366d84 100644 --- a/modules/cryptoexchanges/bittrex/widget.go +++ b/modules/cryptoexchanges/bittrex/widget.go @@ -20,6 +20,7 @@ const baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary" type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings summaryList } @@ -29,6 +30,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, summaryList: summaryList{}, } @@ -77,7 +79,10 @@ func makeMarketCurrency(name string) *mCurrency { // Refresh & update after interval time func (widget *Widget) Refresh() { widget.updateSummary() - widget.display() + + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ @@ -137,7 +142,9 @@ func (widget *Widget) updateSummary() { } } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } func makeRequest(baseName, marketName string) *http.Request { diff --git a/modules/cryptoexchanges/blockfolio/widget.go b/modules/cryptoexchanges/blockfolio/widget.go index 27f8e5fe..b1c75f1d 100644 --- a/modules/cryptoexchanges/blockfolio/widget.go +++ b/modules/cryptoexchanges/blockfolio/widget.go @@ -14,6 +14,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application device_token string settings *Settings } @@ -22,6 +23,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, device_token: settings.deviceToken, settings: settings, } @@ -32,15 +34,17 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - widget.View.SetTitle(" Blockfolio ") - positions, err := Fetch(widget.device_token) if err != nil { return } content := widget.contentFrom(positions) - widget.View.SetText(content) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(" Blockfolio ") + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/cryptoexchanges/cryptolive/widget.go b/modules/cryptoexchanges/cryptolive/widget.go index c16c4dcf..651d1170 100644 --- a/modules/cryptoexchanges/cryptolive/widget.go +++ b/modules/cryptoexchanges/cryptolive/widget.go @@ -14,6 +14,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application priceWidget *price.Widget toplistWidget *toplist.Widget settings *Settings @@ -24,6 +25,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, priceWidget: price.NewWidget(settings.priceSettings), toplistWidget: toplist.NewWidget(settings.toplistSettings), settings: settings, @@ -46,14 +48,17 @@ func (widget *Widget) Refresh() { widget.toplistWidget.Refresh(&wg) wg.Wait() - display(widget) + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ -func display(widget *Widget) { +func (widget *Widget) display() { str := "" str += widget.priceWidget.Result str += widget.toplistWidget.Result + widget.View.SetText(fmt.Sprintf("\n%s", str)) } diff --git a/modules/datadog/widget.go b/modules/datadog/widget.go index 7b97b40d..f40372f6 100644 --- a/modules/datadog/widget.go +++ b/modules/datadog/widget.go @@ -11,6 +11,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -18,6 +19,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -29,9 +31,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { monitors, monitorErr := widget.Monitors() - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name()))) - widget.View.Clear() - var content string if monitorErr != nil { widget.View.SetWrap(true) @@ -40,8 +39,11 @@ func (widget *Widget) Refresh() { widget.View.SetWrap(false) content = widget.contentFrom(monitors) } - - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name()))) + widget.View.Clear() + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/gcal/widget.go b/modules/gcal/widget.go index 67fc4aec..ccc22efc 100644 --- a/modules/gcal/widget.go +++ b/modules/gcal/widget.go @@ -41,7 +41,9 @@ func (widget *Widget) Disable() { func (widget *Widget) Refresh() { if isAuthenticated() { - widget.fetchAndDisplayEvents() + widget.app.QueueUpdateDraw(func() { + widget.fetchAndDisplayEvents() + }) return } @@ -75,7 +77,9 @@ outer: for { select { case <-tick.C: - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) case <-widget.ch: break outer } diff --git a/modules/gerrit/widget.go b/modules/gerrit/widget.go index 15afa32c..83f18d31 100644 --- a/modules/gerrit/widget.go +++ b/modules/gerrit/widget.go @@ -38,8 +38,10 @@ type Widget struct { GerritProjects []*GerritProject Idx int - selected int - settings *Settings + + app *tview.Application + selected int + settings *Settings } var ( @@ -51,7 +53,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), - Idx: 0, + Idx: 0, + + app: app, settings: settings, } @@ -91,8 +95,11 @@ func (widget *Widget) Refresh() { gerrit, err := glb.NewClient(gerritUrl, httpClient) if err != nil { widget.View.SetWrap(true) - widget.View.SetTitle(widget.Name()) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.View.SetText(err.Error()) + }) return } widget.gerrit = gerrit @@ -102,7 +109,10 @@ func (widget *Widget) Refresh() { project.Refresh(widget.settings.username) } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/gitlab/widget.go b/modules/gitlab/widget.go index bbeb8f4e..fae1465c 100644 --- a/modules/gitlab/widget.go +++ b/modules/gitlab/widget.go @@ -25,8 +25,10 @@ type Widget struct { GitlabProjects []*GitlabProject Idx int - gitlab *glb.Client - settings *Settings + + app *tview.Application + gitlab *glb.Client + settings *Settings } func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { @@ -41,7 +43,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), - Idx: 0, + Idx: 0, + + app: app, gitlab: gitlab, settings: settings, } @@ -61,7 +65,9 @@ func (widget *Widget) Refresh() { project.Refresh() } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } func (widget *Widget) Next() { diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index a3e3ffe0..65e058bd 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -24,6 +24,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application messages []Message selected int settings *Settings @@ -34,6 +35,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -70,14 +72,19 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.View.SetTitle(widget.Name()) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.View.SetText(err.Error()) + }) } else { widget.messages = messages } - widget.display() - widget.View.ScrollToEnd() + widget.app.QueueUpdateDraw(func() { + widget.display() + widget.View.ScrollToEnd() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/gspreadsheets/widget.go b/modules/gspreadsheets/widget.go index f723cec0..b52b9455 100644 --- a/modules/gspreadsheets/widget.go +++ b/modules/gspreadsheets/widget.go @@ -11,6 +11,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -18,6 +19,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -29,7 +31,9 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { cells, _ := widget.Fetch() - widget.View.SetText(widget.contentFrom(cells)) + widget.app.QueueUpdateDraw(func() { + widget.View.SetText(widget.contentFrom(cells)) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/ipaddresses/ipapi/widget.go b/modules/ipaddresses/ipapi/widget.go index 24d6b1fd..22029278 100644 --- a/modules/ipaddresses/ipapi/widget.go +++ b/modules/ipaddresses/ipapi/widget.go @@ -16,6 +16,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application result string settings *Settings } @@ -40,6 +41,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -51,7 +53,10 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { // Refresh refresh the module func (widget *Widget) Refresh() { widget.ipinfo() - widget.View.SetText(widget.result) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetText(widget.result) + }) } //this method reads the config and calls ipinfo for ip information diff --git a/modules/ipaddresses/ipinfo/widget.go b/modules/ipaddresses/ipinfo/widget.go index 0f282519..5edc3a40 100644 --- a/modules/ipaddresses/ipinfo/widget.go +++ b/modules/ipaddresses/ipinfo/widget.go @@ -14,6 +14,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application result string settings *Settings } @@ -33,6 +34,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -43,9 +45,11 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { widget.ipinfo() - widget.View.Clear() - widget.View.SetText(widget.result) + widget.app.QueueUpdateDraw(func() { + widget.View.Clear() + widget.View.SetText(widget.result) + }) } //this method reads the config and calls ipinfo for ip information diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index e4047310..16daa58d 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -28,6 +28,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application selected int settings *Settings view *View @@ -38,6 +39,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -67,11 +69,16 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.View.SetTitle(widget.ContextualTitle(widget.Name())) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(widget.Name())) + widget.View.SetText(err.Error()) + }) } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/jira/widget.go b/modules/jira/widget.go index 8a8713c8..bb16f368 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -26,6 +26,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application result *SearchResult selected int settings *Settings @@ -36,6 +37,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -60,13 +62,18 @@ func (widget *Widget) Refresh() { if err != nil { widget.result = nil widget.View.SetWrap(true) - widget.View.SetTitle(widget.Name()) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.View.SetText(err.Error()) + }) } else { widget.result = searchResult } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/mercurial/widget.go b/modules/mercurial/widget.go index cffe384b..51b36a7c 100644 --- a/modules/mercurial/widget.go +++ b/modules/mercurial/widget.go @@ -65,7 +65,11 @@ func (widget *Widget) Checkout() { repoToCheckout.checkout(text) widget.pages.RemovePage("modal") widget.app.SetFocus(widget.View) - widget.display() + + widget.app.QueueUpdateDraw(func() { + widget.display() + }) + widget.Refresh() } @@ -84,7 +88,10 @@ func (widget *Widget) Refresh() { repoPaths := wtf.ToStrs(widget.settings.repositories) widget.Data = widget.mercurialRepos(repoPaths) - widget.display() + + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 73c24039..962f4fa5 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -11,6 +11,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application client *Client settings *Settings } @@ -19,6 +20,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -38,9 +40,6 @@ func (widget *Widget) Refresh() { appName = app.Name } - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.Name(), appName))) - widget.View.Clear() - var content string if depErr != nil { widget.View.SetWrap(true) @@ -50,7 +49,11 @@ func (widget *Widget) Refresh() { content = widget.contentFrom(deploys) } - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.Name(), appName))) + widget.View.Clear() + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/opsgenie/widget.go b/modules/opsgenie/widget.go index d6d34b2a..f1e7bca3 100644 --- a/modules/opsgenie/widget.go +++ b/modules/opsgenie/widget.go @@ -11,6 +11,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -18,6 +19,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -32,8 +34,6 @@ func (widget *Widget) Refresh() { widget.settings.schedule, ) - widget.View.SetTitle(widget.ContextualTitle(widget.Name())) - var content string if err != nil { widget.View.SetWrap(true) @@ -43,7 +43,10 @@ func (widget *Widget) Refresh() { content = widget.contentFrom(data) } - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(widget.Name())) + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index 4db3f72b..3e21d25b 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -12,6 +12,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -19,6 +20,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -42,8 +44,10 @@ func (widget *Widget) Refresh() { incidents, err2 = GetIncidents(widget.settings.apiKey) } - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name()))) - widget.View.Clear() + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name()))) + widget.View.Clear() + }) var content string if err1 != nil || err2 != nil { @@ -59,7 +63,9 @@ func (widget *Widget) Refresh() { content = widget.contentFrom(onCalls, incidents) } - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/resourceusage/widget.go b/modules/resourceusage/widget.go index ed7d1a2f..fe82f1ee 100644 --- a/modules/resourceusage/widget.go +++ b/modules/resourceusage/widget.go @@ -18,6 +18,7 @@ var ok = true type Widget struct { wtf.BarGraph + app *tview.Application settings *Settings } @@ -26,6 +27,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ BarGraph: wtf.NewBarGraph(app, settings.common.Name, settings.common.ConfigKey, false), + app: app, settings: settings, } @@ -39,7 +41,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { // MakeGraph - Load the dead drop stats func MakeGraph(widget *Widget) { - cpuStats, err := cpu.Percent(time.Duration(0), true) if err != nil { return @@ -114,8 +115,9 @@ func (widget *Widget) Refresh() { widget.View.Clear() - display(widget) - + widget.app.QueueUpdateDraw(func() { + display(widget) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 889d73c4..a88deab0 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -27,6 +27,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application items *Result selected int settings *Settings @@ -37,6 +38,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -63,13 +65,18 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.View.SetTitle(widget.Name()) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.View.SetText(err.Error()) + }) } else { widget.items = &items.Results } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/spotify/widget.go b/modules/spotify/widget.go index b35c0838..081b9447 100644 --- a/modules/spotify/widget.go +++ b/modules/spotify/widget.go @@ -21,6 +21,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application settings *Settings spotigopher.Info spotigopher.SpotifyClient @@ -34,7 +35,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * Info: spotigopher.Info{}, SpotifyClient: spotifyClient, - settings: settings, + + app: app, + settings: settings, } widget.settings.common.RefreshInterval = 5 @@ -54,7 +57,9 @@ func (w *Widget) refreshSpotifyInfos() error { } func (w *Widget) Refresh() { - w.render() + w.app.QueueUpdateDraw(func() { + w.render() + }) } func (w *Widget) render() { diff --git a/modules/spotifyweb/widget.go b/modules/spotifyweb/widget.go index fe91efde..ed102d3e 100644 --- a/modules/spotifyweb/widget.go +++ b/modules/spotifyweb/widget.go @@ -48,6 +48,8 @@ type Widget struct { wtf.TextWidget Info + + app *tview.Application client *spotify.Client clientChan chan *spotify.Client playerState *spotify.PlayerState @@ -95,7 +97,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), - Info: Info{}, + Info: Info{}, + + app: app, client: client, clientChan: tempClientChan, playerState: playerState, @@ -173,7 +177,9 @@ func (w *Widget) refreshSpotifyInfos() error { // Refresh refreshes the current view of the widget func (w *Widget) Refresh() { - w.render() + w.app.QueueUpdateDraw(func() { + w.render() + }) } func (w *Widget) render() { diff --git a/modules/system/widget.go b/modules/system/widget.go index 113cfbc8..802d9a2b 100644 --- a/modules/system/widget.go +++ b/modules/system/widget.go @@ -14,7 +14,7 @@ type Widget struct { Date string Version string - app *tview.App + app *tview.Application settings *Settings systemInfo *SystemInfo } diff --git a/modules/todo/widget.go b/modules/todo/widget.go index 4036fbd7..51160637 100644 --- a/modules/todo/widget.go +++ b/modules/todo/widget.go @@ -267,8 +267,10 @@ func (widget *Widget) addSaveButton(form *tview.Form, fctn func()) { func (widget *Widget) modalFocus(form *tview.Form) { frame := widget.modalFrame(form) widget.pages.AddPage("modal", frame, false, true) - widget.app.SetFocus(frame) - widget.app.Draw() + + widget.app.QueueUpdateDraw(func() { + widget.app.SetFocus(frame) + }) } func (widget *Widget) modalForm(lbl, text string) *tview.Form { diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index 9f044edd..1d583244 100644 --- a/modules/travisci/widget.go +++ b/modules/travisci/widget.go @@ -26,6 +26,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application builds *Builds selected int settings *Settings @@ -36,6 +37,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -58,13 +60,18 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.View.SetTitle(widget.Name()) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.View.SetText(err.Error()) + }) } else { widget.builds = builds } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/trello/widget.go b/modules/trello/widget.go index fd79984f..e6b46cb2 100644 --- a/modules/trello/widget.go +++ b/modules/trello/widget.go @@ -11,6 +11,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -18,6 +19,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -40,24 +42,27 @@ func (widget *Widget) Refresh() { widget.settings.list, ) + var title string var content string + if err != nil { widget.View.SetWrap(true) - widget.View.SetTitle(widget.Name()) + title = widget.Name() content = err.Error() } else { widget.View.SetWrap(false) - widget.View.SetTitle( - fmt.Sprintf( - "[white]%s: [green]%s ", - widget.Name(), - widget.settings.board, - ), + title = fmt.Sprintf( + "[white]%s: [green]%s ", + widget.Name(), + widget.settings.board, ) content = widget.contentFrom(searchResult) } - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(title) + widget.View.SetText(content) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/unknown/widget.go b/modules/unknown/widget.go index 053c9bad..b9559805 100644 --- a/modules/unknown/widget.go +++ b/modules/unknown/widget.go @@ -10,6 +10,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application settings *Settings } @@ -17,6 +18,7 @@ func NewWidget(app *tview.Application, name string, settings *Settings) *Widget widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -26,9 +28,11 @@ func NewWidget(app *tview.Application, name string, settings *Settings) *Widget /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name()))) - widget.View.Clear() + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name()))) + widget.View.Clear() - content := fmt.Sprintf("Widget %s does not exist", widget.Name()) - widget.View.SetText(content) + content := fmt.Sprintf("Widget %s does not exist", widget.Name()) + widget.View.SetText(content) + }) } diff --git a/modules/victorops/widget.go b/modules/victorops/widget.go index a3e0fcdb..ac92e64c 100644 --- a/modules/victorops/widget.go +++ b/modules/victorops/widget.go @@ -20,6 +20,7 @@ const HelpText = ` type Widget struct { wtf.TextWidget + app *tview.Application teams []OnCallTeam settings *Settings } @@ -47,12 +48,17 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.View.SetText(err.Error()) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetText(err.Error()) + }) } else { widget.teams = teams } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } func (widget *Widget) display() { diff --git a/modules/zendesk/widget.go b/modules/zendesk/widget.go index 11c06efa..35650973 100644 --- a/modules/zendesk/widget.go +++ b/modules/zendesk/widget.go @@ -12,6 +12,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application result *TicketArray selected int settings *Settings @@ -21,6 +22,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -39,7 +41,9 @@ func (widget *Widget) Refresh() { widget.result = ticketArray } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */