diff --git a/generator/textwidget.tpl b/generator/textwidget.tpl index 3c1e6513..f39df08e 100644 --- a/generator/textwidget.tpl +++ b/generator/textwidget.tpl @@ -18,7 +18,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application settings *Settings } @@ -28,15 +27,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } widget.initializeKeyboardControls() widget.View.SetInputCapture(widget.InputCapture) - widget.unselect() - widget.View.SetScrollable(true) widget.View.SetRegions(true) @@ -50,22 +46,11 @@ 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.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) display() { - widget.View.SetWrap(false) - - widget.View.Clear() - widget.View.SetText("Some Text") - widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + widget.Redraw(widget.CommonSettings.Title, "Some text", false) } - -func (widget *Widget) unselect() { - widget.selected = -1 - widget.display() -} \ No newline at end of file diff --git a/modules/bamboohr/widget.go b/modules/bamboohr/widget.go index 890144b1..8885fe6c 100644 --- a/modules/bamboohr/widget.go +++ b/modules/bamboohr/widget.go @@ -42,10 +42,7 @@ func (widget *Widget) Refresh() { wtf.Now().Format(wtf.DateFormat), ) - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.View.SetText(widget.contentFrom(todayItems)) - }) + widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(todayItems), false) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/circleci/widget.go b/modules/circleci/widget.go index 718d6998..64f09b1b 100644 --- a/modules/circleci/widget.go +++ b/modules/circleci/widget.go @@ -11,7 +11,6 @@ type Widget struct { wtf.TextWidget *Client - app *tview.Application settings *Settings } @@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { TextWidget: wtf.NewTextWidget(app, settings.common, false), Client: NewClient(settings.apiKey), - app: app, settings: settings, } @@ -36,19 +34,17 @@ func (widget *Widget) Refresh() { builds, err := widget.Client.BuildsFor() + title := fmt.Sprintf("%s - Builds", widget.CommonSettings.Title) var content string + wrap := false if err != nil { - widget.View.SetWrap(true) + wrap = true content = err.Error() } else { - widget.View.SetWrap(false) content = widget.contentFrom(builds) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.CommonSettings.Title)) - widget.View.SetText(content) - }) + widget.Redraw(title, content, wrap) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index 83cd37fc..6ecbdf6e 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -12,7 +12,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application args []string cmd string settings *Settings @@ -23,7 +22,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, args: settings.args, cmd: settings.cmd, settings: settings, @@ -41,10 +39,7 @@ func (widget *Widget) Refresh() { ansiTitle := tview.TranslateANSI(widget.String()) ansiResult := tview.TranslateANSI(result) - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(ansiTitle) - widget.View.SetText(ansiResult) - }) + widget.Redraw(ansiTitle, ansiResult, false) } // String returns the string representation of the widget diff --git a/modules/datadog/widget.go b/modules/datadog/widget.go index c15592be..137dfbf1 100644 --- a/modules/datadog/widget.go +++ b/modules/datadog/widget.go @@ -39,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, settings: settings, } diff --git a/modules/gcal/display.go b/modules/gcal/display.go index 6f9e2ddc..65ee7221 100644 --- a/modules/gcal/display.go +++ b/modules/gcal/display.go @@ -29,13 +29,12 @@ func (widget *Widget) display() { return } - widget.View.SetTitle(widget.ContextualTitle(widget.settings.common.Title)) - widget.View.SetText(widget.contentFrom(widget.calEvents)) + widget.TextWidget.Redraw(widget.settings.common.Title, widget.contentFrom(widget.calEvents), false) } func (widget *Widget) contentFrom(calEvents []*CalEvent) string { if (calEvents == nil) || (len(calEvents) == 0) { - return "" + return "No calendar events" } var str string diff --git a/modules/gcal/widget.go b/modules/gcal/widget.go index dfac54a1..964fc4e3 100644 --- a/modules/gcal/widget.go +++ b/modules/gcal/widget.go @@ -1,8 +1,6 @@ package gcal import ( - "time" - "github.com/rivo/tview" "github.com/wtfutil/wtf/wtf" ) @@ -12,7 +10,6 @@ type Widget struct { app *tview.Application calEvents []*CalEvent - ch chan struct{} settings *Settings } @@ -21,27 +18,21 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { TextWidget: wtf.NewTextWidget(app, settings.common, true), app: app, - ch: make(chan struct{}), settings: settings, } - go updateLoop(&widget) - return &widget } /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Disable() { - close(widget.ch) widget.TextWidget.Disable() } func (widget *Widget) Refresh() { if isAuthenticated() { - widget.app.QueueUpdateDraw(func() { - widget.fetchAndDisplayEvents() - }) + widget.fetchAndDisplayEvents() return } @@ -59,27 +50,5 @@ func (widget *Widget) fetchAndDisplayEvents() { widget.calEvents = calEvents } - widget.app.QueueUpdateDraw(func() { - widget.display() - }) -} - -func updateLoop(widget *Widget) { - if widget.settings.textInterval == 0 { - return - } - - tick := time.NewTicker(time.Duration(widget.settings.textInterval) * time.Second) - defer tick.Stop() -outer: - for { - select { - case <-tick.C: - widget.app.QueueUpdateDraw(func() { - widget.display() - }) - case <-widget.ch: - break outer - } - } + widget.display() } diff --git a/modules/gerrit/display.go b/modules/gerrit/display.go index ecb048a7..8fc9e188 100644 --- a/modules/gerrit/display.go +++ b/modules/gerrit/display.go @@ -8,11 +8,11 @@ func (widget *Widget) display() { project := widget.currentGerritProject() if project == nil { - widget.View.SetText(fmt.Sprintf("%s", " Gerrit project data is unavailable (1)")) + widget.Redraw(widget.CommonSettings.Title, "Gerrit project data is unavailable", true) return } - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s- %s", widget.CommonSettings.Title, widget.title(project)))) + title := fmt.Sprintf("%s- %s", widget.CommonSettings.Title, widget.title(project)) _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n" @@ -25,7 +25,7 @@ func (widget *Widget) display() { str = str + " [red]My Outgoing Reviews[white]\n" str = str + widget.displayMyOutgoingReviews(project, widget.settings.username) - widget.View.SetText(str) + widget.Redraw(title, str, false) } func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username string) string { diff --git a/modules/gerrit/widget.go b/modules/gerrit/widget.go index 41de5bce..e1536ce0 100644 --- a/modules/gerrit/widget.go +++ b/modules/gerrit/widget.go @@ -39,7 +39,6 @@ type Widget struct { GerritProjects []*GerritProject Idx int - app *tview.Application selected int settings *Settings } @@ -56,7 +55,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * Idx: 0, - app: app, settings: settings, } @@ -99,9 +97,7 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(err.Error()) - }) + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) return } widget.gerrit = gerrit @@ -111,10 +107,7 @@ func (widget *Widget) Refresh() { project.Refresh(widget.settings.username) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/git/display.go b/modules/git/display.go index 4db18818..85712c2c 100644 --- a/modules/git/display.go +++ b/modules/git/display.go @@ -9,12 +9,11 @@ import ( func (widget *Widget) display() { repoData := widget.currentData() if repoData == nil { - widget.View.SetText(" Git repo data is unavailable ") + widget.Redraw(widget.CommonSettings.Title, " Git repo data is unavailable ", false) return } title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, repoData.Repository) - widget.View.SetTitle(widget.ContextualTitle(title)) _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GitRepos), widget.Idx, width) + "\n" @@ -25,7 +24,7 @@ func (widget *Widget) display() { str = str + "\n" str = str + widget.formatCommits(repoData.Commits) - widget.View.SetText(str) + widget.Redraw(title, str, false) } func (widget *Widget) formatChanges(data []string) string { diff --git a/modules/git/widget.go b/modules/git/widget.go index 0c44252c..41026d6c 100644 --- a/modules/git/widget.go +++ b/modules/git/widget.go @@ -97,9 +97,7 @@ func (widget *Widget) Refresh() { return widget.GitRepos[i].Path < widget.GitRepos[j].Path }) - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -125,9 +123,11 @@ func (widget *Widget) addCancelButton(form *tview.Form) { } func (widget *Widget) modalFocus(form *tview.Form) { - frame := widget.modalFrame(form) - widget.pages.AddPage("modal", frame, false, true) - widget.app.SetFocus(frame) + widget.app.QueueUpdateDraw(func() { + frame := widget.modalFrame(form) + widget.pages.AddPage("modal", frame, false, true) + widget.app.SetFocus(frame) + }) } func (widget *Widget) modalForm(lbl, text string) *tview.Form { diff --git a/modules/github/display.go b/modules/github/display.go index 68f8edf0..8d49d65d 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -8,13 +8,12 @@ import ( func (widget *Widget) display() { repo := widget.currentGithubRepo() + title := fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.title(repo)) if repo == nil { - widget.View.SetText(" GitHub repo data is unavailable ") + widget.TextWidget.Redraw(title, " GitHub repo data is unavailable ", false) return } - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.title(repo)))) - _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GithubRepos), widget.Idx, width) + "\n" str = str + " [red]Stats[white]\n" @@ -26,7 +25,7 @@ func (widget *Widget) display() { str = str + " [red]My Pull Requests[white]\n" str = str + widget.displayMyPullRequests(repo, widget.settings.username) - widget.View.SetText(str) + widget.TextWidget.Redraw(title, str, false) } func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { diff --git a/modules/gitlab/display.go b/modules/gitlab/display.go index 2501d11c..040bef5f 100644 --- a/modules/gitlab/display.go +++ b/modules/gitlab/display.go @@ -8,11 +8,11 @@ func (widget *Widget) display() { project := widget.currentGitlabProject() if project == nil { - widget.View.SetText(" Gitlab project data is unavailable ") + widget.Redraw(widget.CommonSettings.Title, " Gitlab project data is unavailable ", true) return } - widget.View.SetTitle(fmt.Sprintf("%s- %s", widget.CommonSettings.Title, widget.title(project))) + title := fmt.Sprintf("%s- %s", widget.CommonSettings.Title, widget.title(project)) _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.GitlabProjects), widget.Idx, width) + "\n" @@ -24,8 +24,7 @@ func (widget *Widget) display() { str = str + "\n" str = str + " [red]My Merge Requests[white]\n" str = str + widget.displayMyMergeRequests(project, widget.settings.username) - - widget.View.SetText(str) + widget.Redraw(title, str, false) } func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username string) string { diff --git a/modules/gitlab/widget.go b/modules/gitlab/widget.go index d28ffaed..05aebe62 100644 --- a/modules/gitlab/widget.go +++ b/modules/gitlab/widget.go @@ -26,7 +26,6 @@ type Widget struct { GitlabProjects []*GitlabProject Idx int - app *tview.Application gitlab *glb.Client settings *Settings } @@ -46,7 +45,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * Idx: 0, - app: app, gitlab: gitlab, settings: settings, } @@ -68,9 +66,7 @@ func (widget *Widget) Refresh() { project.Refresh() } - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } func (widget *Widget) Next() { diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index 319c6231..4bf7ff2c 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -26,7 +26,8 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application + app *tview.Application + messages []Message selected int settings *Settings @@ -80,19 +81,12 @@ func (widget *Widget) Refresh() { if err != nil { widget.View.SetWrap(true) - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.CommonSettings.Title) - widget.View.SetText(err.Error()) - }) - } else { - widget.messages = messages + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) + return } + widget.messages = messages - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.display() - widget.View.ScrollToEnd() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -102,11 +96,13 @@ func (widget *Widget) display() { return } - widget.View.SetWrap(true) - widget.View.Clear() - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.roomURI))) - widget.View.SetText(widget.contentFrom(widget.messages)) - widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + title := fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.roomURI) + + widget.Redraw(title, widget.contentFrom(widget.messages), true) + widget.app.QueueUpdateDraw(func() { + widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + widget.View.ScrollToEnd() + }) } func (widget *Widget) contentFrom(messages []Message) string { diff --git a/modules/gspreadsheets/widget.go b/modules/gspreadsheets/widget.go index b52b9455..d1728474 100644 --- a/modules/gspreadsheets/widget.go +++ b/modules/gspreadsheets/widget.go @@ -11,7 +11,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application settings *Settings } @@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -31,9 +29,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { cells, _ := widget.Fetch() - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(widget.contentFrom(cells)) - }) + widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(cells), false) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index 5caf66f1..b8c97803 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -30,7 +30,8 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application + app *tview.Application + stories []Story selected int settings *Settings @@ -89,9 +90,7 @@ func (widget *Widget) Refresh() { widget.stories = stories } - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -101,12 +100,11 @@ func (widget *Widget) display() { return } - widget.View.SetWrap(false) - - widget.View.Clear() - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %sstories", widget.CommonSettings.Title, widget.settings.storyType))) - widget.View.SetText(widget.contentFrom(widget.stories)) - widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + title := fmt.Sprintf("%s - %sstories", widget.CommonSettings.Title, widget.settings.storyType) + widget.Redraw(title, widget.contentFrom(widget.stories), false) + widget.app.QueueUpdateDraw(func() { + widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + }) } func (widget *Widget) contentFrom(stories []Story) string { diff --git a/modules/ipaddresses/ipinfo/widget.go b/modules/ipaddresses/ipinfo/widget.go index 5edc3a40..1454d987 100644 --- a/modules/ipaddresses/ipinfo/widget.go +++ b/modules/ipaddresses/ipinfo/widget.go @@ -14,7 +14,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application result string settings *Settings } @@ -34,7 +33,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -46,10 +44,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { widget.ipinfo() - widget.app.QueueUpdateDraw(func() { - widget.View.Clear() - widget.View.SetText(widget.result) - }) + widget.TextWidget.Redraw(widget.CommonSettings.Title, widget.result, false) } //this method reads the config and calls ipinfo for ip information diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index 000e34b2..3d453e40 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -29,7 +29,8 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application + app *tview.Application + selected int settings *Settings view *View @@ -73,17 +74,11 @@ func (widget *Widget) Refresh() { widget.view = view if err != nil { - widget.View.SetWrap(true) - - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(err.Error()) - }) + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) + return } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -93,12 +88,12 @@ func (widget *Widget) display() { return } - widget.View.SetWrap(false) + title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings.Title, widget.view.Name) - widget.View.Clear() - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s: [red]%s", widget.CommonSettings.Title, widget.view.Name))) - widget.View.SetText(widget.contentFrom(widget.view)) - widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + widget.Redraw(title, widget.contentFrom(widget.view), false) + widget.app.QueueUpdateDraw(func() { + widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + }) } func (widget *Widget) contentFrom(view *View) string { diff --git a/modules/jira/widget.go b/modules/jira/widget.go index bef1449b..e7bf259f 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -2,7 +2,6 @@ package jira import ( "fmt" - "strconv" "github.com/rivo/tview" @@ -27,7 +26,8 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application + app *tview.Application + result *SearchResult selected int settings *Settings @@ -67,19 +67,11 @@ func (widget *Widget) Refresh() { if err != nil { widget.result = nil - widget.View.SetWrap(true) - - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.CommonSettings.Title) - widget.View.SetText(err.Error()) - }) - } else { - widget.result = searchResult + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) + return } - - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.result = searchResult + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -88,14 +80,13 @@ func (widget *Widget) display() { if widget.result == nil { return } - widget.View.SetWrap(false) str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings.Title, widget.settings.projects) - widget.View.Clear() - widget.View.SetTitle(widget.ContextualTitle(str)) - widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.result))) - widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + widget.Redraw(str, widget.contentFrom(widget.result), false) + widget.app.QueueUpdateDraw(func() { + widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() + }) } func (widget *Widget) next() { diff --git a/modules/mercurial/display.go b/modules/mercurial/display.go index 8dae5e94..9ffbc3b0 100644 --- a/modules/mercurial/display.go +++ b/modules/mercurial/display.go @@ -9,12 +9,11 @@ import ( func (widget *Widget) display() { repoData := widget.currentData() if repoData == nil { - widget.View.SetText(" Mercurial repo data is unavailable ") + widget.Redraw(widget.CommonSettings.Title, " Mercurial repo data is unavailable ", false) return } title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, repoData.Repository) - widget.View.SetTitle(widget.ContextualTitle(title)) _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" @@ -25,7 +24,7 @@ func (widget *Widget) display() { str = str + "\n" str = str + widget.formatCommits(repoData.Commits) - widget.View.SetText(str) + widget.Redraw(title, str, false) } func (widget *Widget) formatChanges(data []string) string { diff --git a/modules/mercurial/widget.go b/modules/mercurial/widget.go index d6625c20..36748dd4 100644 --- a/modules/mercurial/widget.go +++ b/modules/mercurial/widget.go @@ -71,9 +71,7 @@ func (widget *Widget) Checkout() { widget.pages.RemovePage("modal") widget.app.SetFocus(widget.View) - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() widget.Refresh() } @@ -86,7 +84,6 @@ func (widget *Widget) Pull() { repoToPull := widget.Data[widget.Idx] repoToPull.pull() widget.Refresh() - } func (widget *Widget) Refresh() { @@ -94,9 +91,7 @@ func (widget *Widget) Refresh() { widget.Data = widget.mercurialRepos(repoPaths) - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -122,9 +117,11 @@ func (widget *Widget) addCancelButton(form *tview.Form) { } func (widget *Widget) modalFocus(form *tview.Form) { - frame := widget.modalFrame(form) - widget.pages.AddPage("modal", frame, false, true) - widget.app.SetFocus(frame) + widget.app.QueueUpdateDraw(func() { + frame := widget.modalFrame(form) + widget.pages.AddPage("modal", frame, false, true) + widget.app.SetFocus(frame) + }) } func (widget *Widget) modalForm(lbl, text string) *tview.Form { diff --git a/modules/nbascore/widget.go b/modules/nbascore/widget.go index 6f6cd9bd..ac7a47d6 100644 --- a/modules/nbascore/widget.go +++ b/modules/nbascore/widget.go @@ -25,7 +25,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application language string result string settings *Settings @@ -40,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, settings: settings, } @@ -55,39 +53,32 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * } func (widget *Widget) Refresh() { - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.nbascore() - }) + widget.Redraw(widget.CommonSettings.Title, widget.nbascore(), false) } -func (widget *Widget) nbascore() { +func (widget *Widget) nbascore() string { cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days curString := cur.Format("20060102") // Need 20060102 format to feed to api client := &http.Client{} req, err := http.NewRequest("GET", "http://data.nba.net/10s/prod/v1/"+curString+"/scoreboard.json", nil) if err != nil { - widget.result = err.Error() - return + return err.Error() } req.Header.Set("Accept-Language", widget.language) req.Header.Set("User-Agent", "curl") response, err := client.Do(req) if err != nil { - widget.result = err.Error() - return + return err.Error() } defer response.Body.Close() if response.StatusCode != 200 { - widget.result = err.Error() - return + return err.Error() } // Get data from data.nba.net and check if successful contents, err := ioutil.ReadAll(response.Body) if err != nil { - widget.result = err.Error() - return + return err.Error() } result := map[string]interface{}{} json.Unmarshal(contents, &result) @@ -146,6 +137,5 @@ func (widget *Widget) nbascore() { } allGame += fmt.Sprintf("%s%5s%v[white] %s %3s [white]vs %s%-3s %s\n", qColor, "Q", quarter, vTeam, vScore, hColor, hScore, hTeam) // Format the score and store in allgame } - widget.View.SetText(allGame) - + return allGame } diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 3a6b611b..62d7d971 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -11,7 +11,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application client *Client settings *Settings } @@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -41,19 +39,16 @@ func (widget *Widget) Refresh() { } var content string + title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, appName) + wrap := false if depErr != nil { - widget.View.SetWrap(true) + wrap = true content = depErr.Error() } else { - widget.View.SetWrap(false) content = widget.contentFrom(deploys) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, appName))) - widget.View.Clear() - widget.View.SetText(content) - }) + widget.Redraw(title, content, wrap) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/opsgenie/widget.go b/modules/opsgenie/widget.go index 149e2a74..aef05445 100644 --- a/modules/opsgenie/widget.go +++ b/modules/opsgenie/widget.go @@ -11,7 +11,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application settings *Settings } @@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -35,18 +33,15 @@ func (widget *Widget) Refresh() { ) var content string + wrap := false if err != nil { - widget.View.SetWrap(true) + wrap = true content = err.Error() } else { - widget.View.SetWrap(false) content = widget.contentFrom(data) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.View.SetText(content) - }) + widget.Redraw(widget.CommonSettings.Title, content, wrap) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index 70d931de..a032e43f 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -12,7 +12,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application settings *Settings } @@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -44,14 +42,10 @@ func (widget *Widget) Refresh() { incidents, err2 = GetIncidents(widget.settings.apiKey) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.View.Clear() - }) - var content string + wrap := false if err1 != nil || err2 != nil { - widget.View.SetWrap(true) + wrap = true if err1 != nil { content = content + err1.Error() } @@ -63,9 +57,7 @@ func (widget *Widget) Refresh() { content = widget.contentFrom(onCalls, incidents) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(content) - }) + widget.Redraw(widget.CommonSettings.Title, content, wrap) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/power/widget.go b/modules/power/widget.go index 5ef57f08..0dfa167c 100644 --- a/modules/power/widget.go +++ b/modules/power/widget.go @@ -12,7 +12,6 @@ type Widget struct { Battery *Battery - app *tview.Application settings *Settings } @@ -22,7 +21,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { Battery: NewBattery(), - app: app, settings: settings, } @@ -39,7 +37,5 @@ func (widget *Widget) Refresh() { content = content + "\n" content = content + widget.Battery.String() - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(content) - }) + widget.Redraw(widget.CommonSettings.Title, content, true) } diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 95a6e2d5..8b23af71 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -28,7 +28,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application items *Result selected int settings *Settings @@ -41,7 +40,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, settings: settings, } @@ -69,19 +67,12 @@ func (widget *Widget) Refresh() { ) if err != nil { - widget.View.SetWrap(true) - - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(err.Error()) - }) - } else { - widget.items = &items.Results + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) + return } + widget.items = &items.Results - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -91,12 +82,14 @@ func (widget *Widget) display() { return } - widget.View.SetWrap(false) - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.projectName))) - widget.View.SetText(widget.contentFrom(widget.items)) + title := fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.projectName) + widget.Redraw(title, widget.contentFrom(widget.items), false) } func (widget *Widget) contentFrom(result *Result) string { + if result == nil { + return "No results" + } var str string if len(result.Items) > widget.settings.count { result.Items = result.Items[:widget.settings.count] diff --git a/modules/security/widget.go b/modules/security/widget.go index b10b7013..368aaa1f 100644 --- a/modules/security/widget.go +++ b/modules/security/widget.go @@ -11,7 +11,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application settings *Settings } @@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -37,9 +35,7 @@ func (widget *Widget) Refresh() { data := NewSecurityData() data.Fetch() - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(widget.contentFrom(data)) - }) + widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(data), false) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/spotify/widget.go b/modules/spotify/widget.go index dc82836b..dfb151fb 100644 --- a/modules/spotify/widget.go +++ b/modules/spotify/widget.go @@ -21,7 +21,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application settings *Settings spotigopher.Info spotigopher.SpotifyClient @@ -38,7 +37,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * Info: spotigopher.Info{}, SpotifyClient: spotifyClient, - app: app, settings: settings, } @@ -63,19 +61,18 @@ func (w *Widget) refreshSpotifyInfos() error { } func (w *Widget) Refresh() { - w.app.QueueUpdateDraw(func() { - w.render() - }) + w.render() } func (w *Widget) render() { err := w.refreshSpotifyInfos() - w.View.Clear() + var content string if err != nil { - w.TextWidget.View.SetText(err.Error()) + content = err.Error() } else { - w.TextWidget.View.SetText(w.createOutput()) + content = w.createOutput() } + w.Redraw(w.CommonSettings.Title, content, true) } func (w *Widget) createOutput() string { diff --git a/modules/spotifyweb/widget.go b/modules/spotifyweb/widget.go index a5747c26..047b37ae 100644 --- a/modules/spotifyweb/widget.go +++ b/modules/spotifyweb/widget.go @@ -48,7 +48,6 @@ type Widget struct { Info - app *tview.Application client *spotify.Client clientChan chan *spotify.Client playerState *spotify.PlayerState @@ -99,7 +98,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * Info: Info{}, - app: app, client: client, clientChan: tempClientChan, playerState: playerState, @@ -181,18 +179,11 @@ func (w *Widget) refreshSpotifyInfos() error { // Refresh refreshes the current view of the widget func (w *Widget) Refresh() { - w.app.QueueUpdateDraw(func() { - w.render() - }) -} - -func (w *Widget) render() { err := w.refreshSpotifyInfos() - w.View.Clear() if err != nil { - w.TextWidget.View.SetText(err.Error()) + w.Redraw(w.CommonSettings.Title, err.Error(), true) } else { - w.TextWidget.View.SetText(w.createOutput()) + w.Redraw(w.CommonSettings.Title, w.createOutput(), false) } } diff --git a/modules/status/widget.go b/modules/status/widget.go index cf02188d..e205dae8 100644 --- a/modules/status/widget.go +++ b/modules/status/widget.go @@ -10,7 +10,6 @@ type Widget struct { CurrentIcon int - app *tview.Application settings *Settings } @@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { CurrentIcon: 0, - app: app, settings: settings, } @@ -30,9 +28,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(widget.animation()) - }) + widget.Redraw(widget.CommonSettings.Title, widget.animation(), false) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/system/widget.go b/modules/system/widget.go index 802d9a2b..d3f249b9 100644 --- a/modules/system/widget.go +++ b/modules/system/widget.go @@ -14,7 +14,6 @@ type Widget struct { Date string Version string - app *tview.Application settings *Settings systemInfo *SystemInfo } @@ -25,7 +24,6 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings) Date: date, - app: app, settings: settings, Version: version, } @@ -36,21 +34,18 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings) } func (widget *Widget) Refresh() { - widget.app.QueueUpdateDraw(func() { - widget.View.SetText( - fmt.Sprintf( - "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", - "Built", - widget.prettyDate(), - "Vers", - widget.Version, - "OS", - widget.systemInfo.ProductVersion, - "Build", - widget.systemInfo.BuildVersion, - ), - ) - }) + content := fmt.Sprintf( + "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", + "Built", + widget.prettyDate(), + "Vers", + widget.Version, + "OS", + widget.systemInfo.ProductVersion, + "Build", + widget.systemInfo.BuildVersion, + ) + widget.Redraw(widget.CommonSettings.Title, content, false) } func (widget *Widget) prettyDate() string { diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index d27fb24b..06beda1b 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -73,16 +73,13 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * // Refresh is only called once on start-up. Its job is to display the // text files that first time. After that, the watcher takes over func (widget *Widget) Refresh() { - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) display() { title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource()) - title = widget.ContextualTitle(title) _, _, width, _ := widget.View.GetRect() text := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width) + "\n" @@ -93,8 +90,7 @@ func (widget *Widget) display() { text = text + widget.plainText() } - widget.View.SetTitle(title) // <- Writes to TextView's title - widget.View.SetText(text) // <- Writes to TextView's text + widget.Redraw(title, text, false) } func (widget *Widget) fileName() string { diff --git a/modules/todo/display.go b/modules/todo/display.go index 3baea999..179e81a3 100644 --- a/modules/todo/display.go +++ b/modules/todo/display.go @@ -2,7 +2,6 @@ package todo import ( "fmt" - "strconv" "github.com/rivo/tview" "github.com/wtfutil/wtf/checklist" @@ -34,9 +33,7 @@ func (widget *Widget) display() { newList.SetSelectedByItem(widget.list.SelectedItem()) widget.SetList(newList) - widget.View.Clear() - widget.View.SetText(str) - widget.View.Highlight(strconv.Itoa(widget.list.Selected())).ScrollToHighlight() + widget.Redraw(widget.CommonSettings.Title, str, false) } func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string { diff --git a/modules/todo/widget.go b/modules/todo/widget.go index 13713d4d..8e0c7f8e 100644 --- a/modules/todo/widget.go +++ b/modules/todo/widget.go @@ -79,13 +79,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * func (widget *Widget) Refresh() { widget.load() - - widget.app.QueueUpdateDraw(func() { - title := widget.ContextualTitle(widget.CommonSettings.Title) - widget.View.SetTitle(title) - widget.display() - }) - + widget.display() } func (widget *Widget) SetList(list checklist.Checklist) { @@ -198,10 +192,9 @@ 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.QueueUpdateDraw(func() { + frame := widget.modalFrame(form) + widget.pages.AddPage("modal", frame, false, true) widget.app.SetFocus(frame) }) } diff --git a/modules/todoist/display.go b/modules/todoist/display.go index fbd7d3f2..ca4aeaba 100644 --- a/modules/todoist/display.go +++ b/modules/todoist/display.go @@ -17,7 +17,6 @@ func (widget *Widget) display() { } title := fmt.Sprintf("[green]%s[white]", proj.Project.Name) - widget.View.SetTitle(widget.ContextualTitle(title)) _, _, width, _ := widget.View.GetRect() str := widget.settings.common.SigilStr(len(widget.projects), widget.idx, width) + "\n" @@ -47,5 +46,5 @@ func (widget *Widget) display() { str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + "\n" } - widget.View.SetText(str) + widget.TextWidget.Redraw(title, str, false) } diff --git a/modules/todoist/widget.go b/modules/todoist/widget.go index 0cb3540f..329ef96c 100644 --- a/modules/todoist/widget.go +++ b/modules/todoist/widget.go @@ -31,7 +31,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application idx int projects []*Project settings *Settings @@ -44,7 +43,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, settings: settings, } @@ -96,9 +94,7 @@ func (w *Widget) Refresh() { return } - w.app.QueueUpdateDraw(func() { - w.display() - }) + w.display() } /* -------------------- Keyboard Movement -------------------- */ diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index e13925ba..0a385e4e 100644 --- a/modules/travisci/widget.go +++ b/modules/travisci/widget.go @@ -27,7 +27,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application builds *Builds selected int settings *Settings @@ -39,7 +38,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, settings: settings, } @@ -63,19 +61,11 @@ func (widget *Widget) Refresh() { builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro) if err != nil { - widget.View.SetWrap(true) - - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(err.Error()) - }) - } else { - widget.builds = builds + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) + return } - - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.display() - }) + widget.builds = builds + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -85,10 +75,8 @@ func (widget *Widget) display() { return } - widget.View.SetWrap(false) - - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - Builds", widget.CommonSettings.Title))) - widget.View.SetText(widget.contentFrom(widget.builds)) + title := fmt.Sprintf("%s - Builds", widget.CommonSettings.Title) + widget.Redraw(title, widget.contentFrom(widget.builds), false) } func (widget *Widget) contentFrom(builds *Builds) string { diff --git a/modules/trello/widget.go b/modules/trello/widget.go index a4afbe58..dbac1389 100644 --- a/modules/trello/widget.go +++ b/modules/trello/widget.go @@ -11,7 +11,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application settings *Settings } @@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -45,8 +43,9 @@ func (widget *Widget) Refresh() { var title string var content string + wrap := false if err != nil { - widget.View.SetWrap(true) + wrap = true title = widget.CommonSettings.Title content = err.Error() } else { @@ -59,10 +58,7 @@ func (widget *Widget) Refresh() { content = widget.contentFrom(searchResult) } - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(title) - widget.View.SetText(content) - }) + widget.Redraw(title, content, wrap) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index 9fd9e2b4..7f94caee 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -28,7 +28,6 @@ type Widget struct { wtf.MultiSourceWidget wtf.TextWidget - app *tview.Application client *Client idx int settings *Settings @@ -42,7 +41,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "screenName", "screenNames"), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, idx: 0, settings: settings, } @@ -67,9 +65,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * // Refresh is called on the interval and refreshes the data func (widget *Widget) Refresh() { - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ @@ -78,7 +74,7 @@ func (widget *Widget) display() { widget.client.screenName = widget.CurrentSource() tweets := widget.client.Tweets() - widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("Twitter - [green]@%s[white]", widget.CurrentSource()))) + title := fmt.Sprintf("Twitter - [green]@%s[white]", widget.CurrentSource()) if len(tweets) == 0 { str := fmt.Sprintf("\n\n\n%s", wtf.CenterText("[blue]No Tweets[white]", 50)) @@ -92,7 +88,7 @@ func (widget *Widget) display() { str = str + widget.format(tweet) } - widget.View.SetText(str) + widget.Redraw(title, str, false) } // If the tweet's Username is the same as the account we're watching, no diff --git a/modules/unknown/widget.go b/modules/unknown/widget.go index 6493c6c1..8232aa7a 100644 --- a/modules/unknown/widget.go +++ b/modules/unknown/widget.go @@ -10,7 +10,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application settings *Settings } @@ -18,7 +17,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -28,10 +26,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - widget.app.QueueUpdateDraw(func() { - widget.View.Clear() - - content := fmt.Sprintf("Widget %s and/or type %s does not exist", widget.Name(), widget.CommonSettings.Module.Type) - widget.View.SetText(content) - }) + content := fmt.Sprintf("Widget %s and/or type %s does not exist", widget.Name(), widget.CommonSettings.Module.Type) + widget.Redraw(widget.CommonSettings.Title, content, true) } diff --git a/modules/victorops/widget.go b/modules/victorops/widget.go index cc57118a..735c3dcd 100644 --- a/modules/victorops/widget.go +++ b/modules/victorops/widget.go @@ -20,7 +20,6 @@ const HelpText = ` type Widget struct { wtf.TextWidget - app *tview.Application teams []OnCallTeam settings *Settings } @@ -47,19 +46,11 @@ func (widget *Widget) Refresh() { widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) if err != nil { - widget.View.SetWrap(true) - - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(err.Error()) - }) + widget.Redraw(widget.CommonSettings.Title, err.Error(), true) } else { widget.teams = teams + widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(widget.teams), true) } - - widget.app.QueueUpdateDraw(func() { - widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) - widget.display() - }) } func (widget *Widget) display() { @@ -75,6 +66,10 @@ func (widget *Widget) display() { func (widget *Widget) contentFrom(teams []OnCallTeam) string { var str string + if teams == nil || len(teams) == 0 { + return "No teams specified" + } + for _, team := range teams { if len(widget.settings.team) > 0 && widget.settings.team != team.Slug { continue diff --git a/modules/weatherservices/prettyweather/widget.go b/modules/weatherservices/prettyweather/widget.go index f7b7a500..a88b209d 100644 --- a/modules/weatherservices/prettyweather/widget.go +++ b/modules/weatherservices/prettyweather/widget.go @@ -12,7 +12,6 @@ import ( type Widget struct { wtf.TextWidget - app *tview.Application result string settings *Settings } @@ -21,7 +20,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - app: app, settings: settings, } @@ -31,9 +29,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { widget.prettyWeather() - widget.app.QueueUpdateDraw(func() { - widget.View.SetText(widget.result) - }) + widget.Redraw(widget.CommonSettings.Title, widget.result, false) } //this method reads the config and calls wttr.in for pretty weather diff --git a/modules/weatherservices/weather/display.go b/modules/weatherservices/weather/display.go index cc357cc2..e916b7b0 100644 --- a/modules/weatherservices/weather/display.go +++ b/modules/weatherservices/weather/display.go @@ -9,31 +9,34 @@ import ( ) func (widget *Widget) display() { + err := "" if widget.apiKeyValid() == false { - widget.View.SetText(" Environment variable WTF_OWM_API_KEY is not set") - return + err += " Environment variable WTF_OWM_API_KEY is not set\n" } cityData := widget.currentData() if cityData == nil { - widget.View.SetText(" Weather data is unavailable: no city data") - return + err += " Weather data is unavailable: no city data\n" } if len(cityData.Weather) == 0 { - widget.View.SetText(" Weather data is unavailable: no weather data") - return + err += " Weather data is unavailable: no weather data" } - widget.View.SetTitle(widget.title(cityData)) + title := widget.CommonSettings.Title + var content string + if err != "" { + content = err + } else { + title = widget.title(cityData) + _, _, width, _ := widget.View.GetRect() + content = widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" + content = content + widget.description(cityData) + "\n\n" + content = content + widget.temperatures(cityData) + "\n" + content = content + widget.sunInfo(cityData) + } - _, _, width, _ := widget.View.GetRect() - content := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" - content = content + widget.description(cityData) + "\n\n" - content = content + widget.temperatures(cityData) + "\n" - content = content + widget.sunInfo(cityData) - - widget.View.SetText(content) + widget.Redraw(title, content, false) } func (widget *Widget) description(cityData *owm.CurrentWeatherData) string { diff --git a/modules/weatherservices/weather/widget.go b/modules/weatherservices/weather/widget.go index 586123b8..458d08af 100644 --- a/modules/weatherservices/weather/widget.go +++ b/modules/weatherservices/weather/widget.go @@ -27,7 +27,6 @@ type Widget struct { Data []*owm.CurrentWeatherData Idx int - app *tview.Application settings *Settings } @@ -40,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * Idx: 0, - app: app, settings: settings, } @@ -77,9 +75,7 @@ func (widget *Widget) Refresh() { widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs)) } - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } // Next displays data for the next city data in the list. If the current city is the last diff --git a/modules/zendesk/widget.go b/modules/zendesk/widget.go index 79224237..8882c54f 100644 --- a/modules/zendesk/widget.go +++ b/modules/zendesk/widget.go @@ -13,7 +13,6 @@ type Widget struct { wtf.KeyboardWidget wtf.TextWidget - app *tview.Application result *TicketArray selected int settings *Settings @@ -25,7 +24,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { KeyboardWidget: wtf.NewKeyboardWidget(), TextWidget: wtf.NewTextWidget(app, settings.common, true), - app: app, settings: settings, } @@ -46,16 +44,14 @@ func (widget *Widget) Refresh() { widget.result = ticketArray } - widget.app.QueueUpdateDraw(func() { - widget.display() - }) + widget.display() } /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) display() { - widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.CommonSettings.Title, widget.result.Count)) - widget.View.SetText(widget.textContent(widget.result.Tickets)) + title := fmt.Sprintf("%s (%d)", widget.CommonSettings.Title, widget.result.Count) + widget.Redraw(title, widget.textContent(widget.result.Tickets), false) } func (widget *Widget) textContent(items []Ticket) string { diff --git a/wtf/text_widget.go b/wtf/text_widget.go index de403606..373f1f51 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -13,6 +13,7 @@ type TextWidget struct { focusChar string name string refreshInterval int + app *tview.Application View *tview.TextView @@ -24,6 +25,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable widget := TextWidget{ CommonSettings: commonSettings, + app: app, enabled: commonSettings.Enabled, focusable: focusable, focusChar: commonSettings.FocusChar(), @@ -107,6 +109,16 @@ func (widget *TextWidget) TextView() *tview.TextView { return widget.View } +func (widget *TextWidget) Redraw(title, text string, wrap bool) { + + widget.app.QueueUpdateDraw(func() { + widget.View.Clear() + widget.View.SetWrap(wrap) + widget.View.SetTitle(widget.ContextualTitle(title)) + widget.View.SetText(text) + }) +} + /* -------------------- Unexported Functions -------------------- */ func (widget *TextWidget) addView() *tview.TextView {