With this file:
main = do
putStr "Input: "
s <- getLine
putStr s
It does what I want in GHCi, which is to put the prompt and then allow input right there on the same line as the prompt. If I compile it and run the executable in the terminal I won't see the prompt until after I do my input. Something about the new lines. I'm using Mac OS 10.8.5, GHC 7.4.2.
Is there a terminal setting or GHC option that I need to switch to get the behavior I want from the executable?
You need to use hSetBuffering
from System.IO
main = do
hSetBuffering stdout NoBuffering
putStr "Input: "
s <- getLine
putStr s
For completeness: You could also do hFlush stdout
to explicitly flush the partial line to file.
But yes, for your scenario, the accepted answer is almost certainly the most sensible way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With