mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Renormalize the redraw function
Have all instances take a function Update the remaining modules to take this into account Numerous smaller refactors to make some widgets work more or less the same
This commit is contained in:
@@ -13,6 +13,7 @@ type Widget struct {
|
||||
|
||||
settings *Settings
|
||||
view *View
|
||||
err error
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
@@ -47,24 +48,27 @@ func (widget *Widget) Refresh() {
|
||||
widget.view = view
|
||||
|
||||
if err != nil {
|
||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
||||
return
|
||||
widget.err = err
|
||||
widget.SetItemCount(0)
|
||||
} else {
|
||||
widget.SetItemCount(len(widget.view.Jobs))
|
||||
}
|
||||
|
||||
widget.SetItemCount(len(widget.view.Jobs))
|
||||
|
||||
widget.Render()
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Render() {
|
||||
widget.RedrawFunc(widget.content)
|
||||
widget.Redraw(widget.content)
|
||||
}
|
||||
|
||||
func (widget *Widget) content() (string, string, bool) {
|
||||
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
|
||||
if widget.view == nil {
|
||||
if widget.err != nil {
|
||||
return title, widget.err.Error(), true
|
||||
}
|
||||
if widget.view == nil || len(widget.view.Jobs) == 0 {
|
||||
return title, "No content to display", false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user