add: clarify runInteraction*
This commit is contained in:
		
							parent
							
								
									431ef894e0
								
							
						
					
					
						commit
						f34d3aa9d6
					
				@ -86,7 +86,7 @@ getTransaction j opts defdate moredefs = do
 | 
				
			|||||||
    Nothing -> restart
 | 
					    Nothing -> restart
 | 
				
			||||||
    Just t  -> do
 | 
					    Just t  -> do
 | 
				
			||||||
      hPrintf stderr "\nTransaction entered:\n%s" (show t)
 | 
					      hPrintf stderr "\nTransaction entered:\n%s" (show t)
 | 
				
			||||||
      yn <- runInteractionDefault $ askFor "Accept this transaction" (Just "y") (Just $ \s -> map toLower s `elem` ["<","y","yes","n","no"])
 | 
					      yn <- runInteraction $ askFor "Accept this transaction" (Just "y") (Just $ \s -> map toLower s `elem` ["<","y","yes","n","no"])
 | 
				
			||||||
      case headMay $ map toLower yn of
 | 
					      case headMay $ map toLower yn of
 | 
				
			||||||
        Just 'y' -> return t
 | 
					        Just 'y' -> return t
 | 
				
			||||||
        _        -> restart
 | 
					        _        -> restart
 | 
				
			||||||
@ -97,7 +97,7 @@ getTransaction j opts defdate moredefs = do
 | 
				
			|||||||
getTransactionOrRestart :: Journal -> CliOpts -> String -> [String] -> IO (Maybe Transaction)
 | 
					getTransactionOrRestart :: Journal -> CliOpts -> String -> [String] -> IO (Maybe Transaction)
 | 
				
			||||||
getTransactionOrRestart j opts defdate moredefs = do
 | 
					getTransactionOrRestart j opts defdate moredefs = do
 | 
				
			||||||
  let dateandcodep = do {d <- smartdate; c <- optionMaybe codep; many spacenonewline; eof; return (d, fromMaybe "" c)}
 | 
					  let dateandcodep = do {d <- smartdate; c <- optionMaybe codep; many spacenonewline; eof; return (d, fromMaybe "" c)}
 | 
				
			||||||
  datecodestr <- runInteractionDefault $ askFor "date"
 | 
					  datecodestr <- runInteraction $ askFor "date"
 | 
				
			||||||
            (Just defdate)
 | 
					            (Just defdate)
 | 
				
			||||||
            (Just $ \s -> null s
 | 
					            (Just $ \s -> null s
 | 
				
			||||||
                         || s == "."
 | 
					                         || s == "."
 | 
				
			||||||
@ -109,7 +109,7 @@ getTransactionOrRestart j opts defdate moredefs = do
 | 
				
			|||||||
      datestr = showDate $ fixSmartDate defday sdate
 | 
					      datestr = showDate $ fixSmartDate defday sdate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let (defdesc, moredefs') = headTailDef "" moredefs
 | 
					  let (defdesc, moredefs') = headTailDef "" moredefs
 | 
				
			||||||
  desc <- runInteractionDefault $ askFor "description" (Just defdesc) Nothing
 | 
					  desc <- runInteraction $ askFor "description" (Just defdesc) Nothing
 | 
				
			||||||
  if desc == "<"
 | 
					  if desc == "<"
 | 
				
			||||||
   then return Nothing
 | 
					   then return Nothing
 | 
				
			||||||
   else do
 | 
					   else do
 | 
				
			||||||
@ -172,7 +172,7 @@ getPostingsLoop st enteredps defargs = do
 | 
				
			|||||||
      defargs' = tailDef [] defargs
 | 
					      defargs' = tailDef [] defargs
 | 
				
			||||||
      ordot | null enteredps || length enteredrealps == 1 = "" :: String
 | 
					      ordot | null enteredps || length enteredrealps == 1 = "" :: String
 | 
				
			||||||
            | otherwise = " (or . to complete this transaction)"
 | 
					            | otherwise = " (or . to complete this transaction)"
 | 
				
			||||||
  account <- runInteraction j $ askFor (printf "account %d%s" n ordot) defacct (Just accept)
 | 
					  account <- runInteractionWithAccountCompletion j $ askFor (printf "account %d%s" n ordot) defacct (Just accept)
 | 
				
			||||||
  when (account=="<") $ throwIO RestartEntryException
 | 
					  when (account=="<") $ throwIO RestartEntryException
 | 
				
			||||||
  if account=="."
 | 
					  if account=="."
 | 
				
			||||||
    then
 | 
					    then
 | 
				
			||||||
@ -204,7 +204,7 @@ getPostingsLoop st enteredps defargs = do
 | 
				
			|||||||
                -- I think 1 or 4, whichever would show the most decimal places
 | 
					                -- I think 1 or 4, whichever would show the most decimal places
 | 
				
			||||||
                p = maxprecisionwithpoint
 | 
					                p = maxprecisionwithpoint
 | 
				
			||||||
          defargs'' = tailDef [] defargs'
 | 
					          defargs'' = tailDef [] defargs'
 | 
				
			||||||
      amt <- runInteractionDefault $ askFor (printf "amount  %d" n) defamountstr validateamount
 | 
					      amt <- runInteraction $ askFor (printf "amount  %d" n) defamountstr validateamount
 | 
				
			||||||
      when (amt=="<") $ throwIO RestartEntryException
 | 
					      when (amt=="<") $ throwIO RestartEntryException
 | 
				
			||||||
      let (amountstr,comment) = (strip a, strip $ dropWhile (==';') b) where (a,b) = break (==';') amt
 | 
					      let (amountstr,comment) = (strip a, strip $ dropWhile (==';') b) where (a,b) = break (==';') amt
 | 
				
			||||||
      let a  = fromparse $ runParser (amountp <|> return missingamt) ctx     "" amountstr
 | 
					      let a  = fromparse $ runParser (amountp <|> return missingamt) ctx     "" amountstr
 | 
				
			||||||
@ -327,15 +327,15 @@ transactionsSimilarTo j q s =
 | 
				
			|||||||
      ts = filter (q `matchesTransaction`) $ jtxns j
 | 
					      ts = filter (q `matchesTransaction`) $ jtxns j
 | 
				
			||||||
      threshold = 0
 | 
					      threshold = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
runInteraction :: Journal -> InputT IO a -> IO a
 | 
					runInteraction :: InputT IO a -> IO a
 | 
				
			||||||
runInteraction j m = do
 | 
					runInteraction m = do
 | 
				
			||||||
 | 
					    runInputT (setComplete noCompletion defaultSettings) m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					runInteractionWithAccountCompletion :: Journal -> InputT IO a -> IO a
 | 
				
			||||||
 | 
					runInteractionWithAccountCompletion j m = do
 | 
				
			||||||
    let cc = completionCache j
 | 
					    let cc = completionCache j
 | 
				
			||||||
    runInputT (setComplete (accountCompletion cc) defaultSettings) m
 | 
					    runInputT (setComplete (accountCompletion cc) defaultSettings) m
 | 
				
			||||||
 | 
					
 | 
				
			||||||
runInteractionDefault :: InputT IO a -> IO a
 | 
					 | 
				
			||||||
runInteractionDefault m = do
 | 
					 | 
				
			||||||
    runInputT (setComplete noCompletion defaultSettings) m
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
-- A precomputed list of all accounts previously entered into the journal.
 | 
					-- A precomputed list of all accounts previously entered into the journal.
 | 
				
			||||||
type CompletionCache = [AccountName]
 | 
					type CompletionCache = [AccountName]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user