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

Add a global Redraw method for TextWidget

Partially addresses #429, by centralizing widget drawing
This commit is contained in:
Sean Smith 2019-05-07 20:49:46 -04:00 committed by Chris Cummer
parent aedcf9dd51
commit 018d2af3ae
48 changed files with 194 additions and 412 deletions

View File

@ -18,7 +18,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -28,15 +27,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
widget.initializeKeyboardControls() widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture) widget.View.SetInputCapture(widget.InputCapture)
widget.unselect()
widget.View.SetScrollable(true) widget.View.SetScrollable(true)
widget.View.SetRegions(true) widget.View.SetRegions(true)
@ -50,22 +46,11 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
// The last call should always be to the display function // The last call should always be to the display function
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() { func (widget *Widget) display() {
widget.View.SetWrap(false) widget.Redraw(widget.CommonSettings.Title, "Some text", false)
widget.View.Clear()
widget.View.SetText("Some Text")
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
}
func (widget *Widget) unselect() {
widget.selected = -1
widget.display()
} }

View File

@ -42,10 +42,7 @@ func (widget *Widget) Refresh() {
wtf.Now().Format(wtf.DateFormat), wtf.Now().Format(wtf.DateFormat),
) )
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(todayItems), false)
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.View.SetText(widget.contentFrom(todayItems))
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -11,7 +11,6 @@ type Widget struct {
wtf.TextWidget wtf.TextWidget
*Client *Client
app *tview.Application
settings *Settings settings *Settings
} }
@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
Client: NewClient(settings.apiKey), Client: NewClient(settings.apiKey),
app: app,
settings: settings, settings: settings,
} }
@ -36,19 +34,17 @@ func (widget *Widget) Refresh() {
builds, err := widget.Client.BuildsFor() builds, err := widget.Client.BuildsFor()
title := fmt.Sprintf("%s - Builds", widget.CommonSettings.Title)
var content string var content string
wrap := false
if err != nil { if err != nil {
widget.View.SetWrap(true) wrap = true
content = err.Error() content = err.Error()
} else { } else {
widget.View.SetWrap(false)
content = widget.contentFrom(builds) content = widget.contentFrom(builds)
} }
widget.app.QueueUpdateDraw(func() { widget.Redraw(title, content, wrap)
widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.CommonSettings.Title))
widget.View.SetText(content)
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -12,7 +12,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
args []string args []string
cmd string cmd string
settings *Settings settings *Settings
@ -23,7 +22,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
args: settings.args, args: settings.args,
cmd: settings.cmd, cmd: settings.cmd,
settings: settings, settings: settings,
@ -41,10 +39,7 @@ func (widget *Widget) Refresh() {
ansiTitle := tview.TranslateANSI(widget.String()) ansiTitle := tview.TranslateANSI(widget.String())
ansiResult := tview.TranslateANSI(result) ansiResult := tview.TranslateANSI(result)
widget.app.QueueUpdateDraw(func() { widget.Redraw(ansiTitle, ansiResult, false)
widget.View.SetTitle(ansiTitle)
widget.View.SetText(ansiResult)
})
} }
// String returns the string representation of the widget // String returns the string representation of the widget

View File

@ -39,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }

View File

@ -29,13 +29,12 @@ func (widget *Widget) display() {
return return
} }
widget.View.SetTitle(widget.ContextualTitle(widget.settings.common.Title)) widget.TextWidget.Redraw(widget.settings.common.Title, widget.contentFrom(widget.calEvents), false)
widget.View.SetText(widget.contentFrom(widget.calEvents))
} }
func (widget *Widget) contentFrom(calEvents []*CalEvent) string { func (widget *Widget) contentFrom(calEvents []*CalEvent) string {
if (calEvents == nil) || (len(calEvents) == 0) { if (calEvents == nil) || (len(calEvents) == 0) {
return "" return "No calendar events"
} }
var str string var str string

View File

@ -1,8 +1,6 @@
package gcal package gcal
import ( import (
"time"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
) )
@ -12,7 +10,6 @@ type Widget struct {
app *tview.Application app *tview.Application
calEvents []*CalEvent calEvents []*CalEvent
ch chan struct{}
settings *Settings settings *Settings
} }
@ -21,27 +18,21 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app, app: app,
ch: make(chan struct{}),
settings: settings, settings: settings,
} }
go updateLoop(&widget)
return &widget return &widget
} }
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Disable() { func (widget *Widget) Disable() {
close(widget.ch)
widget.TextWidget.Disable() widget.TextWidget.Disable()
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if isAuthenticated() { if isAuthenticated() {
widget.app.QueueUpdateDraw(func() {
widget.fetchAndDisplayEvents() widget.fetchAndDisplayEvents()
})
return return
} }
@ -59,27 +50,5 @@ func (widget *Widget) fetchAndDisplayEvents() {
widget.calEvents = calEvents widget.calEvents = calEvents
} }
widget.app.QueueUpdateDraw(func() {
widget.display() 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
}
}
} }

