From 42821b31029f9abb65aa1a37989fa66d73323cfd Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Sat, 11 May 2019 12:10:30 -0400 Subject: [PATCH] Clean up drawing functionality Fix up a bunch of missed places that can use the standardized `Redraw` method --- modules/clocks/display.go | 3 ++- modules/cryptoexchanges/bittrex/display.go | 4 ++-- modules/cryptoexchanges/bittrex/widget.go | 8 ++------ modules/cryptoexchanges/blockfolio/widget.go | 6 ++---- modules/cryptoexchanges/cryptolive/widget.go | 6 ++---- modules/ipaddresses/ipapi/widget.go | 4 +--- modules/logger/widget.go | 5 +---- modules/spotify/widget.go | 1 - modules/spotifyweb/widget.go | 1 - modules/twitter/widget.go | 2 +- modules/victorops/widget.go | 11 ----------- 11 files changed, 13 insertions(+), 38 deletions(-) diff --git a/modules/clocks/display.go b/modules/clocks/display.go index 58e46e52..eae5d075 100644 --- a/modules/clocks/display.go +++ b/modules/clocks/display.go @@ -6,7 +6,8 @@ import ( func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) { if len(clocks) == 0 { - widget.View.SetText(fmt.Sprintf("\n%s", " no timezone data available")) + title := fmt.Sprintf("\n%s", " no timezone data available") + widget.Redraw(widget.CommonSettings.Title, title, true) return } diff --git a/modules/cryptoexchanges/bittrex/display.go b/modules/cryptoexchanges/bittrex/display.go index cb8b5001..f9ddeca3 100644 --- a/modules/cryptoexchanges/bittrex/display.go +++ b/modules/cryptoexchanges/bittrex/display.go @@ -8,12 +8,12 @@ import ( func (widget *Widget) display() { if ok == false { - widget.View.SetText(errorText) + widget.Redraw(widget.CommonSettings.Title, errorText, true) return } summaryText := widget.summaryText(&widget.summaryList) - widget.View.SetText(summaryText) + widget.Redraw(widget.CommonSettings.Title, summaryText, false) } func (widget *Widget) summaryText(list *summaryList) string { diff --git a/modules/cryptoexchanges/bittrex/widget.go b/modules/cryptoexchanges/bittrex/widget.go index 0d366d84..95683fe3 100644 --- a/modules/cryptoexchanges/bittrex/widget.go +++ b/modules/cryptoexchanges/bittrex/widget.go @@ -80,9 +80,7 @@ func makeMarketCurrency(name string) *mCurrency { func (widget *Widget) Refresh() { widget.updateSummary() - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -142,9 +140,7 @@ func (widget *Widget) updateSummary() { } } - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } func makeRequest(baseName, marketName string) *http.Request { diff --git a/modules/cryptoexchanges/blockfolio/widget.go b/modules/cryptoexchanges/blockfolio/widget.go index b1148607..5aa41472 100644 --- a/modules/cryptoexchanges/blockfolio/widget.go +++ b/modules/cryptoexchanges/blockfolio/widget.go @@ -36,15 +36,13 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { positions, err := Fetch(widget.device_token) if err != nil { + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) return } content := widget.contentFrom(positions) - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.CommonSettings.Title) - widget.View.SetText(content) - }) + widget.Redraw(widget.CommonSettings.Title, content, false) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/cryptoexchanges/cryptolive/widget.go b/modules/cryptoexchanges/cryptolive/widget.go index 651d1170..82ef76e0 100644 --- a/modules/cryptoexchanges/cryptolive/widget.go +++ b/modules/cryptoexchanges/cryptolive/widget.go @@ -48,9 +48,7 @@ func (widget *Widget) Refresh() { widget.toplistWidget.Refresh(&wg) wg.Wait() - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -60,5 +58,5 @@ func (widget *Widget) display() { str += widget.priceWidget.Result str += widget.toplistWidget.Result - widget.View.SetText(fmt.Sprintf("\n%s", str)) + widget.Redraw(widget.CommonSettings.Title, fmt.Sprintf("\n%s", str), false) } diff --git a/modules/ipaddresses/ipapi/widget.go b/modules/ipaddresses/ipapi/widget.go index 22029278..d7118b48 100644 --- a/modules/ipaddresses/ipapi/widget.go +++ b/modules/ipaddresses/ipapi/widget.go @@ -54,9 +54,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { widget.ipinfo() - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(widget.result) - }) + widget.Redraw(widget.CommonSettings.Title, widget.result, false) } //this method reads the config and calls ipinfo for ip information diff --git a/modules/logger/widget.go b/modules/logger/widget.go index b58d10e6..1a99965d 100644 --- a/modules/logger/widget.go +++ b/modules/logger/widget.go @@ -40,10 +40,7 @@ func (widget *Widget) Refresh() { logLines := widget.tailFile() - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.CommonSettings.Title) - widget.View.SetText(widget.contentFrom(logLines)) - }) + widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(logLines), false) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/spotify/widget.go b/modules/spotify/widget.go index dfb151fb..cc0f40ec 100644 --- a/modules/spotify/widget.go +++ b/modules/spotify/widget.go @@ -47,7 +47,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * widget.View.SetWrap(true) widget.View.SetWordWrap(true) - widget.View.SetTitle(fmt.Sprint("[green]Spotify[white]")) widget.HelpfulWidget.SetView(widget.View) diff --git a/modules/spotifyweb/widget.go b/modules/spotifyweb/widget.go index 047b37ae..b052476d 100644 --- a/modules/spotifyweb/widget.go +++ b/modules/spotifyweb/widget.go @@ -144,7 +144,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * widget.View.SetWrap(true) widget.View.SetWordWrap(true) - widget.View.SetTitle("[green]Spotify Web[white]") widget.HelpfulWidget.SetView(widget.View) diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index f26564a0..c2e32f61 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -78,7 +78,7 @@ func (widget *Widget) display() { if len(tweets) == 0 { str := fmt.Sprintf("\n\n\n%s", wtf.CenterText("[lightblue]No Tweets[white]", 50)) - widget.View.SetText(str) + widget.Redraw(title, str, true) return } diff --git a/modules/victorops/widget.go b/modules/victorops/widget.go index 735c3dcd..5fcffffd 100644 --- a/modules/victorops/widget.go +++ b/modules/victorops/widget.go @@ -43,7 +43,6 @@ func (widget *Widget) Refresh() { } teams, err := Fetch(widget.settings.apiID, widget.settings.apiKey) - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) if err != nil { widget.Redraw(widget.CommonSettings.Title, err.Error(), true) @@ -53,16 +52,6 @@ func (widget *Widget) Refresh() { } } -func (widget *Widget) display() { - if widget.teams == nil { - return - } - - widget.View.SetWrap(false) - widget.View.Clear() - widget.View.SetText(widget.contentFrom(widget.teams)) -} - func (widget *Widget) contentFrom(teams []OnCallTeam) string { var str string