Finish the "add" command after an end-of-file.
This commit is contained in:
parent
17d5acf64b
commit
bb43c2c750
@ -28,6 +28,7 @@ import Control.Monad.Trans (liftIO)
|
|||||||
import System.Console.Haskeline.Completion
|
import System.Console.Haskeline.Completion
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import Safe (headMay)
|
import Safe (headMay)
|
||||||
|
import Control.Exception (throw)
|
||||||
|
|
||||||
|
|
||||||
-- | Read transactions from the terminal, prompting for each field,
|
-- | Read transactions from the terminal, prompting for each field,
|
||||||
@ -151,7 +152,7 @@ getPostings ctx accept historicalps enteredps = do
|
|||||||
-- input is valid. May also raise an EOF exception if control-d is pressed.
|
-- input is valid. May also raise an EOF exception if control-d is pressed.
|
||||||
askFor :: String -> Maybe String -> Maybe (String -> Bool) -> InputT IO String
|
askFor :: String -> Maybe String -> Maybe (String -> Bool) -> InputT IO String
|
||||||
askFor prompt def validator = do
|
askFor prompt def validator = do
|
||||||
l <- fmap (maybe "" id)
|
l <- fmap (maybe eofErr id)
|
||||||
$ getInputLine $ prompt ++ maybe "" showdef def ++ ": "
|
$ getInputLine $ prompt ++ maybe "" showdef def ++ ": "
|
||||||
let input = if null l then fromMaybe l def else l
|
let input = if null l then fromMaybe l def else l
|
||||||
case validator of
|
case validator of
|
||||||
@ -159,7 +160,9 @@ askFor prompt def validator = do
|
|||||||
then return input
|
then return input
|
||||||
else askFor prompt def validator
|
else askFor prompt def validator
|
||||||
Nothing -> return input
|
Nothing -> return input
|
||||||
where showdef s = " [" ++ s ++ "]"
|
where
|
||||||
|
showdef s = " [" ++ s ++ "]"
|
||||||
|
eofErr = throw $ mkIOError eofErrorType "end of input" Nothing Nothing
|
||||||
|
|
||||||
-- | Append this transaction to the journal's file, and to the journal's
|
-- | Append this transaction to the journal's file, and to the journal's
|
||||||
-- transaction list.
|
-- transaction list.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user