2022-06-25 08:14:25 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2022-06-28 14:15:17 +00:00
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
|
2022-06-25 08:14:25 +00:00
|
|
|
module GHCup.Prompts
|
2022-07-10 04:14:23 +00:00
|
|
|
( PromptQuestion,
|
|
|
|
PromptResponse (..),
|
2022-06-28 14:15:17 +00:00
|
|
|
getUserPromptResponse,
|
|
|
|
)
|
2022-06-25 08:14:25 +00:00
|
|
|
where
|
|
|
|
|
2022-06-28 14:15:17 +00:00
|
|
|
import Control.Monad.Reader
|
2022-06-25 08:14:25 +00:00
|
|
|
import qualified Data.Text.IO as TIO
|
2022-06-28 14:15:17 +00:00
|
|
|
import GHCup.Prelude.Logger
|
|
|
|
import GHCup.Types.Optics
|
2022-07-10 04:15:39 +00:00
|
|
|
import GHCup.Types (PromptQuestion, PromptResponse(..))
|
2022-06-25 08:14:25 +00:00
|
|
|
|
2022-06-28 14:15:17 +00:00
|
|
|
getUserPromptResponse :: ( HasLog env
|
|
|
|
, MonadReader env m
|
|
|
|
, MonadIO m)
|
|
|
|
=> PromptQuestion
|
|
|
|
-> m PromptResponse
|
2022-07-10 04:15:39 +00:00
|
|
|
|
2022-06-25 08:14:25 +00:00
|
|
|
getUserPromptResponse prompt = do
|
2022-07-10 04:15:39 +00:00
|
|
|
logInfo prompt
|
2022-06-25 08:14:25 +00:00
|
|
|
resp <- liftIO TIO.getLine
|
|
|
|
if resp `elem` ["YES", "yes", "y", "Y"]
|
|
|
|
then pure PromptYes
|
|
|
|
else pure PromptNo
|