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

Convert the bulk of modules over to RedrawFunc

This commit is contained in:
Sean Smith
2019-08-26 23:07:02 -04:00
parent 51e4325f0b
commit 3a716bcf9a
25 changed files with 214 additions and 224 deletions

View File

@@ -16,6 +16,7 @@ type Widget struct {
view.TextWidget
settings *Settings
items []Item
}
func NewWidget(app *tview.Application, settings *Settings) *Widget {
@@ -37,28 +38,28 @@ func (widget *Widget) Refresh() {
widget.settings.subdomain,
)
todayItems := client.Away(
widget.items = client.Away(
"timeOff",
time.Now().Local().Format(wtf.DateFormat),
time.Now().Local().Format(wtf.DateFormat),
)
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(todayItems), false)
widget.RedrawFunc(widget.content)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(items []Item) string {
if len(items) == 0 {
return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
}
func (widget *Widget) content() (string, string, bool) {
str := ""
for _, item := range items {
str += widget.format(item)
if len(widget.items) == 0 {
str = fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
} else {
for _, item := range widget.items {
str += widget.format(item)
}
}
return str
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) format(item Item) string {