lib: showAmountCost(B): drop leading whitespace

This commit is contained in:
Simon Michael 2025-01-15 16:05:39 -10:00
parent e98af39e27
commit edfcd3554f
3 changed files with 15 additions and 15 deletions

View File

@ -673,11 +673,11 @@ showAmountB
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
cost = if displayCost then showAmountCostB afmt a else mempty cost = if displayCost then showAmountCostB afmt a else mempty
-- Show an amount's cost as @ UNITCOST or @@ TOTALCOST. -- Show an amount's cost as @ UNITCOST or @@ TOTALCOST, plus a leading space, or "" if there's no cost.
showAmountCost :: Amount -> String showAmountCost :: Amount -> String
showAmountCost = wbUnpack . showAmountCostB defaultFmt showAmountCost = wbUnpack . showAmountCostB defaultFmt
-- Show an amount's cost as @ UNITCOST or @@ TOTALCOST (builder version). -- showAmountCost, efficient builder version.
showAmountCostB :: AmountFormat -> Amount -> WideBuilder showAmountCostB :: AmountFormat -> Amount -> WideBuilder
showAmountCostB afmt amt = case acost amt of showAmountCostB afmt amt = case acost amt of
Nothing -> mempty Nothing -> mempty
@ -687,8 +687,8 @@ showAmountCostB afmt amt = case acost amt of
showAmountCostDebug :: Maybe AmountCost -> String showAmountCostDebug :: Maybe AmountCost -> String
showAmountCostDebug Nothing = "" showAmountCostDebug Nothing = ""
showAmountCostDebug (Just (UnitCost pa)) = " @ " ++ showAmountDebug pa showAmountCostDebug (Just (UnitCost pa)) = "@ " ++ showAmountDebug pa
showAmountCostDebug (Just (TotalCost pa)) = " @@ " ++ showAmountDebug pa showAmountCostDebug (Just (TotalCost pa)) = "@@ " ++ showAmountDebug pa
-- | 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.

View File

@ -1178,7 +1178,7 @@ pivotComponent fieldortagname p
| fieldortagname == "acct" = paccount p | fieldortagname == "acct" = paccount p
| fieldortagname `elem` commnames = case map acommodity $ amounts $ pamount p of [s] -> s; _ -> unknown | fieldortagname `elem` commnames = case map acommodity $ amounts $ pamount p of [s] -> s; _ -> unknown
| fieldortagname == "amt" = case amounts $ pamount p of [a] -> T.pack $ show $ aquantity a; _ -> unknown | fieldortagname == "amt" = case amounts $ pamount p of [a] -> T.pack $ show $ aquantity a; _ -> unknown
| fieldortagname == "cost" = case amounts $ pamount p of [a@Amount{acost=Just _}] -> T.pack $ showAmountCost a; _ -> unknown | fieldortagname == "cost" = case amounts $ pamount p of [a@Amount{acost=Just _}] -> T.pack $ lstrip $ showAmountCost a; _ -> unknown
| Just (_, tagvalue) <- postingFindTag fieldortagname p = tagvalue | Just (_, tagvalue) <- postingFindTag fieldortagname p = tagvalue
| otherwise = unknown | otherwise = unknown
where where

View File

@ -201,9 +201,9 @@ $ hledger -f- bal -Y --pivot=cost
Balance changes in 2025: Balance changes in 2025:
|| 2025 || 2025
=========++================= ========++=================
|| $-210 || $-210
@ $10 || 1 A @ $10 || 1 A
@ $100 || 2 B @ $100 || 2 B
---------++----------------- --------++-----------------
|| $-210, 1 A, 2 B || $-210, 1 A, 2 B