dev: distinguish oneLineFmt and oneLineNoCostFmt; add fullZeroFmt
This commit is contained in:
parent
999cba8c31
commit
df79aa5e35
@ -79,8 +79,10 @@ module Hledger.Data.Amount (
|
|||||||
-- ** rendering
|
-- ** rendering
|
||||||
AmountFormat(..),
|
AmountFormat(..),
|
||||||
defaultFmt,
|
defaultFmt,
|
||||||
|
fullZeroFmt,
|
||||||
noCostFmt,
|
noCostFmt,
|
||||||
oneLineFmt,
|
oneLineFmt,
|
||||||
|
oneLineNoCostFmt,
|
||||||
machineFmt,
|
machineFmt,
|
||||||
showAmount,
|
showAmount,
|
||||||
showAmountWith,
|
showAmountWith,
|
||||||
@ -217,7 +219,7 @@ quoteCommoditySymbolIfNeeded s
|
|||||||
| otherwise = s
|
| otherwise = s
|
||||||
|
|
||||||
-- | Formatting options available when displaying Amounts and MixedAmounts.
|
-- | Formatting options available when displaying Amounts and MixedAmounts.
|
||||||
-- Similar to "AmountStyle" but lower level, and not attached to amounts or commodities.
|
-- Similar to "AmountStyle" but lower level, not attached to amounts or commodities, and can override it in some ways.
|
||||||
-- See also hledger manual > "Amount formatting, parseability", which speaks of human, hledger, and machine output.
|
-- See also hledger manual > "Amount formatting, parseability", which speaks of human, hledger, and machine output.
|
||||||
data AmountFormat = AmountFormat
|
data AmountFormat = AmountFormat
|
||||||
{ displayCommodity :: Bool -- ^ Whether to display commodity symbols.
|
{ displayCommodity :: Bool -- ^ Whether to display commodity symbols.
|
||||||
@ -254,17 +256,25 @@ defaultFmt = AmountFormat {
|
|||||||
, displayColour = False
|
, displayColour = False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Like defaultFmt but show zero amounts with commodity symbol and styling, like non-zero amounts.
|
||||||
|
fullZeroFmt :: AmountFormat
|
||||||
|
fullZeroFmt = defaultFmt{displayZeroCommodity=True}
|
||||||
|
|
||||||
-- | Like defaultFmt but don't show costs.
|
-- | Like defaultFmt but don't show costs.
|
||||||
noCostFmt :: AmountFormat
|
noCostFmt :: AmountFormat
|
||||||
noCostFmt = defaultFmt{displayCost=False}
|
noCostFmt = defaultFmt{displayCost=False}
|
||||||
|
|
||||||
-- | Like noCostFmt but display amounts on one line rather than several.
|
-- | Like defaultFmt but display all amounts on one line.
|
||||||
oneLineFmt :: AmountFormat
|
oneLineFmt :: AmountFormat
|
||||||
oneLineFmt = noCostFmt{displayOneLine=True}
|
oneLineFmt = defaultFmt{displayOneLine=True}
|
||||||
|
|
||||||
-- | A (slightly more) machine-readable amount format; like oneLineFmt but don't show digit group marks.
|
-- | Like noCostFmt but display all amounts on one line.
|
||||||
|
oneLineNoCostFmt :: AmountFormat
|
||||||
|
oneLineNoCostFmt = noCostFmt{displayOneLine=True}
|
||||||
|
|
||||||
|
-- | A (slightly more) machine-readable amount format; like oneLineNoCostFmt but don't show digit group marks.
|
||||||
machineFmt :: AmountFormat
|
machineFmt :: AmountFormat
|
||||||
machineFmt = oneLineFmt{displayDigitGroups=False}
|
machineFmt = oneLineNoCostFmt{displayDigitGroups=False}
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Amount arithmetic
|
-- Amount arithmetic
|
||||||
@ -1032,7 +1042,7 @@ showMixedAmountWith fmt = wbUnpack . showMixedAmountB fmt
|
|||||||
-- | Get the one-line string representation of a mixed amount (also showing any costs).
|
-- | Get the one-line string representation of a mixed amount (also showing any costs).
|
||||||
-- See showMixedAmountB for special cases.
|
-- See showMixedAmountB for special cases.
|
||||||
showMixedAmountOneLine :: MixedAmount -> String
|
showMixedAmountOneLine :: MixedAmount -> String
|
||||||
showMixedAmountOneLine = wbUnpack . showMixedAmountB oneLineFmt{displayCost=True}
|
showMixedAmountOneLine = wbUnpack . showMixedAmountB oneLineNoCostFmt{displayCost=True}
|
||||||
|
|
||||||
-- | Like showMixedAmount, but zero amounts are shown with their
|
-- | Like showMixedAmount, but zero amounts are shown with their
|
||||||
-- commodity if they have one.
|
-- commodity if they have one.
|
||||||
@ -1054,7 +1064,7 @@ showMixedAmountWithoutCost c = wbUnpack . showMixedAmountB noCostFmt{displayColo
|
|||||||
--
|
--
|
||||||
-- > showMixedAmountOneLineWithoutCost c = wbUnpack . showMixedAmountB oneLineFmt{displayColour=c}
|
-- > showMixedAmountOneLineWithoutCost c = wbUnpack . showMixedAmountB oneLineFmt{displayColour=c}
|
||||||
showMixedAmountOneLineWithoutCost :: Bool -> MixedAmount -> String
|
showMixedAmountOneLineWithoutCost :: Bool -> MixedAmount -> String
|
||||||
showMixedAmountOneLineWithoutCost c = wbUnpack . showMixedAmountB oneLineFmt{displayColour=c}
|
showMixedAmountOneLineWithoutCost c = wbUnpack . showMixedAmountB oneLineNoCostFmt{displayColour=c}
|
||||||
|
|
||||||
-- | Like showMixedAmountOneLineWithoutCost, but show at most the given width,
|
-- | Like showMixedAmountOneLineWithoutCost, but show at most the given width,
|
||||||
-- with an elision indicator if there are more.
|
-- with an elision indicator if there are more.
|
||||||
@ -1062,7 +1072,7 @@ showMixedAmountOneLineWithoutCost c = wbUnpack . showMixedAmountB oneLineFmt{dis
|
|||||||
--
|
--
|
||||||
-- > showMixedAmountElided w c = wbUnpack . showMixedAmountB oneLineFmt{displayColour=c, displayMaxWidth=Just w}
|
-- > showMixedAmountElided w c = wbUnpack . showMixedAmountB oneLineFmt{displayColour=c, displayMaxWidth=Just w}
|
||||||
showMixedAmountElided :: Int -> Bool -> MixedAmount -> String
|
showMixedAmountElided :: Int -> Bool -> MixedAmount -> String
|
||||||
showMixedAmountElided w c = wbUnpack . showMixedAmountB oneLineFmt{displayColour=c, displayMaxWidth=Just w}
|
showMixedAmountElided w c = wbUnpack . showMixedAmountB oneLineNoCostFmt{displayColour=c, displayMaxWidth=Just w}
|
||||||
|
|
||||||
-- | Get an unambiguous string representation of a mixed amount for debugging.
|
-- | Get an unambiguous string representation of a mixed amount for debugging.
|
||||||
showMixedAmountDebug :: MixedAmount -> String
|
showMixedAmountDebug :: MixedAmount -> String
|
||||||
|
|||||||
@ -337,7 +337,7 @@ budgetReportAsTable
|
|||||||
rowfuncs :: [CommoditySymbol] -> (BudgetShowMixed, BudgetPercBudget)
|
rowfuncs :: [CommoditySymbol] -> (BudgetShowMixed, BudgetPercBudget)
|
||||||
rowfuncs cs = case layout_ of
|
rowfuncs cs = case layout_ of
|
||||||
LayoutWide width ->
|
LayoutWide width ->
|
||||||
( pure . showMixedAmountB oneLineFmt{displayMaxWidth=width, displayColour=color_}
|
( pure . showMixedAmountB oneLineNoCostFmt{displayMaxWidth=width, displayColour=color_}
|
||||||
, \a -> pure . percentage a)
|
, \a -> pure . percentage a)
|
||||||
_ -> ( showMixedAmountLinesB noCostFmt{displayCommodity=layout_/=LayoutBare, displayCommodityOrder=Just cs, displayMinWidth=Nothing, displayColour=color_}
|
_ -> ( showMixedAmountLinesB noCostFmt{displayCommodity=layout_/=LayoutBare, displayCommodityOrder=Just cs, displayMinWidth=Nothing, displayColour=color_}
|
||||||
, \a b -> fmap (percentage' a b) cs)
|
, \a b -> fmap (percentage' a b) cs)
|
||||||
@ -466,7 +466,7 @@ budgetReportAsCsv
|
|||||||
|
|
||||||
where
|
where
|
||||||
flattentuples tups = concat [[a,b] | (a,b) <- tups]
|
flattentuples tups = concat [[a,b] | (a,b) <- tups]
|
||||||
showNorm = maybe "" (wbToText . showMixedAmountB oneLineFmt)
|
showNorm = maybe "" (wbToText . showMixedAmountB oneLineNoCostFmt)
|
||||||
|
|
||||||
rowAsTexts :: (PeriodicReportRow a BudgetCell -> Text)
|
rowAsTexts :: (PeriodicReportRow a BudgetCell -> Text)
|
||||||
-> PeriodicReportRow a BudgetCell
|
-> PeriodicReportRow a BudgetCell
|
||||||
@ -480,7 +480,7 @@ budgetReportAsCsv
|
|||||||
$ vals
|
$ vals
|
||||||
where
|
where
|
||||||
cs = S.toList . foldl' S.union mempty . fmap maCommodities $ catMaybes vals
|
cs = S.toList . foldl' S.union mempty . fmap maCommodities $ catMaybes vals
|
||||||
dopts = oneLineFmt{displayCommodity=layout_ /= LayoutBare, displayCommodityOrder=Just cs, displayMinWidth=Nothing}
|
dopts = oneLineNoCostFmt{displayCommodity=layout_ /= LayoutBare, displayCommodityOrder=Just cs, displayMinWidth=Nothing}
|
||||||
vals = flattentuples as
|
vals = flattentuples as
|
||||||
++ concat [[rowtot, budgettot] | row_total_]
|
++ concat [[rowtot, budgettot] | row_total_]
|
||||||
++ concat [[rowavg, budgetavg] | average_]
|
++ concat [[rowavg, budgetavg] | average_]
|
||||||
|
|||||||
@ -80,7 +80,7 @@ asDrawHelper UIState{aScreen=scr, aopts=uopts, ajournal=j, aMode=mode} ropts scr
|
|||||||
displayitems = ass ^. assList . listElementsL
|
displayitems = ass ^. assList . listElementsL
|
||||||
|
|
||||||
acctwidths = V.map (\AccountsScreenItem{..} -> asItemIndentLevel + realLength asItemDisplayAccountName) displayitems
|
acctwidths = V.map (\AccountsScreenItem{..} -> asItemIndentLevel + realLength asItemDisplayAccountName) displayitems
|
||||||
balwidths = V.map (maybe 0 (wbWidth . showMixedAmountB oneLineFmt) . asItemMixedAmount) displayitems
|
balwidths = V.map (maybe 0 (wbWidth . showMixedAmountB oneLineNoCostFmt) . asItemMixedAmount) displayitems
|
||||||
preferredacctwidth = V.maximum acctwidths
|
preferredacctwidth = V.maximum acctwidths
|
||||||
totalacctwidthseen = V.sum acctwidths
|
totalacctwidthseen = V.sum acctwidths
|
||||||
preferredbalwidth = V.maximum balwidths
|
preferredbalwidth = V.maximum balwidths
|
||||||
@ -169,7 +169,7 @@ asDrawItem (acctwidth, balwidth) selected AccountsScreenItem{..} =
|
|||||||
splitAmounts balBuilder
|
splitAmounts balBuilder
|
||||||
where
|
where
|
||||||
balBuilder = maybe mempty showamt asItemMixedAmount
|
balBuilder = maybe mempty showamt asItemMixedAmount
|
||||||
showamt = showMixedAmountB oneLineFmt{displayMinWidth=Just balwidth, displayMaxWidth=Just balwidth}
|
showamt = showMixedAmountB oneLineNoCostFmt{displayMinWidth=Just balwidth, displayMaxWidth=Just balwidth}
|
||||||
balspace = T.replicate (2 + balwidth - wbWidth balBuilder) " "
|
balspace = T.replicate (2 + balwidth - wbWidth balBuilder) " "
|
||||||
splitAmounts = foldr1 (<+>) . intersperse (str ", ") . map renderamt . T.splitOn ", " . wbToText
|
splitAmounts = foldr1 (<+>) . intersperse (str ", ") . map renderamt . T.splitOn ", " . wbToText
|
||||||
renderamt :: T.Text -> Widget Name
|
renderamt :: T.Text -> Widget Name
|
||||||
|
|||||||
@ -291,7 +291,7 @@ rsUpdate uopts d j rss@RSS{_rssAccount, _rssForceInclusive, _rssList=oldlist} =
|
|||||||
,rsItemTransaction = t
|
,rsItemTransaction = t
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
showamt = showMixedAmountB oneLineFmt{displayMaxWidth=Just 3}
|
showamt = showMixedAmountB oneLineNoCostFmt{displayMaxWidth=Just 3}
|
||||||
wd = whichDate ropts'
|
wd = whichDate ropts'
|
||||||
|
|
||||||
-- blank items are added to allow more control of scroll position; we won't allow movement over these.
|
-- blank items are added to allow more control of scroll position; we won't allow movement over these.
|
||||||
|
|||||||
@ -110,7 +110,7 @@ registerChartHtml q title percommoditytxnreports = $(hamletFile "templates/chart
|
|||||||
colorForCommodity = fromMaybe 0 . flip lookup commoditiesIndex
|
colorForCommodity = fromMaybe 0 . flip lookup commoditiesIndex
|
||||||
commoditiesIndex = zip (map fst percommoditytxnreports) [0..] :: [(CommoditySymbol,Int)]
|
commoditiesIndex = zip (map fst percommoditytxnreports) [0..] :: [(CommoditySymbol,Int)]
|
||||||
simpleMixedAmountQuantity = maybe 0 aquantity . listToMaybe . amounts . mixedAmountStripCosts
|
simpleMixedAmountQuantity = maybe 0 aquantity . listToMaybe . amounts . mixedAmountStripCosts
|
||||||
showZeroCommodity = wbUnpack . showMixedAmountB oneLineFmt{displayCost=False,displayZeroCommodity=True}
|
showZeroCommodity = wbUnpack . showMixedAmountB oneLineNoCostFmt{displayCost=False,displayZeroCommodity=True}
|
||||||
shownull c = if null c then " " else c
|
shownull c = if null c then " " else c
|
||||||
nodatelink = (RegisterR, [("q", T.unwords $ removeDates q)])
|
nodatelink = (RegisterR, [("q", T.unwords $ removeDates q)])
|
||||||
|
|
||||||
|
|||||||
@ -148,9 +148,9 @@ htmlRow CliOpts{reportspec_=ReportSpec{_rsReportOpts=ropts}} reportq thisacctq
|
|||||||
L.tr_ (do (L.td_ . toHtml . show . transactionRegisterDate (whichDate ropts) reportq thisacctq) t
|
L.tr_ (do (L.td_ . toHtml . show . transactionRegisterDate (whichDate ropts) reportq thisacctq) t
|
||||||
(L.td_ . toHtml) tdescription
|
(L.td_ . toHtml) tdescription
|
||||||
(L.td_ . toHtml) otheracctsstr
|
(L.td_ . toHtml) otheracctsstr
|
||||||
-- piggy back on the oneLineFmt display style for now.
|
-- piggy back on the oneLineNoCostFmt display style for now.
|
||||||
(L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineFmt) amt
|
(L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineNoCostFmt) amt
|
||||||
(L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineFmt) bal)
|
(L.td_ . toHtml . wbUnpack . showMixedAmountB oneLineNoCostFmt) bal)
|
||||||
|
|
||||||
-- | Render a register report as plain text suitable for console output.
|
-- | Render a register report as plain text suitable for console output.
|
||||||
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
||||||
|
|||||||
@ -470,7 +470,7 @@ balanceReportAsText' opts ((items, total)) =
|
|||||||
[ Cell TopRight damts
|
[ Cell TopRight damts
|
||||||
, Cell TopLeft (fmap wbFromText cs)
|
, Cell TopLeft (fmap wbFromText cs)
|
||||||
, Cell TopLeft (replicate (length damts - 1) mempty ++ [wbFromText dispname]) ]
|
, Cell TopLeft (replicate (length damts - 1) mempty ++ [wbFromText dispname]) ]
|
||||||
where dopts = oneLineFmt{displayCommodity=layout_ opts /= LayoutBare, displayCommodityOrder=Just cs, displayColour=color_ opts}
|
where dopts = oneLineNoCostFmt{displayCommodity=layout_ opts /= LayoutBare, displayCommodityOrder=Just cs, displayColour=color_ opts}
|
||||||
cs = if mixedAmountLooksZero amt then [""] else S.toList $ maCommodities amt
|
cs = if mixedAmountLooksZero amt then [""] else S.toList $ maCommodities amt
|
||||||
dispname = T.replicate ((dep - 1) * 2) " " <> acctname
|
dispname = T.replicate ((dep - 1) * 2) " " <> acctname
|
||||||
damts = showMixedAmountLinesB dopts amt
|
damts = showMixedAmountLinesB dopts amt
|
||||||
@ -781,7 +781,7 @@ multiBalanceRowAsCsvText :: ReportOpts -> [DateSpan] -> PeriodicReportRow a Mixe
|
|||||||
multiBalanceRowAsCsvText opts colspans = fmap (fmap wbToText) . multiBalanceRowAsWbs machineFmt opts colspans
|
multiBalanceRowAsCsvText opts colspans = fmap (fmap wbToText) . multiBalanceRowAsWbs machineFmt opts colspans
|
||||||
|
|
||||||
multiBalanceRowAsTableText :: ReportOpts -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
|
multiBalanceRowAsTableText :: ReportOpts -> PeriodicReportRow a MixedAmount -> [[WideBuilder]]
|
||||||
multiBalanceRowAsTableText opts = multiBalanceRowAsWbs oneLineFmt{displayColour=color_ opts} opts []
|
multiBalanceRowAsTableText opts = multiBalanceRowAsWbs oneLineNoCostFmt{displayColour=color_ opts} opts []
|
||||||
|
|
||||||
tests_Balance = testGroup "Balance" [
|
tests_Balance = testGroup "Balance" [
|
||||||
|
|
||||||
|
|||||||
@ -282,7 +282,7 @@ postingsOrTransactionsReportAsText alignAll opts itemAsText itemamt itembal repo
|
|||||||
startAlign = (if alignAll then id else take chunkSize) itemsWithAmounts
|
startAlign = (if alignAll then id else take chunkSize) itemsWithAmounts
|
||||||
|
|
||||||
itemsWithAmounts = map (\x -> (x, showAmt $ itemamt x, showAmt $ itembal x)) report
|
itemsWithAmounts = map (\x -> (x, showAmt $ itemamt x, showAmt $ itembal x)) report
|
||||||
showAmt = showMixedAmountLinesB oneLineFmt{displayColour=opts^.color__}
|
showAmt = showMixedAmountLinesB oneLineNoCostFmt{displayColour=opts^.color__}
|
||||||
amt = second3
|
amt = second3
|
||||||
bal = third3
|
bal = third3
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user