Skip to content

Commit

Permalink
Merge pull request #4063 from commercialhaskell/flush-on-prompt
Browse files Browse the repository at this point in the history
Flush after prompt
  • Loading branch information
mgsloan committed Jun 10, 2018
2 parents 33d6edd + d4b5d8c commit df6520a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Expand Up @@ -42,6 +42,9 @@ Bug fixes:
was tried to be registered. This is now fixed by always building internal
libraries. See
[#3996](https://github.com/commercialhaskell/stack/issues/3996).
* When prompting users about saving their Hackage credentials on upload,
flush to stdout before waiting for the response so the prompt actually
displays.


## v1.7.1
Expand Down
24 changes: 10 additions & 14 deletions src/Stack/Upload.hs
Expand Up @@ -99,28 +99,24 @@ loadCreds config = do

when (configSaveHackageCreds config) $ do
let prompt = "Save hackage credentials to file at " ++ fp ++ " [y/n]? "
putStr prompt
input <- loopPrompt prompt
putStrLn "NOTE: Avoid this prompt in the future by using: save-hackage-creds: false"
hFlush stdout
case input of
"y" -> do
L.writeFile fp (encode hc)
putStrLn "Saved!"
hFlush stdout
_ -> return ()
when input $ do
L.writeFile fp (encode hc)
putStrLn "Saved!"
hFlush stdout

return hc

loopPrompt :: String -> IO String
loopPrompt :: String -> IO Bool
loopPrompt p = do
putStr p
hFlush stdout
input <- TIO.getLine
case input of
"y" -> return "y"
"n" -> return "n"
_ -> do
putStr p
loopPrompt p
"y" -> return True
"n" -> return False
_ -> loopPrompt p

credsFile :: Config -> IO FilePath
credsFile config = do
Expand Down

0 comments on commit df6520a

Please sign in to comment.