diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index ec1cc4583..5b7ad2f06 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -714,8 +714,9 @@ showMixedOneLineUnnormalised showamt mmin mmax c (Mixed as) = 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 = filter (\(_,e) -> maybe True ((m>=) . adTotal) e) - . takeWhile (\(amt,_) -> adTotal amt <= m) + takeFitting m = dropWhileRev (\(a,e) -> m < adTotal (fromMaybe a e)) + dropWhileRev p = foldr (\x xs -> if null xs && p x then [] else x:xs) [] + -- Add the elision strings (if any) to each amount withElided = zipWith (\num amt -> (amt, elisionDisplay Nothing sepwidth num amt)) [n-1,n-2..0] diff --git a/tests/balance/multicommodity.test b/tests/balance/multicommodity.test index 486090608..0432780e0 100644 --- a/tests/balance/multicommodity.test +++ b/tests/balance/multicommodity.test @@ -26,3 +26,38 @@ Balance changes in 2020: a || 1.00A, 1.00B, 1.00C, 1.00D, 1.00E, 1.00F ---++------------------------------------------ || 1.00A, 1.00B, 1.00C, 1.00D, 1.00E, 1.00F + +< +2020-02-22 + 26018c6e:ced6cffd:c3c182f1:7b433efb $ 9.41 + ea50865f:3bfb86b7:bf72f75a:a7cad1ac $ -10.00 + ea50865f:325566ed:216fec7e:7b433efb $ 0.59 + +2020-02-27 + 26018c6e:ced6cffd:c3c182f1:7b433efb £ -19.16 + ea50865f:325566ed:216fec7e:7b433efb £ 0.91 + ea50865f:325566ed:47134948 £ 18.25 + +2020-04-12 + 26018c6e:ced6cffd:c3c182f1:7b433efb € 9.21 + ea50865f:3bfb86b7:bf72f75a:a7cad1ac € -10.00 + ea50865f:325566ed:216fec7e:7b433efb € 0.79 + +2020-05-16 + 26018c6e:ced6cffd:c3c182f1:7b433efb C$ 24.56 + ea50865f:3bfb86b7:bf72f75a:a7cad1ac C$ -26.00 + ea50865f:325566ed:216fec7e:7b433efb C$ 1.44 + +# 3. Make sure all amounts up to the largest fit +$ hledger -f- bal -Y --color=yes +Balance changes in 2020: + + || 2020 +=====================================++================================= + 26018c6e:ced6cffd:c3c182f1:7b433efb || $ 9.41, C$ 24.56, 2 more.. + ea50865f:325566ed:216fec7e:7b433efb || $ 0.59, C$ 1.44, £ 0.91, € 0.79 + ea50865f:325566ed:47134948 || £ 18.25 + ea50865f:3bfb86b7:bf72f75a:a7cad1ac || $ -10.00, C$ -26.00, € -10.00 +-------------------------------------++--------------------------------- + || 0 +>=0