summaryrefslogtreecommitdiff
path: root/src/Sequence/Utils
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-06-03 22:09:01 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-06-03 22:09:01 +0200
commitcfb7be14aebffd68ca357d7c6ef15e1c0974a156 (patch)
tree7448ef0ee0fa4049903efabf2fe7abf8eb7940b3 /src/Sequence/Utils
parenta98cd5d87a0c7959146a8ca35aa40f42fc146ad8 (diff)
download2017-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.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 ++ " ")