cli: Use new mixed amount display functions for balance format strings.

This commit is contained in:
Stephen Morgan 2020-10-26 13:20:31 +11:00
parent b39de5989f
commit e9a16edb58
2 changed files with 24 additions and 7 deletions

View File

@ -410,7 +410,7 @@ renderComponent opts (acctname, depth, total) (FormatField ljust min max field)
Just m -> depth * m
Nothing -> depth
AccountField -> formatString ljust min max (T.unpack acctname)
TotalField -> fitStringMulti min max True False $ showMixedAmountWithoutPrice (color_ opts) total
TotalField -> fst $ showMixed showAmountWithoutPrice min max (color_ opts) total
_ -> ""
-- | Render one StringFormat component for a balance report item.
@ -425,9 +425,7 @@ renderComponent1 opts (acctname, depth, total) (FormatField ljust min max field)
-- better to indent the account name here rather than use a DepthField component
-- so that it complies with width spec. Uses a fixed indent step size.
indented = ((replicate (depth*2) ' ')++)
TotalField -> fitStringMulti min max True False $ ((intercalate ", " . map strip . lines) (showamt total))
where
showamt = showMixedAmountWithoutPrice (color_ opts)
TotalField -> fst $ showMixedOneLine showAmountWithoutPrice min max (color_ opts) total
_ -> ""
-- rendering multi-column balance reports

View File

@ -1,5 +1,5 @@
hledger -f sample.journal balance --tree --format="%30(account) %-.20(total)"
>>>
$ hledger -f sample.journal balance --tree --format="%30(account) %-.20(total)"
>
assets $-1
bank:saving $1
cash $-2
@ -12,4 +12,23 @@ hledger -f sample.journal balance --tree --format="%30(account) %-.20(total)"
liabilities:debts $1
----------------------------------
0
>>>= 0
>= 0
<
2020-09-01 Test
a -500 AAA
b
# Test too-small maximum balance widths
$ hledger -f - balance -N --format="%7.7(total) %(account)"
>
1 mor.. a
500 AAA b
>= 0
# Check that maximum balance widths works with colour
$ hledger -f - balance -N --format="%8.8(total) %(account)" --color=yes
>
-500 AAA a
500 AAA b
>= 0