aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/Prompt.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 04:47:21 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-07-18 04:47:21 +0300
commit62f1e6b804a940506eff5f3f924d2d000e16119d (patch)
tree443872b2e8ba439cb77de95391bba9319449de08 /apps/Prompt.hs
parentREADME update (diff)
downloadwindows-env-62f1e6b804a940506eff5f3f924d2d000e16119d.tar.gz
windows-env-62f1e6b804a940506eff5f3f924d2d000e16119d.zip
fix compiler warnings + refactoring
Diffstat (limited to 'apps/Prompt.hs')
-rw-r--r--apps/Prompt.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/apps/Prompt.hs b/apps/Prompt.hs
index 97c23fa..d2127cd 100644
--- a/apps/Prompt.hs
+++ b/apps/Prompt.hs
@@ -7,6 +7,7 @@
module Prompt
( withPrompt
, withoutPrompt
+ , promptUnless
) where
import Control.Monad (liftM, void, when)
@@ -14,14 +15,14 @@ import Data.Char (toLower)
import System.IO (hFlush, stdout)
prompt :: String -> IO String
-prompt banner = do
- putStr banner
+prompt msg = do
+ putStr msg
hFlush stdout
getLine
promptYesNo :: String -> IO Bool
-promptYesNo banner = do
- response <- liftM (map toLower) $ prompt banner
+promptYesNo msg = do
+ response <- liftM (map toLower) $ prompt msg
if response `elem` yeses
then return True
else if response `elem` noes
@@ -35,8 +36,8 @@ promptToContinue :: IO Bool
promptToContinue = promptYesNo "Continue? (y/n) "
withPrompt :: String -> IO a -> IO Bool
-withPrompt banner m = do
- putStr banner
+withPrompt msg m = do
+ putStr msg
hFlush stdout
agreed <- promptToContinue
when agreed $ void m
@@ -44,3 +45,8 @@ withPrompt banner m = do
withoutPrompt :: IO a -> IO Bool
withoutPrompt m = m >> return True
+
+promptUnless :: Bool -> String -> IO a -> IO Bool
+promptUnless skipPrompt msg
+ | skipPrompt = withoutPrompt
+ | otherwise = withPrompt msg