diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-03 22:09:01 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-06-03 22:09:01 +0200 |
commit | cfb7be14aebffd68ca357d7c6ef15e1c0974a156 (patch) | |
tree | 7448ef0ee0fa4049903efabf2fe7abf8eb7940b3 /src/Sequence/Utils | |
parent | a98cd5d87a0c7959146a8ca35aa40f42fc146ad8 (diff) | |
download | 2017-01-16_17:13:37-cfb7be14aebffd68ca357d7c6ef15e1c0974a156.tar 2017-01-16_17:13:37-cfb7be14aebffd68ca357d7c6ef15e1c0974a156.tar.gz 2017-01-16_17:13:37-cfb7be14aebffd68ca357d7c6ef15e1c0974a156.tar.bz2 2017-01-16_17:13:37-cfb7be14aebffd68ca357d7c6ef15e1c0974a156.tar.xz 2017-01-16_17:13:37-cfb7be14aebffd68ca357d7c6ef15e1c0974a156.zip |
cleanup & stumped on variadic val
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 ++ " ") | ||