neater bal print
parent
9352ca82de
commit
9b4accafe3
|
|
@ -158,7 +158,25 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
||||||
if normalized {
|
if normalized {
|
||||||
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f (%%s%%.0f)))\n", linePrefix, max)
|
format = fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f (%%.2f @%%.2f (%%s%%.0f)))\n", linePrefix, max)
|
||||||
}
|
}
|
||||||
for _, key := range keys {
|
for i, key := range keys {
|
||||||
|
printableKey := key
|
||||||
|
if i > 0 {
|
||||||
|
j := 0
|
||||||
|
n := len(keys[i])
|
||||||
|
if n2 := len(keys[i-1]); n2 < n {
|
||||||
|
n = n2
|
||||||
|
}
|
||||||
|
for j = 0; j < n; j++ {
|
||||||
|
if keys[i-1][j] != keys[i][j] {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for keys[i][j] != ':' && j > 0 {
|
||||||
|
j -= 1
|
||||||
|
}
|
||||||
|
printableKey = strings.Repeat(" ", j) + keys[i][j:]
|
||||||
|
}
|
||||||
|
|
||||||
currencies := []ledger.Currency{}
|
currencies := []ledger.Currency{}
|
||||||
for currency := range balances[key] {
|
for currency := range balances[key] {
|
||||||
currencies = append(currencies, currency)
|
currencies = append(currencies, currency)
|
||||||
|
|
@ -182,11 +200,11 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
||||||
}
|
}
|
||||||
|
|
||||||
if !normalized {
|
if !normalized {
|
||||||
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative)
|
fmt.Fprintf(w, format, printableKey, printableCurrency, balances[key][currency], printableCurrency, cumulative)
|
||||||
} else {
|
} else {
|
||||||
factor := normalizer.NormalizeFactor(ledger.Delta{Name: key, Date: date})
|
factor := normalizer.NormalizeFactor(ledger.Delta{Name: key, Date: date})
|
||||||
trailingMax := maxes[currency] - math.Abs(balances[key][currency])
|
trailingMax := maxes[currency] - math.Abs(balances[key][currency])
|
||||||
fmt.Fprintf(w, format, key, printableCurrency, balances[key][currency], printableCurrency, cumulative, cumulative*factor, factor, printableCurrency, factor*trailingMax)
|
fmt.Fprintf(w, format, printableKey, printableCurrency, balances[key][currency], printableCurrency, cumulative, cumulative*factor, factor, printableCurrency, factor*trailingMax)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue