diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index 9651541ba..042101240 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -150,14 +150,12 @@ amountstyle = AmountStyle L False 0 (Just '.') Nothing ------------------------------------------------------------------------------- -- Amount -instance Show Amount where - show _a@Amount{..} - -- debugLevel < 2 = showAmountWithoutPrice a - -- debugLevel < 3 = showAmount a - | debugLevel < 6 = - printf "Amount {acommodity=%s, aquantity=%s, ..}" (show acommodity) (show aquantity) - | otherwise = --showAmountDebug a - printf "Amount {acommodity=%s, aquantity=%s, aprice=%s, astyle=%s}" (show acommodity) (show aquantity) (showPriceDebug aprice) (show astyle) +instance Show Price where + show NoPrice = "NoPrice" + show (UnitPrice a) = "\"@ " ++ showAmountWithoutPrice a ++ "..\"" + show (TotalPrice a) = "\"@@ " ++ showAmountWithoutPrice a ++ "..\"" + +deriving instance Show Amount instance Num Amount where abs a@Amount{aquantity=q} = a{aquantity=abs q} diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index 73f472d2b..f6a9b67e9 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable, StandaloneDeriving, DeriveGeneric, TypeSynonymInstances, FlexibleInstances, OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} {-| Most data types are defined here to avoid import cycles. @@ -32,6 +33,7 @@ import Data.Text (Text) import Data.Time.Calendar import Data.Time.LocalTime import System.Time (ClockTime(..)) +import Text.Printf import Hledger.Utils.Regex @@ -137,10 +139,19 @@ data AmountStyle = AmountStyle { asprecision :: !Int, -- ^ number of digits displayed after the decimal point asdecimalpoint :: Maybe Char, -- ^ character used as decimal point: period or comma. Nothing means "unspecified, use default" asdigitgroups :: Maybe DigitGroupStyle -- ^ style for displaying digit groups, if any -} deriving (Eq,Ord,Read,Show,Typeable,Data,Generic) +} deriving (Eq,Ord,Read,Typeable,Data,Generic) instance NFData AmountStyle +instance Show AmountStyle where + show AmountStyle{..} = + printf "AmountStyle \"%s %s %s %s %s..\"" + (show ascommodityside) + (show ascommodityspaced) + (show asprecision) + (show asdecimalpoint) + (show asdigitgroups) + -- | A style for displaying digit groups in the integer part of a -- floating point number. It consists of the character used to -- separate groups (comma or period, whichever is not used as decimal