dev: showAmountPrice -> showAmountCostB, showAmountPriceDebug -> showAmountCostDebug

This commit is contained in:
Simon Michael 2024-01-23 07:10:20 -10:00
parent 2ac0905c70
commit 0353840d90

View File

@ -85,7 +85,7 @@ module Hledger.Data.Amount (
csvDisplay, csvDisplay,
showAmountB, showAmountB,
showAmount, showAmount,
showAmountPrice, showAmountCostB,
cshowAmount, cshowAmount,
showAmountWithZeroCommodity, showAmountWithZeroCommodity,
showAmountDebug, showAmountDebug,
@ -617,17 +617,17 @@ withDecimalPoint = flip setAmountDecimalPoint
amountStripPrices :: Amount -> Amount amountStripPrices :: Amount -> Amount
amountStripPrices a = a{aprice=Nothing} amountStripPrices a = a{aprice=Nothing}
showAmountPrice :: Amount -> WideBuilder showAmountCostB :: Amount -> WideBuilder
showAmountPrice amt = case aprice amt of showAmountCostB amt = case aprice amt of
Nothing -> mempty Nothing -> mempty
Just (UnitPrice pa) -> WideBuilder (TB.fromString " @ ") 3 <> showAmountB noColour{displayZeroCommodity=True} pa Just (UnitPrice pa) -> WideBuilder (TB.fromString " @ ") 3 <> showAmountB noColour{displayZeroCommodity=True} pa
Just (TotalPrice pa) -> WideBuilder (TB.fromString " @@ ") 4 <> showAmountB noColour{displayZeroCommodity=True} (sign pa) Just (TotalPrice pa) -> WideBuilder (TB.fromString " @@ ") 4 <> showAmountB noColour{displayZeroCommodity=True} (sign pa)
where sign = if aquantity amt < 0 then negate else id where sign = if aquantity amt < 0 then negate else id
showAmountPriceDebug :: Maybe AmountPrice -> String showAmountCostDebug :: Maybe AmountPrice -> String
showAmountPriceDebug Nothing = "" showAmountCostDebug Nothing = ""
showAmountPriceDebug (Just (UnitPrice pa)) = " @ " ++ showAmountDebug pa showAmountCostDebug (Just (UnitPrice pa)) = " @ " ++ showAmountDebug pa
showAmountPriceDebug (Just (TotalPrice pa)) = " @@ " ++ showAmountDebug pa showAmountCostDebug (Just (TotalPrice pa)) = " @@ " ++ showAmountDebug pa
-- | Get the string representation of an amount, based on its -- | Get the string representation of an amount, based on its
-- commodity's display settings. String representations equivalent to -- commodity's display settings. String representations equivalent to
@ -667,7 +667,7 @@ showAmountB
| amountLooksZero a && not displayZeroCommodity = (WideBuilder (TB.singleton '0') 1, "") | amountLooksZero a && not displayZeroCommodity = (WideBuilder (TB.singleton '0') 1, "")
| otherwise = (quantity, quoteCommoditySymbolIfNeeded $ acommodity a) | otherwise = (quantity, quoteCommoditySymbolIfNeeded $ acommodity a)
space = if not (T.null comm) && ascommodityspaced style then WideBuilder (TB.singleton ' ') 1 else mempty space = if not (T.null comm) && ascommodityspaced style then WideBuilder (TB.singleton ' ') 1 else mempty
price = if displayCost then showAmountPrice a else mempty price = if displayCost then showAmountCostB a else mempty
-- | Colour version. For a negative amount, adds ANSI codes to change the colour, -- | Colour version. For a negative amount, adds ANSI codes to change the colour,
-- currently to hard-coded red. -- currently to hard-coded red.
@ -694,7 +694,7 @@ showAmountDebug :: Amount -> String
showAmountDebug Amount{acommodity="AUTO"} = "(missing)" showAmountDebug Amount{acommodity="AUTO"} = "(missing)"
showAmountDebug Amount{..} = showAmountDebug Amount{..} =
"Amount {acommodity=" ++ show acommodity ++ ", aquantity=" ++ show aquantity "Amount {acommodity=" ++ show acommodity ++ ", aquantity=" ++ show aquantity
++ ", aprice=" ++ showAmountPriceDebug aprice ++ ", astyle=" ++ show astyle ++ "}" ++ ", aprice=" ++ showAmountCostDebug aprice ++ ", astyle=" ++ show astyle ++ "}"
-- | Get a Text Builder for the string representation of the number part of of an amount, -- | Get a Text Builder for the string representation of the number part of of an amount,
-- using the display settings from its commodity. Also returns the width of the number. -- using the display settings from its commodity. Also returns the width of the number.