1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
Chris Cummer 3a388fba23
20191215 code improvements (#790)
* Upgrade godo to latest
* Fix a bunch of issues found by
* Running staticcheck on a codebase for the first time is a sobering experience
* go mod tidy
* More static improvements

Signed-off-by: Chris Cummer <chriscummer@me.com>
2019-12-16 20:25:29 -08:00

72 lines
1.8 KiB
Go

package bittrex
import (
"bytes"
"fmt"
"text/template"
)
func (widget *Widget) display() {
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
if !ok {
return widget.CommonSettings().Title, errorText, true
}
list := &widget.summaryList
str := ""
for _, baseCurrency := range list.items {
str += fmt.Sprintf(
" [%s]%s[%s] (%s)\n\n",
widget.settings.colors.base.displayName,
baseCurrency.displayName,
widget.settings.colors.base.name,
baseCurrency.name,
)
resultTemplate := template.New("bittrex")
for _, marketCurrency := range baseCurrency.markets {
writer := new(bytes.Buffer)
strTemplate, _ := resultTemplate.Parse(
" [{{.nameColor}}]{{.mName}}\n" +
formatableText("High", "High") +
formatableText("Low", "Low") +
formatableText("Last", "Last") +
formatableText("Volume", "Volume") +
"\n" +
formatableText("Open Buy", "OpenBuyOrders") +
formatableText("Open Sell", "OpenSellOrders"),
)
strTemplate.Execute(writer, map[string]string{
"nameColor": widget.settings.colors.market.name,
"fieldColor": widget.settings.colors.market.field,
"valueColor": widget.settings.colors.market.value,
"mName": marketCurrency.name,
"High": marketCurrency.High,
"Low": marketCurrency.Low,
"Last": marketCurrency.Last,
"Volume": marketCurrency.Volume,
"OpenBuyOrders": marketCurrency.OpenBuyOrders,
"OpenSellOrders": marketCurrency.OpenSellOrders,
})
str += writer.String() + "\n"
}
}
return widget.CommonSettings().Title, str, true
}
func formatableText(key, value string) string {
return fmt.Sprintf("[{{.fieldColor}}]%12s: [{{.valueColor}}]{{.%s}}\n", key, value)
}