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:
@@ -7,16 +7,15 @@ import (
|
||||
)
|
||||
|
||||
func (widget *Widget) display() {
|
||||
if ok == false {
|
||||
widget.Redraw(widget.CommonSettings().Title, errorText, true)
|
||||
return
|
||||
}
|
||||
|
||||
summaryText := widget.summaryText(&widget.summaryList)
|
||||
widget.Redraw(widget.CommonSettings().Title, summaryText, false)
|
||||
widget.RedrawFunc(widget.content)
|
||||
}
|
||||
|
||||
func (widget *Widget) summaryText(list *summaryList) string {
|
||||
func (widget *Widget) content() (string, string, bool) {
|
||||
if ok == false {
|
||||
return widget.CommonSettings().Title, errorText, true
|
||||
}
|
||||
list := &widget.summaryList
|
||||
str := ""
|
||||
|
||||
for _, baseCurrency := range list.items {
|
||||
@@ -62,7 +61,7 @@ func (widget *Widget) summaryText(list *summaryList) string {
|
||||
|
||||
}
|
||||
|
||||
return str
|
||||
return widget.CommonSettings().Title, str, true
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -32,19 +32,18 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
positions, err := Fetch(widget.device_token)
|
||||
if err != nil {
|
||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
||||
return
|
||||
}
|
||||
|
||||
content := widget.contentFrom(positions)
|
||||
|
||||
widget.Redraw(widget.CommonSettings().Title, content, false)
|
||||
widget.RedrawFunc(widget.content)
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
|
||||
func (widget *Widget) content() (string, string, bool) {
|
||||
positions, err := Fetch(widget.device_token)
|
||||
title := widget.CommonSettings().Title
|
||||
if err != nil {
|
||||
return title, err.Error(), true
|
||||
}
|
||||
|
||||
res := ""
|
||||
totalFiat := float32(0.0)
|
||||
|
||||
@@ -86,7 +85,7 @@ func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
|
||||
res += fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000)
|
||||
}
|
||||
|
||||
return res
|
||||
return title, res, true
|
||||
}
|
||||
|
||||
//always the same
|
||||
|
||||
@@ -46,15 +46,15 @@ func (widget *Widget) Refresh() {
|
||||
widget.toplistWidget.Refresh(&wg)
|
||||
wg.Wait()
|
||||
|
||||
widget.display()
|
||||
widget.RedrawFunc(widget.content)
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) display() {
|
||||
func (widget *Widget) content() (string, string, bool) {
|
||||
str := ""
|
||||
str += widget.priceWidget.Result
|
||||
str += widget.toplistWidget.Result
|
||||
|
||||
widget.Redraw(widget.CommonSettings().Title, fmt.Sprintf("\n%s", str), false)
|
||||
return widget.CommonSettings().Title, fmt.Sprintf("\n%s", str), false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user