print: always right-align amounts

print now always right-aligns the amounts in an entry, even when they
are wider than 12 characters.

If there is a price, it's considered part of the amount for
right-alignment. Maybe it would be nicer to put amounts and prices in
separate columns ? That will get a little complicated, needs more
discussion/design.

Also some cleanup of postingAsLines.
This commit is contained in:
Simon Michael 2015-10-10 15:09:42 -07:00
parent 155722d7ee
commit eb75946e64
5 changed files with 58 additions and 23 deletions

View File

@ -175,19 +175,25 @@ postingAsLines elideamount ps p =
postinglines
++ newlinecomments
where
postinglines = map rstrip $ lines $ concatTopPadded [showacct p, " ", amount, samelinecomment]
amount = if elideamount then "" else showamt (pamount p)
postinglines = map rstrip $ lines $ concatTopPadded [account, " ", amount, samelinecomment]
account =
indent $
showstatus p ++ fitString (Just acctwidth) Nothing False True (showAccountName Nothing (ptype p) (paccount p))
where
showstatus p = if pstatus p == Cleared then "* " else ""
acctwidth = maximum $ map (strWidth . paccount) ps
-- currently prices are considered part of the amount string when right-aligning amounts
amount
| elideamount = ""
| otherwise = fitStringMulti (Just amtwidth) Nothing False False $ showMixedAmount $ pamount p
where
amtwidth = maximum $ 12 : map (strWidth . showMixedAmount . pamount) ps -- min. 12 for backwards compatibility
(samelinecomment, newlinecomments) =
case renderCommentLines (pcomment p) of [] -> ("",[])
c:cs -> (c,cs)
showacct p =
indent $
showstatus p ++ fitString (Just w) Nothing False True (showAccountName Nothing (ptype p) (paccount p))
where
showstatus p = if pstatus p == Cleared then "* " else ""
w = maximum $ map (strWidth . paccount) ps
showamt =
padLeftWide 12 . showMixedAmount
tests_postingAsLines = [
"postingAsLines" ~: do

View File

@ -1,17 +1,46 @@
# ALl output should preserve alignment etc. when showing wide characters.
# XXX For a better test, the sample journals should have commodity symbols.
# XXX How to test hledger-ui ?
# ALl output should preserve alignment etc. when showing wide characters
# (in apps and fonts which render wide chars as exactly double width).
#
# XXX add commodity symbols and prices to the sample journals
# XXX how to test hledger-ui ?
# 1.
hledger -f chinese.journal print
# hledger -f chinese.journal print
# >>>
# 2014/01/01 transaction 1
# 㐀 1
# 㐀:㐁 -1
#
# 2014/01/02 transaction 2
# 㐀:㐁:㐂 1
# 㐀:㐁:㐂:㐃 -1
#
# 2014/01/03 transaction 3
# 㐀:㐁:㐂:㐃:㐄 1
# 㐀 -1
#
# >>>=0
hledger -f - print
<<<
2014-01-01 transaction 1
㐀 㐃㐃1 @ 2 㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂
㐀:㐁 ;㐃㐃-1
2014-01-02 transaction 2
㐀:㐁:㐂 USD 1
㐀:㐁:㐂:㐃 EUR -1
2014-01-03 transaction 3
㐀:㐁:㐂:㐃:㐄 1
㐀 -1
>>>
2014/01/01 transaction 1
㐀 1
㐀:㐁 -1
㐃㐃1 @ 2 㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂
㐀:㐁 -2 㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂 ; 㐃㐃-1
2014/01/02 transaction 2
㐀:㐁:㐂 1
㐀:㐁:㐂:㐃 -1
㐀:㐁:㐂 USD 1 @@ EUR 1
㐀:㐁:㐂:㐃 EUR -1
2014/01/03 transaction 3
㐀:㐁:㐂:㐃:㐄 1

View File

@ -15,7 +15,7 @@ hledger -f- print
b
>>>
2010/04/05 x
a 10 "DE 0002 635307"
a 10 "DE 0002 635307"
b -10 "DE 0002 635307"
>>>=0

View File

@ -10,7 +10,7 @@ hledger -f - print
>>>
2010/01/01 x
A 55.3653 C @ 30.92189512 D
A -1712 D
A -1712 D
>>>=0
@ -140,7 +140,7 @@ hledger -f- print
2015/01/01
c C 10.00 @ D 15.2381
c C 11.00 @ D 15.2381
d D -320.00
d D -320.00
>>>=0
@ -157,6 +157,6 @@ hledger -f- print
2015/01/01
e E 10.0000 @ F 15.2380952
e E 11.0000 @ F 15.2380952
f F -320.000
f F -320.000
>>>=0

View File

@ -85,7 +85,7 @@ hledger -f - print
>>>
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG @@ $17,783.72
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
>>>=0