View File

@ -8,11 +8,11 @@ func (widget *Widget) display() {
project := widget.currentGerritProject() project := widget.currentGerritProject()
if project == nil { 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 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() _, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n" 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 + " [red]My Outgoing Reviews[white]\n"
str = str + widget.displayMyOutgoingReviews(project, widget.settings.username) 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 { func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username string) string {

View File

@ -39,7 +39,6 @@ type Widget struct {
GerritProjects []*GerritProject GerritProjects []*GerritProject
Idx int Idx int
app *tview.Application
selected int selected int
settings *Settings settings *Settings
} }
@ -56,7 +55,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
Idx: 0, Idx: 0,
app: app,
settings: settings, settings: settings,
} }
@ -99,9 +97,7 @@ func (widget *Widget) Refresh() {
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
widget.View.SetText(err.Error())
})
return return
} }
widget.gerrit = gerrit widget.gerrit = gerrit
@ -111,10 +107,7 @@ func (widget *Widget) Refresh() {
project.Refresh(widget.settings.username) project.Refresh(widget.settings.username)
} }
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -9,12 +9,11 @@ import (
func (widget *Widget) display() { func (widget *Widget) display() {
repoData := widget.currentData() repoData := widget.currentData()
if repoData == nil { if repoData == nil {
widget.View.SetText(" Git repo data is unavailable ") widget.Redraw(widget.CommonSettings.Title, " Git repo data is unavailable ", false)
return return
} }
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, repoData.Repository) title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, repoData.Repository)
widget.View.SetTitle(widget.ContextualTitle(title))
_, _, width, _ := widget.View.GetRect() _, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.GitRepos), widget.Idx, width) + "\n" 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 + "\n"
str = str + widget.formatCommits(repoData.Commits) str = str + widget.formatCommits(repoData.Commits)
widget.View.SetText(str) widget.Redraw(title, str, false)
} }
func (widget *Widget) formatChanges(data []string) string { func (widget *Widget) formatChanges(data []string) string {

View File

@ -97,9 +97,7 @@ func (widget *Widget) Refresh() {
return widget.GitRepos[i].Path < widget.GitRepos[j].Path return widget.GitRepos[i].Path < widget.GitRepos[j].Path
}) })
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -125,9 +123,11 @@ func (widget *Widget) addCancelButton(form *tview.Form) {
} }
func (widget *Widget) modalFocus(form *tview.Form) { func (widget *Widget) modalFocus(form *tview.Form) {
widget.app.QueueUpdateDraw(func() {
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)
})
} }
func (widget *Widget) modalForm(lbl, text string) *tview.Form { func (widget *Widget) modalForm(lbl, text string) *tview.Form {

View File

@ -8,13 +8,12 @@ import (
func (widget *Widget) display() { func (widget *Widget) display() {
repo := widget.currentGithubRepo() repo := widget.currentGithubRepo()
title := fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.title(repo))
if repo == nil { if repo == nil {
widget.View.SetText(" GitHub repo data is unavailable ") widget.TextWidget.Redraw(title, " GitHub repo data is unavailable ", false)
return return
} }
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.title(repo))))
_, _, width, _ := widget.View.GetRect() _, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.GithubRepos), widget.Idx, width) + "\n" str := widget.settings.common.SigilStr(len(widget.GithubRepos), widget.Idx, width) + "\n"
str = str + " [red]Stats[white]\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 + " [red]My Pull Requests[white]\n"
str = str + widget.displayMyPullRequests(repo, widget.settings.username) 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 { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {

View File

@ -8,11 +8,11 @@ func (widget *Widget) display() {
project := widget.currentGitlabProject() project := widget.currentGitlabProject()
if project == nil { if project == nil {
widget.View.SetText(" Gitlab project data is unavailable ") widget.Redraw(widget.CommonSettings.Title, " Gitlab project data is unavailable ", true)
return 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() _, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.GitlabProjects), widget.Idx, width) + "\n" 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 + "\n"
str = str + " [red]My Merge Requests[white]\n" str = str + " [red]My Merge Requests[white]\n"
str = str + widget.displayMyMergeRequests(project, widget.settings.username) str = str + widget.displayMyMergeRequests(project, widget.settings.username)
widget.Redraw(title, str, false)
widget.View.SetText(str)
} }
func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username string) string { func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username string) string {

View File

@ -26,7 +26,6 @@ type Widget struct {
GitlabProjects []*GitlabProject GitlabProjects []*GitlabProject
Idx int Idx int
app *tview.Application
gitlab *glb.Client gitlab *glb.Client
settings *Settings settings *Settings
} }
@ -46,7 +45,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
Idx: 0, Idx: 0,
app: app,
gitlab: gitlab, gitlab: gitlab,
settings: settings, settings: settings,
} }
@ -68,9 +66,7 @@ func (widget *Widget) Refresh() {
project.Refresh() project.Refresh()
} }
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
func (widget *Widget) Next() { func (widget *Widget) Next() {

View File

@ -27,6 +27,7 @@ type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application app *tview.Application
messages []Message messages []Message
selected int selected int
settings *Settings settings *Settings
@ -80,19 +81,12 @@ func (widget *Widget) Refresh() {
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.View.SetWrap(true)
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
widget.View.SetTitle(widget.CommonSettings.Title) return
widget.View.SetText(err.Error())
})
} else {
widget.messages = messages
} }
widget.messages = messages
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.display() widget.display()
widget.View.ScrollToEnd()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -102,11 +96,13 @@ func (widget *Widget) display() {
return return
} }
widget.View.SetWrap(true) title := fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.roomURI)
widget.View.Clear()
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.roomURI))) widget.Redraw(title, widget.contentFrom(widget.messages), true)
widget.View.SetText(widget.contentFrom(widget.messages)) widget.app.QueueUpdateDraw(func() {
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
widget.View.ScrollToEnd()
})
} }
func (widget *Widget) contentFrom(messages []Message) string { func (widget *Widget) contentFrom(messages []Message) string {

View File

@ -11,7 +11,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -31,9 +29,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
cells, _ := widget.Fetch() cells, _ := widget.Fetch()
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(cells), false)
widget.View.SetText(widget.contentFrom(cells))
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -31,6 +31,7 @@ type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application app *tview.Application
stories []Story stories []Story
selected int selected int
settings *Settings settings *Settings
@ -89,9 +90,7 @@ func (widget *Widget) Refresh() {
widget.stories = stories widget.stories = stories
} }
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -101,12 +100,11 @@ func (widget *Widget) display() {
return return
} }
widget.View.SetWrap(false) title := fmt.Sprintf("%s - %sstories", widget.CommonSettings.Title, widget.settings.storyType)
widget.Redraw(title, widget.contentFrom(widget.stories), false)
widget.View.Clear() widget.app.QueueUpdateDraw(func() {
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() widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
})
} }
func (widget *Widget) contentFrom(stories []Story) string { func (widget *Widget) contentFrom(stories []Story) string {

View File

@ -14,7 +14,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
result string result string
settings *Settings settings *Settings
} }
@ -34,7 +33,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -46,10 +44,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.ipinfo() widget.ipinfo()
widget.app.QueueUpdateDraw(func() { widget.TextWidget.Redraw(widget.CommonSettings.Title, widget.result, false)
widget.View.Clear()
widget.View.SetText(widget.result)
})
} }
//this method reads the config and calls ipinfo for ip information //this method reads the config and calls ipinfo for ip information

