lib: redo buggy Amount refactoring
This commit is contained in:
parent
988510dde2
commit
968ae13035
@ -119,6 +119,7 @@ import Data.Time.Calendar (Day)
|
|||||||
import Data.Ord (comparing)
|
import Data.Ord (comparing)
|
||||||
-- import Data.Text (Text)
|
-- import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import Safe (maximumDef)
|
||||||
import Test.HUnit
|
import Test.HUnit
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
@ -599,28 +600,31 @@ showMixedAmountDebug m | m == missingmixedamt = "(missing)"
|
|||||||
| otherwise = printf "Mixed [%s]" as
|
| otherwise = printf "Mixed [%s]" as
|
||||||
where as = intercalate "\n " $ map showAmountDebug $ amounts m
|
where as = intercalate "\n " $ map showAmountDebug $ amounts m
|
||||||
|
|
||||||
-- | Get the string representation of a mixed amount, but without any \@ prices.
|
-- TODO these and related fns are comically complicated:
|
||||||
|
|
||||||
|
-- | Get the string representation of a mixed amount, without showing any transaction prices.
|
||||||
showMixedAmountWithoutPrice :: MixedAmount -> String
|
showMixedAmountWithoutPrice :: MixedAmount -> String
|
||||||
showMixedAmountWithoutPrice m@(Mixed as) = showMixedAmountWithoutPriceHelper showamt m
|
showMixedAmountWithoutPrice m = intercalate "\n" $ map showamt as
|
||||||
where
|
where
|
||||||
width = maximum $ map (length . showAmount) as
|
Mixed as = normaliseMixedAmountSquashPricesForDisplay $ mixedAmountStripPrices m
|
||||||
showamt = printf (printf "%%%ds" width) . showAmountWithoutPrice
|
showamt = printf (printf "%%%ds" width) . showAmountWithoutPrice
|
||||||
|
where
|
||||||
|
width = maximumDef 0 $ map (length . showAmount) as
|
||||||
|
|
||||||
-- | Colour version of showMixedAmountWithoutPrice, adds ANSI codes to show
|
-- | Colour version of showMixedAmountWithoutPrice. Any individual Amount
|
||||||
-- any negative Amounts in red.
|
-- which is negative is wrapped in ANSI codes to make it display in red.
|
||||||
cshowMixedAmountWithoutPrice :: MixedAmount -> String
|
cshowMixedAmountWithoutPrice :: MixedAmount -> String
|
||||||
cshowMixedAmountWithoutPrice m@(Mixed as) = showMixedAmountWithoutPriceHelper showamt m
|
cshowMixedAmountWithoutPrice m = intercalate "\n" $ map showamt as
|
||||||
where
|
where
|
||||||
width = maximum $ map (length . showAmount) as
|
Mixed as = normaliseMixedAmountSquashPricesForDisplay $ mixedAmountStripPrices m
|
||||||
showamt a =
|
showamt a =
|
||||||
(if isNegativeAmount a then color Dull Red else id) $
|
(if isNegativeAmount a then color Dull Red else id) $
|
||||||
printf (printf "%%%ds" width) $ showAmountWithoutPrice a
|
printf (printf "%%%ds" width) $ showAmountWithoutPrice a
|
||||||
|
where
|
||||||
|
width = maximumDef 0 $ map (length . showAmount) as
|
||||||
|
|
||||||
showMixedAmountWithoutPriceHelper :: (Amount -> String) -> MixedAmount -> String
|
mixedAmountStripPrices :: MixedAmount -> MixedAmount
|
||||||
showMixedAmountWithoutPriceHelper showfn m = intercalate "\n" $ map showfn as
|
mixedAmountStripPrices (Mixed as) = Mixed $ map (\a -> a{aprice=NoPrice}) as
|
||||||
where
|
|
||||||
(Mixed as) = normaliseMixedAmountSquashPricesForDisplay $ stripPrices m
|
|
||||||
stripPrices (Mixed as) = Mixed $ map stripprice as where stripprice a = a{aprice=NoPrice}
|
|
||||||
|
|
||||||
-- | Get the one-line string representation of a mixed amount, but without
|
-- | Get the one-line string representation of a mixed amount, but without
|
||||||
-- any \@ prices.
|
-- any \@ prices.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user