From c7eceb233077047ce94b79c97bd5a2be1e4b1e4e Mon Sep 17 00:00:00 2001 From: Arjun Kathuria Date: Sat, 25 Jun 2022 13:44:25 +0530 Subject: [PATCH] Adds GHCup.Prompt modules and its types to project --- ghcup.cabal | 2 ++ lib/GHCup/Prompts.hs | 20 ++++++++++++++++++++ lib/GHCup/Types/Prompts.hs | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 lib/GHCup/Prompts.hs create mode 100644 lib/GHCup/Types/Prompts.hs diff --git a/ghcup.cabal b/ghcup.cabal index c2094ea..3e51465 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -69,12 +69,14 @@ library GHCup.Prelude.Process GHCup.Prelude.String.QQ GHCup.Prelude.Version.QQ + GHCup.Prompts GHCup.Requirements GHCup.Stack GHCup.Types GHCup.Types.JSON GHCup.Types.JSON.Utils GHCup.Types.Optics + GHCup.Types.Prompts GHCup.Utils GHCup.Utils.Dirs GHCup.Version diff --git a/lib/GHCup/Prompts.hs b/lib/GHCup/Prompts.hs new file mode 100644 index 0000000..c1f537d --- /dev/null +++ b/lib/GHCup/Prompts.hs @@ -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 diff --git a/lib/GHCup/Types/Prompts.hs b/lib/GHCup/Types/Prompts.hs new file mode 100644 index 0000000..a2e753c --- /dev/null +++ b/lib/GHCup/Types/Prompts.hs @@ -0,0 +1,8 @@ +module GHCup.Types.Prompts where + +import Data.Text (Text) + +type PromptQuestion = Text + +data PromptResponse = PromptYes | PromptNo + deriving (Show, Eq)