View File

@ -30,6 +30,7 @@ type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application app *tview.Application
selected int selected int
settings *Settings settings *Settings
view *View view *View
@ -73,17 +74,11 @@ func (widget *Widget) Refresh() {
widget.view = view widget.view = view
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
return
widget.app.QueueUpdateDraw(func() {
widget.View.SetText(err.Error())
})
} }
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -93,12 +88,12 @@ func (widget *Widget) display() {
return return
} }
widget.View.SetWrap(false) title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings.Title, widget.view.Name)
widget.View.Clear() widget.Redraw(title, widget.contentFrom(widget.view), false)
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s: [red]%s", widget.CommonSettings.Title, widget.view.Name))) widget.app.QueueUpdateDraw(func() {
widget.View.SetText(widget.contentFrom(widget.view))
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
})
} }
func (widget *Widget) contentFrom(view *View) string { func (widget *Widget) contentFrom(view *View) string {

View File

@ -2,7 +2,6 @@ package jira
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"github.com/rivo/tview" "github.com/rivo/tview"
@ -28,6 +27,7 @@ type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application app *tview.Application
result *SearchResult result *SearchResult
selected int selected int
settings *Settings settings *Settings
@ -67,19 +67,11 @@ func (widget *Widget) Refresh() {
if err != nil { if err != nil {
widget.result = nil widget.result = nil
widget.View.SetWrap(true) widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
return
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.CommonSettings.Title)
widget.View.SetText(err.Error())
})
} else {
widget.result = searchResult
} }
widget.result = searchResult
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -88,14 +80,13 @@ func (widget *Widget) display() {
if widget.result == nil { if widget.result == nil {
return return
} }
widget.View.SetWrap(false)
str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings.Title, widget.settings.projects) str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings.Title, widget.settings.projects)
widget.View.Clear() widget.Redraw(str, widget.contentFrom(widget.result), false)
widget.View.SetTitle(widget.ContextualTitle(str)) widget.app.QueueUpdateDraw(func() {
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.result)))
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight() widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
})
} }
func (widget *Widget) next() { func (widget *Widget) next() {

View File

@ -9,12 +9,11 @@ import (
func (widget *Widget) display() { func (widget *Widget) display() {
repoData := widget.currentData() repoData := widget.currentData()
if repoData == nil { if repoData == nil {
widget.View.SetText(" Mercurial repo data is unavailable ") widget.Redraw(widget.CommonSettings.Title, " Mercurial repo data is unavailable ", false)
return return
} }
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, repoData.Repository) title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, repoData.Repository)
widget.View.SetTitle(widget.ContextualTitle(title))
_, _, width, _ := widget.View.GetRect() _, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" 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 + "\n"
str = str + widget.formatCommits(repoData.Commits) str = str + widget.formatCommits(repoData.Commits)
widget.View.SetText(str) widget.Redraw(title, str, false)
} }
func (widget *Widget) formatChanges(data []string) string { func (widget *Widget) formatChanges(data []string) string {

View File

@ -71,9 +71,7 @@ func (widget *Widget) Checkout() {
widget.pages.RemovePage("modal") widget.pages.RemovePage("modal")
widget.app.SetFocus(widget.View) widget.app.SetFocus(widget.View)
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
widget.Refresh() widget.Refresh()
} }
@ -86,7 +84,6 @@ func (widget *Widget) Pull() {
repoToPull := widget.Data[widget.Idx] repoToPull := widget.Data[widget.Idx]
repoToPull.pull() repoToPull.pull()
widget.Refresh() widget.Refresh()
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
@ -94,9 +91,7 @@ func (widget *Widget) Refresh() {
widget.Data = widget.mercurialRepos(repoPaths) widget.Data = widget.mercurialRepos(repoPaths)
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -122,9 +117,11 @@ func (widget *Widget) addCancelButton(form *tview.Form) {
} }
func (widget *Widget) modalFocus(form *tview.Form) { func (widget *Widget) modalFocus(form *tview.Form) {
widget.app.QueueUpdateDraw(func() {
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)
})
} }
func (widget *Widget) modalForm(lbl, text string) *tview.Form { func (widget *Widget) modalForm(lbl, text string) *tview.Form {

View File

@ -25,7 +25,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
language string language string
result string result string
settings *Settings settings *Settings
@ -40,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -55,39 +53,32 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, widget.nbascore(), false)
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.nbascore()
})
} }
func (widget *Widget) nbascore() { func (widget *Widget) nbascore() string {
cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days
curString := cur.Format("20060102") // Need 20060102 format to feed to api curString := cur.Format("20060102") // Need 20060102 format to feed to api
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest("GET", "http://data.nba.net/10s/prod/v1/"+curString+"/scoreboard.json", nil) req, err := http.NewRequest("GET", "http://data.nba.net/10s/prod/v1/"+curString+"/scoreboard.json", nil)
if err != nil { if err != nil {
widget.result = err.Error() return err.Error()
return
} }
req.Header.Set("Accept-Language", widget.language) req.Header.Set("Accept-Language", widget.language)
req.Header.Set("User-Agent", "curl") req.Header.Set("User-Agent", "curl")
response, err := client.Do(req) response, err := client.Do(req)
if err != nil { if err != nil {
widget.result = err.Error() return err.Error()
return
} }
defer response.Body.Close() defer response.Body.Close()
if response.StatusCode != 200 { if response.StatusCode != 200 {
widget.result = err.Error() return err.Error()
return
} // Get data from data.nba.net and check if successful } // Get data from data.nba.net and check if successful
contents, err := ioutil.ReadAll(response.Body) contents, err := ioutil.ReadAll(response.Body)
if err != nil { if err != nil {
widget.result = err.Error() return err.Error()
return
} }
result := map[string]interface{}{} result := map[string]interface{}{}
json.Unmarshal(contents, &result) 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 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
} }

View File

@ -11,7 +11,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
client *Client client *Client
settings *Settings settings *Settings
} }
@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -41,19 +39,16 @@ func (widget *Widget) Refresh() {
} }
var content string var content string
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, appName)
wrap := false
if depErr != nil { if depErr != nil {
widget.View.SetWrap(true) wrap = true
content = depErr.Error() content = depErr.Error()
} else { } else {
widget.View.SetWrap(false)
content = widget.contentFrom(deploys) content = widget.contentFrom(deploys)
} }
widget.app.QueueUpdateDraw(func() { widget.Redraw(title, content, wrap)
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, appName)))
widget.View.Clear()
widget.View.SetText(content)
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -11,7 +11,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -35,18 +33,15 @@ func (widget *Widget) Refresh() {
) )
var content string var content string
wrap := false
if err != nil { if err != nil {
widget.View.SetWrap(true) wrap = true
content = err.Error() content = err.Error()
} else { } else {
widget.View.SetWrap(false)
content = widget.contentFrom(data) content = widget.contentFrom(data)
} }
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, content, wrap)
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.View.SetText(content)
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -12,7 +12,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -44,14 +42,10 @@ func (widget *Widget) Refresh() {
incidents, err2 = GetIncidents(widget.settings.apiKey) incidents, err2 = GetIncidents(widget.settings.apiKey)
} }
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.View.Clear()
})
var content string var content string
wrap := false
if err1 != nil || err2 != nil { if err1 != nil || err2 != nil {
widget.View.SetWrap(true) wrap = true
if err1 != nil { if err1 != nil {
content = content + err1.Error() content = content + err1.Error()
} }
@ -63,9 +57,7 @@ func (widget *Widget) Refresh() {
content = widget.contentFrom(onCalls, incidents) content = widget.contentFrom(onCalls, incidents)
} }
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, content, wrap)
widget.View.SetText(content)
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -12,7 +12,6 @@ type Widget struct {
Battery *Battery Battery *Battery
app *tview.Application
settings *Settings settings *Settings
} }
@ -22,7 +21,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
Battery: NewBattery(), Battery: NewBattery(),
app: app,
settings: settings, settings: settings,
} }
@ -39,7 +37,5 @@ func (widget *Widget) Refresh() {
content = content + "\n" content = content + "\n"
content = content + widget.Battery.String() content = content + widget.Battery.String()
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, content, true)
widget.View.SetText(content)
})
} }

