Skip to content

Commit

Permalink
Flush stdout after prompt, before parsing response.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredefox authored and mergify-bot committed Nov 30, 2021
1 parent 4462606 commit 139ac4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/Init/Prompt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Prelude hiding (break, putStrLn, getLine, putStr)

import Distribution.Client.Compat.Prelude hiding (break, empty, getLine, putStr, putStrLn)
import Distribution.Client.Init.Types
import qualified System.IO


-- | Create a prompt with optional default value that returns a
Expand Down Expand Up @@ -149,6 +150,7 @@ promptDefault
-> m t
promptDefault parse pprint msg def = do
putStr $ mkDefPrompt msg (pprint <$> def)
hFlush System.IO.stdout
input <- getLine
case def of
DefaultPrompt d | null input -> return d
Expand Down
4 changes: 4 additions & 0 deletions cabal-install/src/Distribution/Client/Init/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import Distribution.CabalSpecVersion
import Distribution.Client.Utils as P
import Distribution.Fields.Pretty
import Language.Haskell.Extension ( Language(..), Extension )
import qualified System.IO

import qualified System.Directory as P
import qualified System.Process as P
Expand Down Expand Up @@ -322,6 +323,7 @@ class Monad m => Interactive m where
copyFile :: FilePath -> FilePath -> m ()
renameDirectory :: FilePath -> FilePath -> m ()
message :: Verbosity -> String -> m ()
hFlush :: System.IO.Handle -> m ()

-- misc functions
break :: m Bool
Expand Down Expand Up @@ -350,6 +352,7 @@ instance Interactive IO where
copyFile = P.copyFile
renameDirectory = P.renameDirectory
message q = unless (q == silent) . putStrLn
hFlush = System.IO.hFlush

break = return False
throwPrompt = throwM
Expand Down Expand Up @@ -382,6 +385,7 @@ instance Interactive PurePrompt where
copyFile !_ !_ = return ()
renameDirectory !_ !_ = return ()
message !_ !_ = return ()
hFlush _ = return ()

break = return True
throwPrompt (BreakException e) = PurePrompt $ \s -> Left $ BreakException
Expand Down

0 comments on commit 139ac4f

Please sign in to comment.