mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-07 21:15:19 +03:00
add: don't let number style disturb the default (Fixes #1378)
This commit is contained in:
parent
e8672c4cd5
commit
0ce9c352ec
@ -69,6 +69,7 @@ module Hledger.Data.Amount (
|
||||
amountstyle,
|
||||
styleAmount,
|
||||
styleAmountExceptPrecision,
|
||||
amountUnstyled,
|
||||
showAmount,
|
||||
cshowAmount,
|
||||
showAmountWithZeroCommodity,
|
||||
@ -108,6 +109,7 @@ module Hledger.Data.Amount (
|
||||
mixedAmountTotalPriceToUnitPrice,
|
||||
-- ** rendering
|
||||
styleMixedAmount,
|
||||
mixedAmountUnstyled,
|
||||
showMixedAmount,
|
||||
showMixedAmountOneLine,
|
||||
showMixedAmountDebug,
|
||||
@ -351,6 +353,10 @@ styleAmountExceptPrecision styles a@Amount{astyle=AmountStyle{asprecision=origp}
|
||||
Just s -> a{astyle=s{asprecision=origp}}
|
||||
Nothing -> a
|
||||
|
||||
-- | Reset this amount's display style to the default.
|
||||
amountUnstyled :: Amount -> Amount
|
||||
amountUnstyled a = a{astyle=amountstyle}
|
||||
|
||||
-- | Get the string representation of an amount, based on its
|
||||
-- commodity's display settings. String representations equivalent to
|
||||
-- zero are converted to just \"0\". The special "missing" amount is
|
||||
@ -609,6 +615,10 @@ mixedAmountIsZero = all amountIsZero . amounts . normaliseMixedAmountSquashPrice
|
||||
styleMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
||||
styleMixedAmount styles (Mixed as) = Mixed $ map (styleAmount styles) as
|
||||
|
||||
-- | Reset each individual amount's display style to the default.
|
||||
mixedAmountUnstyled :: MixedAmount -> MixedAmount
|
||||
mixedAmountUnstyled = mapMixedAmount amountUnstyled
|
||||
|
||||
-- | Get the string representation of a mixed amount, after
|
||||
-- normalising it to one amount per commodity. Assumes amounts have
|
||||
-- no or similar prices, otherwise this can show misleading prices.
|
||||
|
@ -333,8 +333,12 @@ amountAndCommentWizard PrevInput{..} EntryState{..} = do
|
||||
(mhistoricalp,followedhistoricalsofar) =
|
||||
case esSimilarTransaction of
|
||||
Nothing -> (Nothing,False)
|
||||
Just Transaction{tpostings=ps} -> (if length ps >= pnum then Just (ps !! (pnum-1)) else Nothing
|
||||
,all (\(a,b) -> pamount a == pamount b) $ zip esPostings ps)
|
||||
Just Transaction{tpostings=ps} ->
|
||||
( if length ps >= pnum then Just (ps !! (pnum-1)) else Nothing
|
||||
, all sameamount $ zip esPostings ps
|
||||
)
|
||||
where
|
||||
sameamount (p1,p2) = mixedAmountUnstyled (pamount p1) == mixedAmountUnstyled (pamount p2)
|
||||
def = case (esArgs, mhistoricalp, followedhistoricalsofar) of
|
||||
(d:_,_,_) -> d
|
||||
(_,Just hp,True) -> showamt $ pamount hp
|
||||
@ -343,7 +347,8 @@ amountAndCommentWizard PrevInput{..} EntryState{..} = do
|
||||
retryMsg "A valid hledger amount is required. Eg: 1, $2, 3 EUR, \"4 red apples\"." $
|
||||
parser parseAmountAndComment $
|
||||
withCompletion (amountCompleter def) $
|
||||
defaultTo' def $ nonEmpty $
|
||||
defaultTo' def $
|
||||
nonEmpty $
|
||||
linePrewritten (green $ printf "Amount %d%s: " pnum (showDefault def)) (fromMaybe "" $ prevAmountAndCmnt `atMay` length esPostings) ""
|
||||
where
|
||||
parseAmountAndComment s = if s == "<" then return Nothing else either (const Nothing) (return . Just) $
|
||||
|
Loading…
Reference in New Issue
Block a user