From 1adc63655420d7011430d4f629e8385ab53faea3 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 4 Jun 2017 17:41:42 -0700 Subject: [PATCH] lib: show pending posting flags when rendering a transaction (fix #563) This affects hledger-ui's transaction screen, print, hledger-rewrite etc. A pending flag on postings is now displayed, just like a cleared flag. Also there will now be a space between flag and account name. And it's slightly better at aligning amounts, due to now considering virtual posting parentheses/brackets or something. --- hledger-lib/Hledger/Data/Transaction.hs | 15 +++++++++------ tests/bin/rewrite.test | 6 +++--- tests/misc/account-aliases.test | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 13fcb3a6b..de154d10f 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -212,14 +212,17 @@ postingAsLines elideamount onelineamounts ps p = concat [ ++ newlinecomments | postingblock <- postingblocks] where - postingblocks = [map rstrip $ lines $ concatTopPadded [account, " ", amount, assertion, samelinecomment] | amount <- shownAmounts] + postingblocks = [map rstrip $ lines $ concatTopPadded [statusandaccount, " ", amount, assertion, samelinecomment] | amount <- shownAmounts] assertion = maybe "" ((" = " ++) . showAmountWithZeroCommodity) $ pbalanceassertion p - account = - indent $ - showstatus p ++ fitString (Just acctwidth) Nothing False True (showAccountName Nothing (ptype p) (paccount p)) + statusandaccount = indent $ fitString (Just $ minwidth) Nothing False True $ pstatusandacct p where - showstatus p = if pstatus p == Cleared then "* " else "" - acctwidth = maximum $ map (textWidth . paccount) ps + -- pad to the maximum account name width, to keep amounts aligned + minwidth = maximum $ map (textWidth . T.pack . pacctstr) ps + pstatusandacct p' = pstatusprefix p' ++ pacctstr p' + pstatusprefix p' | null s = "" + | otherwise = s ++ " " + where s = show $ pstatus p' + pacctstr p' = showAccountName Nothing (ptype p') (paccount p') -- currently prices are considered part of the amount string when right-aligning amounts shownAmounts diff --git a/tests/bin/rewrite.test b/tests/bin/rewrite.test index 4efba2448..eeafd0f8a 100644 --- a/tests/bin/rewrite.test +++ b/tests/bin/rewrite.test @@ -70,15 +70,15 @@ >>> 2017/04/24 * 09:00-09:25 (assets:unbilled:client1) 0.42h - (assets:to bill:client1) 42.00 CAD + (assets:to bill:client1) 42.00 CAD 2017/04/25 * 10:00-11:15 (assets:unbilled:client1) 1.25h - (assets:to bill:client1) 125.00 CAD + (assets:to bill:client1) 125.00 CAD 2017/04/25 * 14:00-15:32 (assets:unbilled:client2) 1.54h - (assets:to bill:client2) 231.00 CAD + (assets:to bill:client2) 231.00 CAD >>>2 >>>=0 diff --git a/tests/misc/account-aliases.test b/tests/misc/account-aliases.test index 2fb61a530..a27229853 100644 --- a/tests/misc/account-aliases.test +++ b/tests/misc/account-aliases.test @@ -116,7 +116,7 @@ alias E=F >>> 2011/01/01 - [E:x] 1 + [E:x] 1 [x:A:x] >>>2