diff --git a/BalanceCommand.hs b/BalanceCommand.hs index 3d0efef81..7ccc6fc36 100644 --- a/BalanceCommand.hs +++ b/BalanceCommand.hs @@ -132,7 +132,7 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr) collapse = Collapse `elem` opts totalstr = if isZeroMixedAmount total then "" - else printf "--------------------\n%20s\n" $ showMixedAmount total + else printf "--------------------\n%s\n" $ padleft 20 $ showMixedAmount total total = sum $ map (abalance . ledgerAccount l) $ nonredundantaccts nonredundantaccts = filter (not . hasparentshowing) matchedacctnames hasparentshowing aname = (parentAccountName $ aname) `elem` matchedacctnames @@ -175,8 +175,8 @@ showAccountTreeWithBalances matchednames t = showAccountTreeWithBalances' matche subsindented = showsubs (indent+1) "" showsubs i p = concatMap (showAccountTreeWithBalances' matchednames i p) subs hasmatchedsubs = not $ null $ filter ((`elem` matchednames) . aname) $ concatMap flatten subs - this = showbal ++ spaces ++ prefix ++ leafname ++ "\n" - showbal = printf "%20s" $ showMixedAmount bal + amt = padleft 20 $ showMixedAmount bal + this = concatTopPadded [amt, spaces ++ prefix ++ leafname] ++ "\n" spaces = " " ++ replicate (indent * 2) ' ' leafname = accountLeafName fullname ismatched = fullname `elem` matchednames @@ -184,3 +184,4 @@ showAccountTreeWithBalances matchednames t = showAccountTreeWithBalances' matche numsubs = length subs subbal = abalance $ root $ head subs matched = fullname `elem` matchednames + diff --git a/Ledger/Amount.hs b/Ledger/Amount.hs index 020509cd4..0d99df34e 100644 --- a/Ledger/Amount.hs +++ b/Ledger/Amount.hs @@ -134,8 +134,11 @@ isZeroMixedAmount = all isZeroAmount . amounts . normaliseMixedAmount -- | Get the string representation of a mixed amount, showing each of -- its component amounts. showMixedAmount :: MixedAmount -> String -showMixedAmount m = concat $ intersperse ", " $ map show as - where (Mixed as) = normaliseMixedAmount m +showMixedAmount m = concat $ intersperse "\n" $ map showfixedwidth as + where + (Mixed as) = normaliseMixedAmount m + width = maximum $ map (length . show) $ as + showfixedwidth = printf (printf "%%%ds" width) . show -- | Get the string representation of a mixed amount, and if it -- appears to be all zero just show a bare 0, ledger-style. diff --git a/Ledger/RawTransaction.hs b/Ledger/RawTransaction.hs index 243407276..7e87741fe 100644 --- a/Ledger/RawTransaction.hs +++ b/Ledger/RawTransaction.hs @@ -19,14 +19,14 @@ nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction showRawTransaction :: RawTransaction -> String showRawTransaction (RawTransaction a amt _ ttype) = - showaccountname a ++ " " ++ (showamount amt) + concatTopPadded [showaccountname a ++ " ", showamount amt] where showaccountname = printf "%-22s" . bracket . elideAccountName width - showamount = printf "%12s" . showMixedAmountOrZero (bracket,width) = case ttype of BalancedVirtualTransaction -> (\s -> "["++s++"]", 20) VirtualTransaction -> (\s -> "("++s++")", 20) otherwise -> (id,22) + showamount = padleft 12 . showMixedAmountOrZero isReal :: RawTransaction -> Bool isReal t = rttype t == RegularTransaction diff --git a/NOTES b/NOTES index deefce32e..3a9481409 100644 --- a/NOTES +++ b/NOTES @@ -6,7 +6,6 @@ implementations were its consequences." --Niklaus Wirth * to do ** errors -*** display mixed amounts vertically, not horizontally ** features *** flexible date expressions, for easier time reports **** more formats diff --git a/RegisterCommand.hs b/RegisterCommand.hs index d9a4edc89..4acb6f549 100644 --- a/RegisterCommand.hs +++ b/RegisterCommand.hs @@ -43,11 +43,11 @@ showRegisterReport opts args l = showtxns ts nulltxn nullmixedamt -- show one transaction line, with or without the entry details showtxn :: Bool -> Transaction -> MixedAmount -> String - showtxn omitdesc t b = entrydesc ++ txn ++ bal ++ "\n" + showtxn omitdesc t b = concatBottomPadded [entrydesc ++ txn ++ " ", bal] ++ "\n" where entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc date = show $ da desc = printf "%-20s" $ elideRight 20 de :: String txn = showRawTransaction $ RawTransaction a amt "" tt - bal = printf " %12s" (showMixedAmountOrZero b) + bal = padleft 12 (showMixedAmountOrZero b) Transaction{date=da,description=de,account=a,amount=amt,ttype=tt} = t