summaryrefslogtreecommitdiff
path: root/src/Sequence/Utils/Ask.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Sequence/Utils/Ask.hs')
-rw-r--r--src/Sequence/Utils/Ask.hs27
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
3module Sequence.Utils.Ask
4 ( askQ, askBool
5 ) where
6
7import System.Console.Readline (readline)
8
9import Control.Monad.IO.Class
10import Control.Monad
11
12import Data.CaseInsensitive (CI)
13import qualified Data.CaseInsensitive as CI
14
15import Data.Maybe
16
17askBool :: MonadIO m => String -> Bool -> m Bool
18askBool 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
26askQ :: MonadIO m => String -> (Maybe String -> a) -> m a
27askQ prompt eval = eval <$> liftIO (readline $ prompt ++ " ")