Adds GHCup.Prompt modules and its types to project

This commit is contained in:
Arjun Kathuria
2022-06-25 13:44:25 +05:30
parent 028696d4be
commit c7eceb2330
3 changed files with 30 additions and 0 deletions

20
lib/GHCup/Prompts.hs Normal file
View File

@@ -0,0 +1,20 @@
{-# LANGUAGE OverloadedStrings #-}
module GHCup.Prompts
(module GHCup.Types.Prompts,
getUserPromptResponse)
where
import GHCup.Types.Prompts
import qualified Data.Text.IO as TIO
import Control.Monad.IO.Class (MonadIO, liftIO)
putPrompt :: MonadIO m => PromptQuestion -> m ()
putPrompt prompt = liftIO $ TIO.putStrLn prompt
getUserPromptResponse :: (MonadIO m) => PromptQuestion -> m PromptResponse
getUserPromptResponse prompt = do
putPrompt prompt
resp <- liftIO TIO.getLine
if resp `elem` ["YES", "yes", "y", "Y"]
then pure PromptYes
else pure PromptNo

View File

@@ -0,0 +1,8 @@
module GHCup.Types.Prompts where
import Data.Text (Text)
type PromptQuestion = Text
data PromptResponse = PromptYes | PromptNo
deriving (Show, Eq)