View File

@ -28,7 +28,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
items *Result items *Result
selected int selected int
settings *Settings settings *Settings
@ -41,7 +40,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -69,19 +67,12 @@ func (widget *Widget) Refresh() {
) )
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
return
widget.app.QueueUpdateDraw(func() {
widget.View.SetText(err.Error())
})
} else {
widget.items = &items.Results
} }
widget.items = &items.Results
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -91,12 +82,14 @@ func (widget *Widget) display() {
return return
} }
widget.View.SetWrap(false) title := fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.projectName)
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.CommonSettings.Title, widget.settings.projectName))) widget.Redraw(title, widget.contentFrom(widget.items), false)
widget.View.SetText(widget.contentFrom(widget.items))
} }
func (widget *Widget) contentFrom(result *Result) string { func (widget *Widget) contentFrom(result *Result) string {
if result == nil {
return "No results"
}
var str string var str string
if len(result.Items) > widget.settings.count { if len(result.Items) > widget.settings.count {
result.Items = result.Items[:widget.settings.count] result.Items = result.Items[:widget.settings.count]

View File

@ -11,7 +11,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -37,9 +35,7 @@ func (widget *Widget) Refresh() {
data := NewSecurityData() data := NewSecurityData()
data.Fetch() data.Fetch()
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, widget.contentFrom(data), false)
widget.View.SetText(widget.contentFrom(data))
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -21,7 +21,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
spotigopher.Info spotigopher.Info
spotigopher.SpotifyClient spotigopher.SpotifyClient
@ -38,7 +37,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
Info: spotigopher.Info{}, Info: spotigopher.Info{},
SpotifyClient: spotifyClient, SpotifyClient: spotifyClient,
app: app,
settings: settings, settings: settings,
} }
@ -63,19 +61,18 @@ func (w *Widget) refreshSpotifyInfos() error {
} }
func (w *Widget) Refresh() { func (w *Widget) Refresh() {
w.app.QueueUpdateDraw(func() {
w.render() w.render()
})
} }
func (w *Widget) render() { func (w *Widget) render() {
err := w.refreshSpotifyInfos() err := w.refreshSpotifyInfos()
w.View.Clear() var content string
if err != nil { if err != nil {
w.TextWidget.View.SetText(err.Error()) content = err.Error()
} else { } else {
w.TextWidget.View.SetText(w.createOutput()) content = w.createOutput()
} }
w.Redraw(w.CommonSettings.Title, content, true)
} }
func (w *Widget) createOutput() string { func (w *Widget) createOutput() string {

View File

@ -48,7 +48,6 @@ type Widget struct {
Info Info
app *tview.Application
client *spotify.Client client *spotify.Client
clientChan chan *spotify.Client clientChan chan *spotify.Client
playerState *spotify.PlayerState playerState *spotify.PlayerState
@ -99,7 +98,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
Info: Info{}, Info: Info{},
app: app,
client: client, client: client,
clientChan: tempClientChan, clientChan: tempClientChan,
playerState: playerState, playerState: playerState,
@ -181,18 +179,11 @@ func (w *Widget) refreshSpotifyInfos() error {
// Refresh refreshes the current view of the widget // Refresh refreshes the current view of the widget
func (w *Widget) Refresh() { func (w *Widget) Refresh() {
w.app.QueueUpdateDraw(func() {
w.render()
})
}
func (w *Widget) render() {
err := w.refreshSpotifyInfos() err := w.refreshSpotifyInfos()
w.View.Clear()
if err != nil { if err != nil {
w.TextWidget.View.SetText(err.Error()) w.Redraw(w.CommonSettings.Title, err.Error(), true)
} else { } else {
w.TextWidget.View.SetText(w.createOutput()) w.Redraw(w.CommonSettings.Title, w.createOutput(), false)
} }
} }

View File

@ -10,7 +10,6 @@ type Widget struct {
CurrentIcon int CurrentIcon int
app *tview.Application
settings *Settings settings *Settings
} }
@ -20,7 +19,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
CurrentIcon: 0, CurrentIcon: 0,
app: app,
settings: settings, settings: settings,
} }
@ -30,9 +28,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, widget.animation(), false)
widget.View.SetText(widget.animation())
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -14,7 +14,6 @@ type Widget struct {
Date string Date string
Version string Version string
app *tview.Application
settings *Settings settings *Settings
systemInfo *SystemInfo systemInfo *SystemInfo
} }
@ -25,7 +24,6 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings)
Date: date, Date: date,
app: app,
settings: settings, settings: settings,
Version: version, Version: version,
} }
@ -36,9 +34,7 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings)
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.app.QueueUpdateDraw(func() { content := fmt.Sprintf(
widget.View.SetText(
fmt.Sprintf(
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
"Built", "Built",
widget.prettyDate(), widget.prettyDate(),
@ -48,9 +44,8 @@ func (widget *Widget) Refresh() {
widget.systemInfo.ProductVersion, widget.systemInfo.ProductVersion,
"Build", "Build",
widget.systemInfo.BuildVersion, widget.systemInfo.BuildVersion,
),
) )
}) widget.Redraw(widget.CommonSettings.Title, content, false)
} }
func (widget *Widget) prettyDate() string { func (widget *Widget) prettyDate() string {

View File

@ -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 // 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 // text files that first time. After that, the watcher takes over
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() { func (widget *Widget) display() {
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource()) title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
title = widget.ContextualTitle(title)
_, _, width, _ := widget.View.GetRect() _, _, width, _ := widget.View.GetRect()
text := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width) + "\n" text := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width) + "\n"
@ -93,8 +90,7 @@ func (widget *Widget) display() {
text = text + widget.plainText() text = text + widget.plainText()
} }
widget.View.SetTitle(title) // <- Writes to TextView's title widget.Redraw(title, text, false)
widget.View.SetText(text) // <- Writes to TextView's text
} }
func (widget *Widget) fileName() string { func (widget *Widget) fileName() string {

View File

@ -2,7 +2,6 @@ package todo
import ( import (
"fmt" "fmt"
"strconv"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/checklist" "github.com/wtfutil/wtf/checklist"
@ -34,9 +33,7 @@ func (widget *Widget) display() {
newList.SetSelectedByItem(widget.list.SelectedItem()) newList.SetSelectedByItem(widget.list.SelectedItem())
widget.SetList(newList) widget.SetList(newList)
widget.View.Clear() widget.Redraw(widget.CommonSettings.Title, str, false)
widget.View.SetText(str)
widget.View.Highlight(strconv.Itoa(widget.list.Selected())).ScrollToHighlight()
} }
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string { func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {

View File

@ -79,13 +79,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.load() 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) { 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) { func (widget *Widget) modalFocus(form *tview.Form) {
widget.app.QueueUpdateDraw(func() {
frame := widget.modalFrame(form) frame := widget.modalFrame(form)
widget.pages.AddPage("modal", frame, false, true) widget.pages.AddPage("modal", frame, false, true)
widget.app.QueueUpdateDraw(func() {
widget.app.SetFocus(frame) widget.app.SetFocus(frame)
}) })
} }

View File

@ -17,7 +17,6 @@ func (widget *Widget) display() {
} }
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name) title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
widget.View.SetTitle(widget.ContextualTitle(title))
_, _, width, _ := widget.View.GetRect() _, _, width, _ := widget.View.GetRect()
str := widget.settings.common.SigilStr(len(widget.projects), widget.idx, width) + "\n" 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" str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + "\n"
} }
widget.View.SetText(str) widget.TextWidget.Redraw(title, str, false)
} }

