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:
parent
155722d7ee
commit
eb75946e64
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user