Merge remote-tracking branch 'origin/merge-requests/266'
This commit is contained in:
commit
00fa70b9de
@ -17,6 +17,7 @@ import GHCup.Prelude ( decUTF8Safe )
|
|||||||
import GHCup.Prelude.File
|
import GHCup.Prelude.File
|
||||||
import GHCup.Prelude.Logger
|
import GHCup.Prelude.Logger
|
||||||
import GHCup.Prelude.Process
|
import GHCup.Prelude.Process
|
||||||
|
import GHCup.Prompts
|
||||||
|
|
||||||
import Brick
|
import Brick
|
||||||
import Brick.Widgets.Border
|
import Brick.Widgets.Border
|
||||||
@ -52,6 +53,8 @@ import Text.PrettyPrint.HughesPJClass ( prettyShow )
|
|||||||
import URI.ByteString
|
import URI.ByteString
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.Lazy.Builder as B
|
||||||
|
import qualified Data.Text.Lazy as L
|
||||||
import qualified Graphics.Vty as Vty
|
import qualified Graphics.Vty as Vty
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import System.Environment (getExecutablePath)
|
import System.Environment (getExecutablePath)
|
||||||
@ -98,7 +101,7 @@ keyHandlers KeyBindings {..} =
|
|||||||
[ (bQuit, const "Quit" , halt)
|
[ (bQuit, const "Quit" , halt)
|
||||||
, (bInstall, const "Install" , withIOAction install')
|
, (bInstall, const "Install" , withIOAction install')
|
||||||
, (bUninstall, const "Uninstall", withIOAction del')
|
, (bUninstall, const "Uninstall", withIOAction del')
|
||||||
, (bSet, const "Set" , withIOAction ((liftIO .) . set'))
|
, (bSet, const "Set" , withIOAction set')
|
||||||
, (bChangelog, const "ChangeLog", withIOAction changelog')
|
, (bChangelog, const "ChangeLog", withIOAction changelog')
|
||||||
, ( bShowAllVersions
|
, ( bShowAllVersions
|
||||||
, \BrickSettings {..} ->
|
, \BrickSettings {..} ->
|
||||||
@ -486,9 +489,12 @@ install' _ (_, ListResult {..}) = do
|
|||||||
<> "Also check the logs in ~/.ghcup/logs"
|
<> "Also check the logs in ~/.ghcup/logs"
|
||||||
|
|
||||||
|
|
||||||
set' :: BrickState -> (Int, ListResult) -> IO (Either String ())
|
set' :: (MonadReader AppState m, MonadIO m, MonadThrow m, MonadFail m, MonadMask m, MonadUnliftIO m)
|
||||||
set' _ (_, ListResult {..}) = do
|
=> BrickState
|
||||||
settings <- readIORef settings'
|
-> (Int, ListResult)
|
||||||
|
-> m (Either String ())
|
||||||
|
set' bs input@(_, ListResult {..}) = do
|
||||||
|
settings <- liftIO $ readIORef settings'
|
||||||
|
|
||||||
let run =
|
let run =
|
||||||
flip runReaderT settings
|
flip runReaderT settings
|
||||||
@ -504,7 +510,28 @@ set' _ (_, ListResult {..}) = do
|
|||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
VRight _ -> pure $ Right ()
|
VRight _ -> pure $ Right ()
|
||||||
VLeft e -> pure $ Left (prettyShow e)
|
VLeft e -> case e of
|
||||||
|
(V (NotInstalled tool _)) -> do
|
||||||
|
promptAnswer <- getUserPromptResponse userPrompt
|
||||||
|
case promptAnswer of
|
||||||
|
PromptYes -> do
|
||||||
|
res <- install' bs input
|
||||||
|
case res of
|
||||||
|
(Left err) -> pure $ Left err
|
||||||
|
(Right _) -> do
|
||||||
|
logInfo "Setting now..."
|
||||||
|
set' bs input
|
||||||
|
|
||||||
|
PromptNo -> pure $ Left (prettyShow e)
|
||||||
|
where
|
||||||
|
userPrompt = L.toStrict . B.toLazyText . B.fromString $
|
||||||
|
"This Version of "
|
||||||
|
<> show tool
|
||||||
|
<> " you are trying to set is not installed.\n"
|
||||||
|
<> "Would you like to install it first? [Y/N]: "
|
||||||
|
|
||||||
|
_ -> pure $ Left (prettyShow e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
del' :: (MonadReader AppState m, MonadIO m, MonadFail m, MonadMask m, MonadUnliftIO m)
|
del' :: (MonadReader AppState m, MonadIO m, MonadFail m, MonadMask m, MonadUnliftIO m)
|
||||||
|
@ -69,6 +69,7 @@ library
|
|||||||
GHCup.Prelude.Process
|
GHCup.Prelude.Process
|
||||||
GHCup.Prelude.String.QQ
|
GHCup.Prelude.String.QQ
|
||||||
GHCup.Prelude.Version.QQ
|
GHCup.Prelude.Version.QQ
|
||||||
|
GHCup.Prompts
|
||||||
GHCup.Requirements
|
GHCup.Requirements
|
||||||
GHCup.Stack
|
GHCup.Stack
|
||||||
GHCup.Types
|
GHCup.Types
|
||||||
|
28
lib/GHCup/Prompts.hs
Normal file
28
lib/GHCup/Prompts.hs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{-# 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 prompt = do
|
||||||
|
logInfo prompt
|
||||||
|
resp <- liftIO TIO.getLine
|
||||||
|
if resp `elem` ["YES", "yes", "y", "Y"]
|
||||||
|
then pure PromptYes
|
||||||
|
else pure PromptNo
|
@ -657,3 +657,7 @@ isSafeDir (IsolateDirResolved _) = False
|
|||||||
isSafeDir (GHCupDir _) = True
|
isSafeDir (GHCupDir _) = True
|
||||||
isSafeDir (GHCupBinDir _) = False
|
isSafeDir (GHCupBinDir _) = False
|
||||||
|
|
||||||
|
type PromptQuestion = Text
|
||||||
|
|
||||||
|
data PromptResponse = PromptYes | PromptNo
|
||||||
|
deriving (Show, Eq)
|
||||||
|
Loading…
Reference in New Issue
Block a user