reg prettier print same col w
cicd / ci (push) Successful in 54s
Details
cicd / ci (push) Successful in 54s
Details
parent
9646356d7f
commit
fabd26e8e9
|
|
@ -98,6 +98,13 @@ func Main() {
|
||||||
w := bufio.NewWriter(os.Stdout)
|
w := bufio.NewWriter(os.Stdout)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
|
maxAccW := 0
|
||||||
|
for _, delta := range deltas.Like(q).Group(group) {
|
||||||
|
if accW := len(delta.Name); accW > maxAccW {
|
||||||
|
maxAccW = accW
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch cmd[:3] {
|
switch cmd[:3] {
|
||||||
case "bal":
|
case "bal":
|
||||||
balances := deltas.Balances().
|
balances := deltas.Balances().
|
||||||
|
|
@ -105,7 +112,7 @@ func Main() {
|
||||||
KindaLike(q).
|
KindaLike(q).
|
||||||
KindaGroup(group).
|
KindaGroup(group).
|
||||||
Nonzero()
|
Nonzero()
|
||||||
FPrintBalances(w, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false)
|
FPrintBalances(w, "", balances, nil, config.Query.USDOnly, config.Query.Normalize, time.Now().Format("2006-01-02"), false, maxAccW)
|
||||||
case "reg":
|
case "reg":
|
||||||
transactions := deltas.Transactions()
|
transactions := deltas.Transactions()
|
||||||
cumulative := make(ledger.Balances)
|
cumulative := make(ledger.Balances)
|
||||||
|
|
@ -124,7 +131,7 @@ func Main() {
|
||||||
if shouldPrint {
|
if shouldPrint {
|
||||||
cumulative.PushAll(balances)
|
cumulative.PushAll(balances)
|
||||||
cumulative = cumulative.Nonzero()
|
cumulative = cumulative.Nonzero()
|
||||||
FPrintBalancesFor(transaction[0].Description, w, "\t\t", balances, cumulative, config.Query.USDOnly, config.Query.Normalize, transaction[0].Date, config.Compact)
|
FPrintBalancesFor(transaction[0].Description, w, "\t\t", balances, cumulative, config.Query.USDOnly, config.Query.Normalize, transaction[0].Date, config.Compact, maxAccW)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -132,16 +139,16 @@ func Main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FPrintBalancesFor(description string, w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string, compact bool) {
|
func FPrintBalancesFor(description string, w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string, compact bool, keyW int) {
|
||||||
if compact {
|
if compact {
|
||||||
FPrintBalances(w, date+"\t", balances, cumulatives, usdOnly, normalized, date, compact)
|
FPrintBalances(w, date+"\t", balances, cumulatives, usdOnly, normalized, date, compact, keyW)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "%s\t%s\n", date, description)
|
fmt.Fprintf(w, "%s\t%s\n", date, description)
|
||||||
FPrintBalances(w, linePrefix, balances, cumulatives, usdOnly, normalized, date, compact)
|
FPrintBalances(w, linePrefix, balances, cumulatives, usdOnly, normalized, date, compact, keyW)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string, fullKey bool) {
|
func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger.Balances, usdOnly, normalized bool, date string, fullKey bool, max int) {
|
||||||
maxes := map[ledger.Currency]float64{}
|
maxes := map[ledger.Currency]float64{}
|
||||||
keys := []string{}
|
keys := []string{}
|
||||||
for k, v := range balances {
|
for k, v := range balances {
|
||||||
|
|
@ -154,13 +161,6 @@ func FPrintBalances(w io.Writer, linePrefix string, balances, cumulatives ledger
|
||||||
}
|
}
|
||||||
slices.Sort(keys)
|
slices.Sort(keys)
|
||||||
|
|
||||||
max := 0
|
|
||||||
for _, k := range keys {
|
|
||||||
if n := len(k); n > max {
|
|
||||||
max = n
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
normalizer := ana.NewDefaultNormalizer()
|
normalizer := ana.NewDefaultNormalizer()
|
||||||
|
|
||||||
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f)\n", linePrefix, max)
|
format := fmt.Sprintf("%s%%-%ds\t%%s%%.2f (%%s%%.2f)\n", linePrefix, max)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue