From 72619a99a413d7d393321aca69ab72035db604ee Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Fri, 20 Mar 2020 19:46:27 -0700 Subject: [PATCH] handle multiple conversions per base currency Signed-off-by: Chris Cummer --- modules/exchangerates/widget.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/exchangerates/widget.go b/modules/exchangerates/widget.go index c638d787..809b00ef 100644 --- a/modules/exchangerates/widget.go +++ b/modules/exchangerates/widget.go @@ -43,25 +43,26 @@ func (widget *Widget) Refresh() { widget.Render() } -/* -------------------- Unexported Functions -------------------- */ - func (widget *Widget) Render() { widget.Redraw(widget.content) } +/* -------------------- Unexported Functions -------------------- */ + func (widget *Widget) content() (string, string, bool) { - var out string + out := "" if widget.err != nil { out = widget.err.Error() } else { for base, rates := range widget.settings.rates { - out += fmt.Sprintf("[%s]1 %s[white] = ", widget.settings.common.Colors.Subheading, base) - idx := 0 - for _, cur := range rates { + prefix := fmt.Sprintf("[%s]1 %s[white] = ", widget.settings.common.Colors.Subheading, base) + + for idx, cur := range rates { rate := widget.rates[base][cur] + + out += prefix out += fmt.Sprintf("[%s]%f %s[white]\n", widget.CommonSettings().RowColor(idx), rate, cur) - idx++ } } }