From cc546d9b2dad88d4509523a6c9bddcff888910c5 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sun, 26 Oct 2025 13:11:09 -0600 Subject: [PATCH] fix --- cmd/cli/main.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index cd8e599..599530e 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -148,17 +148,23 @@ func Main() { cumulatives := make(ledger.Balances) var sum float64 for key := range balances { - usd, ok := balances[key][ledger.USD] - if ok { - cumulatives[key] = ledger.Balance{ledger.USD: usd} - sum += usd + if _, ok := cumulatives[key]; !ok { + cumulatives[key] = make(ledger.Balance) + } + for currency, val := range balances[key] { + if currency == ledger.USD { + cumulatives[key][currency] = val + sum += val + } else { + cumulatives[key][currency] = 0 + } } } for key := range cumulatives { cumulatives[key][ledger.USD] = 100 * cumulatives[key][ledger.USD] / sum } - FPrintBalances(w, "", balances, cumulatives, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW, "%.0f%%%%") + FPrintBalances(w, "", balances, cumulatives, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW, "%.0f%%") case "gra": // graph dateGrouping := "^[0-9]{4}-[0-9]{2}" if period := config.Query.Period; !period.Empty() { @@ -352,9 +358,10 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger normalizer := ana.NewDefaultNormalizer() - format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%"+cumulativeFormat+")\n", linePrefix, max) + cumulativeFormat = strings.ReplaceAll(cumulativeFormat, "%", "%%") + format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f ("+cumulativeFormat+")\n", linePrefix, max) if normalized { - format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f (%"+cumulativeFormat+")))\n", linePrefix, max) + format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f ("+cumulativeFormat+")))\n", linePrefix, max) } for i, key := range keys { printableKey := key @@ -389,12 +396,9 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger for _, currency := range currencies { printableCurrency := currency format := format - printPrintableCurrency := strings.Count(cumulativeFormat, "%s") > 0 - if printPrintableCurrency { - if printableCurrency != "$" { - printableCurrency += " " - format = strings.ReplaceAll(format, "%.2f", "%.3f") - } + if printableCurrency != "$" { + printableCurrency += " " + format = strings.ReplaceAll(format, "%.2f", "%.3f") } if usdOnly && printableCurrency != "$" { continue @@ -407,9 +411,14 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger cumulative = value } - if printPrintableCurrency { + printingPercents := strings.Contains(cumulativeFormat, "%%%%") + if !printingPercents { if !normalized { - fmt.Fprintf(w, format, printableKey, printableCurrency, balances[key][currency], printableCurrency, cumulative) + fmt.Fprintf(w, format, + printableKey, + printableCurrency, balances[key][currency], + printableCurrency, cumulative, + ) } else { factor := normalizer.NormalizeFactor(key, date) trailingMax := maxes[currency] - math.Abs(balances[key][currency])