lib: When displaying amounts on a single line, always display at least one amount, even if that would exceed the requested maximum width. Addresses #1526.

This commit is contained in:
Stephen Morgan 2021-04-14 11:15:54 +10:00 committed by Simon Michael
parent f5121129ec
commit 28fd7c65f2
2 changed files with 20 additions and 3 deletions

View File

@ -451,7 +451,9 @@ showAmountB opts a@Amount{astyle=style} =
--
-- If a maximum width is given then:
-- - If displayed on one line, it will display as many Amounts as can
-- fit in the given width, and further Amounts will be elided.
-- fit in the given width, and further Amounts will be elided. There
-- will always be at least one amount displayed, even if this will
-- exceed the requested maximum width.
-- - If displayed on multiple lines, any Amounts longer than the
-- maximum width will be elided.
showAmountsB :: AmountDisplayOpts -> [Amount] -> WideBuilder
@ -507,8 +509,10 @@ showAmountsOneLineB opts@AmountDisplayOpts{displayMaxWidth=mmax,displayMinWidth=
addElide [] = []
addElide xs = maybeAppend (snd $ last xs) $ map fst xs
-- Return the elements of the display list which fit within the maximum width
-- (including their elision strings)
takeFitting m = dropWhileRev (\(a,e) -> m < adTotal (fromMaybe a e))
-- (including their elision strings). Always display at least one amount,
-- regardless of width.
takeFitting _ [] = []
takeFitting m (x:xs) = x : dropWhileRev (\(a,e) -> m < adTotal (fromMaybe a e)) xs
dropWhileRev p = foldr (\x xs -> if null xs && p x then [] else x:xs) []
-- Add the elision strings (if any) to each amount

View File

@ -221,3 +221,16 @@ hledger bal -f -
b -,100.0 EUR
>>>
>>>=1
# 20. long numbers in multi balance reports
hledger bal -YN -f -
<<<
2021-01-01
(a) -0.12345678901234567890123456 EUR
>>>
Balance changes in 2021:
|| 2021
===++===================================
a || -0.12345678901234567890123456 EUR
>>>=0