diff options
Diffstat (limited to 'src/Sequence/Utils')
-rw-r--r-- | src/Sequence/Utils/Ask.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Sequence/Utils/Ask.hs b/src/Sequence/Utils/Ask.hs new file mode 100644 index 0000000..8020656 --- /dev/null +++ b/src/Sequence/Utils/Ask.hs | |||
@@ -0,0 +1,27 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | |||
3 | module Sequence.Utils.Ask | ||
4 | ( askQ, askBool | ||
5 | ) where | ||
6 | |||
7 | import System.Console.Readline (readline) | ||
8 | |||
9 | import Control.Monad.IO.Class | ||
10 | import Control.Monad | ||
11 | |||
12 | import Data.CaseInsensitive (CI) | ||
13 | import qualified Data.CaseInsensitive as CI | ||
14 | |||
15 | import Data.Maybe | ||
16 | |||
17 | askBool :: MonadIO m => String -> Bool -> m Bool | ||
18 | askBool prompt initial = askQ prompt $ fromMaybe initial . join . fmap (eval . CI.mk) | ||
19 | where | ||
20 | eval "yes" = Just True | ||
21 | eval "y" = Just True | ||
22 | eval "no" = Just False | ||
23 | eval "n" = Just False | ||
24 | eval _ = Nothing | ||
25 | |||
26 | askQ :: MonadIO m => String -> (Maybe String -> a) -> m a | ||
27 | askQ prompt eval = eval <$> liftIO (readline $ prompt ++ " ") | ||