1
0
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:
Sean Smith
2019-08-27 21:51:37 -04:00
parent 67658e172c
commit 14e7619075
53 changed files with 209 additions and 182 deletions

View File

@@ -10,7 +10,14 @@ import (
)
func (widget *Widget) content() (string, string, bool) {
title := widget.CommonSettings().Title
if widget.err != nil {
return title, widget.err.Error(), true
}
data := widget.torrents
if data == nil || len(data) == 0 {
return title, "No data", false
}
str := ""
for idx, torrent := range data {
@@ -28,11 +35,11 @@ func (widget *Widget) content() (string, string, bool) {
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
}
return widget.CommonSettings().Title, str, false
return title, str, false
}
func (widget *Widget) display() {
widget.ScrollableWidget.RedrawFunc(widget.content)
widget.ScrollableWidget.Redraw(widget.content)
}
func (widget *Widget) prettyTorrentName(name string) string {

View File

@@ -16,6 +16,7 @@ type Widget struct {
client *transmissionrpc.Client
settings *Settings
torrents []*transmissionrpc.Torrent
err error
}
// NewWidget creates a new instance of a widget
@@ -63,14 +64,15 @@ func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) {
func (widget *Widget) Refresh() {
torrents, err := widget.Fetch()
if err != nil {
widget.err = err
widget.torrents = nil
widget.SetItemCount(0)
widget.ScrollableWidget.Redraw(widget.CommonSettings().Title, err.Error(), false)
return
} else {
widget.err = nil
widget.torrents = torrents
widget.SetItemCount(len(torrents))
}
widget.torrents = torrents
widget.SetItemCount(len(torrents))
widget.display()
}