From cbdbe0a8554ce089ea982c7e408006eefc25bf5b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 7 Nov 2024 01:16:34 -1000 Subject: [PATCH] dev: AmountFormat: add displayQuotes property to control enclosing quotes --- hledger-lib/Hledger/Data/Amount.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index db7b2a0c698..33984bb930b 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -242,6 +242,7 @@ data AmountFormat = AmountFormat , displayMaxWidth :: Maybe Int -- ^ Maximum width to clip to , displayCost :: Bool -- ^ Whether to display Amounts' costs. , displayColour :: Bool -- ^ Whether to ansi-colourise negative Amounts. + , displayQuotes :: Bool -- ^ Whether to enclose complex symbols in quotes (normally true) } deriving (Show) -- | By default, display amounts using @defaultFmt@ amount display options. @@ -260,6 +261,7 @@ defaultFmt = AmountFormat { , displayMaxWidth = Nothing , displayCost = True , displayColour = False + , displayQuotes = True } -- | Like defaultFmt but show zero amounts with commodity symbol and styling, like non-zero amounts. @@ -655,7 +657,7 @@ showAmountB :: AmountFormat -> Amount -> WideBuilder showAmountB _ Amount{acommodity="AUTO"} = mempty showAmountB afmt@AmountFormat{displayCommodity, displayZeroCommodity, displayDigitGroups - ,displayForceDecimalMark, displayCost, displayColour} + ,displayForceDecimalMark, displayCost, displayColour, displayQuotes} a@Amount{astyle=style} = color $ case ascommodityside style of L -> (if displayCommodity then wbFromText comm <> space else mempty) <> quantity' <> cost @@ -666,7 +668,7 @@ showAmountB if displayDigitGroups then a else a{astyle=(astyle a){asdigitgroups=Nothing}} (quantity', comm) | amountLooksZero a && not displayZeroCommodity = (WideBuilder (TB.singleton '0') 1, "") - | otherwise = (quantity, quoteCommoditySymbolIfNeeded $ acommodity a) + | otherwise = (quantity, (if displayQuotes then quoteCommoditySymbolIfNeeded else id) $ acommodity a) space = if not (T.null comm) && ascommodityspaced style then WideBuilder (TB.singleton ' ') 1 else mempty cost = if displayCost then showAmountCostB afmt a else mempty