From 16f8b783050bd5dca0d0ebb359768ab1e249639b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 3 Jul 2014 07:45:55 -0700 Subject: [PATCH] balance: show multi-commodity amts on one line (fixes #186) To avoid totally breaking the layout of multicolumn balance reports when there are multi-commodity balances, these are now rendered on a single line, comma separated. Simple balance reports still use the old vertical format for now. --- hledger-lib/Hledger/Data/Amount.hs | 9 +++++++++ hledger/Hledger/Cli/Balance.hs | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index f6194bc2c..b79ac015f 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -63,6 +63,7 @@ module Hledger.Data.Amount ( showAmount, showAmountDebug, showAmountWithoutPrice, + showMixedAmountOneLineWithoutPrice, maxprecision, maxprecisionwithpoint, setAmountPrecision, @@ -501,6 +502,14 @@ showMixedAmountWithoutPrice m = concat $ intersperse "\n" $ map showfixedwidth a width = maximum $ map (length . showAmount) as showfixedwidth = printf (printf "%%%ds" width) . showAmountWithoutPrice +-- | Get the one-line string representation of a mixed amount, but without +-- any \@ prices. +showMixedAmountOneLineWithoutPrice :: MixedAmount -> String +showMixedAmountOneLineWithoutPrice m = concat $ intersperse ", " $ map showAmountWithoutPrice as + where + (Mixed as) = normaliseMixedAmountPreservingFirstPrice $ stripPrices m + stripPrices (Mixed as) = Mixed $ map stripprice as where stripprice a = a{aprice=NoPrice} + -- | Canonicalise a mixed amount's display styles using the provided commodity style map. canonicaliseMixedAmount :: M.Map Commodity AmountStyle -> MixedAmount -> MixedAmount canonicaliseMixedAmount styles (Mixed as) = Mixed $ map (canonicaliseAmount styles) as diff --git a/hledger/Hledger/Cli/Balance.hs b/hledger/Hledger/Cli/Balance.hs index 9211577d2..2bb34a296 100644 --- a/hledger/Hledger/Cli/Balance.hs +++ b/hledger/Hledger/Cli/Balance.hs @@ -374,7 +374,7 @@ periodBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) render id ((" "++) . showDateSpan) - showMixedAmountWithoutPrice + showMixedAmountOneLineWithoutPrice $ Table (T.Group NoLine $ map (Header . padright acctswidth) accts) (T.Group NoLine $ map Header colspans) @@ -398,7 +398,7 @@ cumulativeBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> [String] cumulativeBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) = (["Ending balance (cumulative):"] ++) $ trimborder $ lines $ - render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountWithoutPrice $ + render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountOneLineWithoutPrice $ addtotalrow $ Table (T.Group NoLine $ map (Header . padright acctswidth) accts) @@ -419,7 +419,7 @@ historicalBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> [String] historicalBalanceReportAsText opts (MultiBalanceReport (colspans, items, coltotals)) = (["Ending balance (historical):"] ++) $ trimborder $ lines $ - render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountWithoutPrice $ + render id ((" "++) . maybe "" (showDate . prevday) . spanEnd) showMixedAmountOneLineWithoutPrice $ addtotalrow $ Table (T.Group NoLine $ map (Header . padright acctswidth) accts)