{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} module GHCup.Prompts ( PromptQuestion, PromptResponse (..), getUserPromptResponse, ) where import Control.Monad.Reader import qualified Data.Text.IO as TIO import GHCup.Prelude.Logger import GHCup.Types.Optics import GHCup.Types (PromptQuestion, PromptResponse(..)) getUserPromptResponse :: ( HasLog env , MonadReader env m , MonadIO m) => PromptQuestion -> m PromptResponse getUserPromptResponse :: forall env (m :: * -> *). (HasLog env, MonadReader env m, MonadIO m) => PromptQuestion -> m PromptResponse getUserPromptResponse PromptQuestion prompt = do forall env (m :: * -> *). (MonadReader env m, LabelOptic' "loggerConfig" A_Lens env LoggerConfig, MonadIO m) => PromptQuestion -> m () logInfo PromptQuestion prompt PromptQuestion resp <- forall (m :: * -> *) a. MonadIO m => IO a -> m a liftIO IO PromptQuestion TIO.getLine if PromptQuestion resp forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` [PromptQuestion "YES", PromptQuestion "yes", PromptQuestion "y", PromptQuestion "Y"] then forall (f :: * -> *) a. Applicative f => a -> f a pure PromptResponse PromptYes else forall (f :: * -> *) a. Applicative f => a -> f a pure PromptResponse PromptNo