View File

@ -31,7 +31,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
idx int idx int
projects []*Project projects []*Project
settings *Settings settings *Settings
@ -44,7 +43,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -96,9 +94,7 @@ func (w *Widget) Refresh() {
return return
} }
w.app.QueueUpdateDraw(func() {
w.display() w.display()
})
} }
/* -------------------- Keyboard Movement -------------------- */ /* -------------------- Keyboard Movement -------------------- */

View File

@ -27,7 +27,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
builds *Builds builds *Builds
selected int selected int
settings *Settings settings *Settings
@ -39,7 +38,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -63,19 +61,11 @@ func (widget *Widget) Refresh() {
builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro) builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro)
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
return
widget.app.QueueUpdateDraw(func() {
widget.View.SetText(err.Error())
})
} else {
widget.builds = builds
} }
widget.builds = builds
widget.app.QueueUpdateDraw(func() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -85,10 +75,8 @@ func (widget *Widget) display() {
return return
} }
widget.View.SetWrap(false) title := fmt.Sprintf("%s - Builds", widget.CommonSettings.Title)
widget.Redraw(title, widget.contentFrom(widget.builds), false)
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - Builds", widget.CommonSettings.Title)))
widget.View.SetText(widget.contentFrom(widget.builds))
} }
func (widget *Widget) contentFrom(builds *Builds) string { func (widget *Widget) contentFrom(builds *Builds) string {

View File

@ -11,7 +11,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -19,7 +18,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -45,8 +43,9 @@ func (widget *Widget) Refresh() {
var title string var title string
var content string var content string
wrap := false
if err != nil { if err != nil {
widget.View.SetWrap(true) wrap = true
title = widget.CommonSettings.Title title = widget.CommonSettings.Title
content = err.Error() content = err.Error()
} else { } else {
@ -59,10 +58,7 @@ func (widget *Widget) Refresh() {
content = widget.contentFrom(searchResult) content = widget.contentFrom(searchResult)
} }
widget.app.QueueUpdateDraw(func() { widget.Redraw(title, content, wrap)
widget.View.SetTitle(title)
widget.View.SetText(content)
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -28,7 +28,6 @@ type Widget struct {
wtf.MultiSourceWidget wtf.MultiSourceWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
client *Client client *Client
idx int idx int
settings *Settings settings *Settings
@ -42,7 +41,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "screenName", "screenNames"), MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "screenName", "screenNames"),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
idx: 0, idx: 0,
settings: settings, 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 // Refresh is called on the interval and refreshes the data
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
@ -78,7 +74,7 @@ func (widget *Widget) display() {
widget.client.screenName = widget.CurrentSource() widget.client.screenName = widget.CurrentSource()
tweets := widget.client.Tweets() 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 { if len(tweets) == 0 {
str := fmt.Sprintf("\n\n\n%s", wtf.CenterText("[blue]No Tweets[white]", 50)) 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) 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 // If the tweet's Username is the same as the account we're watching, no

View File

@ -10,7 +10,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -18,7 +17,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -28,10 +26,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { 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) content := fmt.Sprintf("Widget %s and/or type %s does not exist", widget.Name(), widget.CommonSettings.Module.Type)
widget.View.SetText(content) widget.Redraw(widget.CommonSettings.Title, content, true)
})
} }

View File

@ -20,7 +20,6 @@ const HelpText = `
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
teams []OnCallTeam teams []OnCallTeam
settings *Settings settings *Settings
} }
@ -47,19 +46,11 @@ func (widget *Widget) Refresh() {
widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) widget.View.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
if err != nil { if err != nil {
widget.View.SetWrap(true) widget.Redraw(widget.CommonSettings.Title, err.Error(), true)
widget.app.QueueUpdateDraw(func() {
widget.View.SetText(err.Error())
})
} else { } else {
widget.teams = teams 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() { func (widget *Widget) display() {
@ -75,6 +66,10 @@ func (widget *Widget) display() {
func (widget *Widget) contentFrom(teams []OnCallTeam) string { func (widget *Widget) contentFrom(teams []OnCallTeam) string {
var str string var str string
if teams == nil || len(teams) == 0 {
return "No teams specified"
}
for _, team := range teams { for _, team := range teams {
if len(widget.settings.team) > 0 && widget.settings.team != team.Slug { if len(widget.settings.team) > 0 && widget.settings.team != team.Slug {
continue continue

View File

@ -12,7 +12,6 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
result string result string
settings *Settings settings *Settings
} }
@ -21,7 +20,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -31,9 +29,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.prettyWeather() widget.prettyWeather()
widget.app.QueueUpdateDraw(func() { widget.Redraw(widget.CommonSettings.Title, widget.result, false)
widget.View.SetText(widget.result)
})
} }
//this method reads the config and calls wttr.in for pretty weather //this method reads the config and calls wttr.in for pretty weather

View File

@ -9,31 +9,34 @@ import (
) )
func (widget *Widget) display() { func (widget *Widget) display() {
err := ""
if widget.apiKeyValid() == false { if widget.apiKeyValid() == false {
widget.View.SetText(" Environment variable WTF_OWM_API_KEY is not set") err += " Environment variable WTF_OWM_API_KEY is not set\n"
return
} }
cityData := widget.currentData() cityData := widget.currentData()
if cityData == nil { if cityData == nil {
widget.View.SetText(" Weather data is unavailable: no city data") err += " Weather data is unavailable: no city data\n"
return
} }
if len(cityData.Weather) == 0 { if len(cityData.Weather) == 0 {
widget.View.SetText(" Weather data is unavailable: no weather data") err += " Weather data is unavailable: no weather data"
return
} }
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() _, _, width, _ := widget.View.GetRect()
content := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" content = widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n"
content = content + widget.description(cityData) + "\n\n" content = content + widget.description(cityData) + "\n\n"
content = content + widget.temperatures(cityData) + "\n" content = content + widget.temperatures(cityData) + "\n"
content = content + widget.sunInfo(cityData) content = content + widget.sunInfo(cityData)
}
widget.View.SetText(content) widget.Redraw(title, content, false)
} }
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string { func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {

View File

@ -27,7 +27,6 @@ type Widget struct {
Data []*owm.CurrentWeatherData Data []*owm.CurrentWeatherData
Idx int Idx int
app *tview.Application
settings *Settings settings *Settings
} }
@ -40,7 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
Idx: 0, Idx: 0,
app: app,
settings: settings, settings: settings,
} }
@ -77,9 +75,7 @@ func (widget *Widget) Refresh() {
widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs)) 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 // Next displays data for the next city data in the list. If the current city is the last

View File

@ -13,7 +13,6 @@ type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
result *TicketArray result *TicketArray
selected int selected int
settings *Settings settings *Settings
@ -25,7 +24,6 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
KeyboardWidget: wtf.NewKeyboardWidget(), KeyboardWidget: wtf.NewKeyboardWidget(),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -46,16 +44,14 @@ func (widget *Widget) Refresh() {
widget.result = ticketArray widget.result = ticketArray
} }
widget.app.QueueUpdateDraw(func() {
widget.display() widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() { func (widget *Widget) display() {
widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.CommonSettings.Title, widget.result.Count)) title := fmt.Sprintf("%s (%d)", widget.CommonSettings.Title, widget.result.Count)
widget.View.SetText(widget.textContent(widget.result.Tickets)) widget.Redraw(title, widget.textContent(widget.result.Tickets), false)
} }
func (widget *Widget) textContent(items []Ticket) string { func (widget *Widget) textContent(items []Ticket) string {

View File

@ -13,6 +13,7 @@ type TextWidget struct {
focusChar string focusChar string
name string name string
refreshInterval int refreshInterval int
app *tview.Application
View *tview.TextView View *tview.TextView
@ -24,6 +25,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable
widget := TextWidget{ widget := TextWidget{
CommonSettings: commonSettings, CommonSettings: commonSettings,
app: app,
enabled: commonSettings.Enabled, enabled: commonSettings.Enabled,
focusable: focusable, focusable: focusable,
focusChar: commonSettings.FocusChar(), focusChar: commonSettings.FocusChar(),
@ -107,6 +109,16 @@ func (widget *TextWidget) TextView() *tview.TextView {
return widget.View 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 -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) addView() *tview.TextView { func (widget *TextWidget) addView() *tview.TextView {