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

@@ -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 {