intellij-haskell
intellij-haskell copied to clipboard
Stack run does not print text in terminal
This isn't completely related to intellij-haskell, but the run task is created from this plugin, so perhaps someone knows something about this.
I have a very simple test:
main = do
putStrLn "Hello, what's your name?"
name <- getLine
putStrLn ("Hey " ++ name)
If I run it in my terminal or in the intellij terminal, using either stack run or stack build --exec ***.exe (what the plugin template uses), it works.
However, if I run the template, which launches the run tab, I don't get the hello prompt until I type something and press enter. When I first tried this, I thought my project failed to build for many minutes.
Does anyone have any idea what's going on here?
Using v1.0.0-beta40 on macOS
i have the exact same problem
Thanks for reporting!
I can reproduce this issue but I can not find the cause.
Affects me too on Linux. My guess is the executable somehow gets a non-pty stdout/err which causes output buffering to be enabled automatically.
Do not know if it really solution but got the example in this way working:
import System.IO
main = do
hSetBuffering stdout NoBuffering
putStrLn "Hello, what's your name?"
name <- getLine
putStrLn ("Hey " ++ name)
changing the sample source in following way
module Main where
import System.Posix.IO (stdInput, stdOutput)
import System.Posix.Terminal (queryTerminal)
import Lib
main :: IO ()
main = do
putStrLn "Hello, what's your name?"
name <- getLine
inTty <- queryTerminal stdInput
outTty <- queryTerminal stdOutput
putStrLn ("Hey " ++ name)
putStrLn $ "Am I terminal? In - " ++ (show inTty) ++ ", out - " ++ (show outTty)
prints
[…skip…]
Am I terminal? In - False, out - False
Seems to be working again.
Still doesn't work for me with Beta 52 (no more recent release published on Intellij Market).
@Sir4ur0n Which version of IntelliJ are you using? I did not make changes to the plugin with respect to this issue.
For me the putStrLns are just working.
When I use getLine I have to use NoBuffering as in this example:
import System.IO
main = do
hSetBuffering stdout NoBuffering
putStrLn "Hello, what's your name?"
name <- getLine
putStrLn ("Hey " ++ name)
Ah, I hadn't paid enough attention to the hSetBuffering stdout NoBuffering part, my apologies :( It works when disabling buffering.
Shouldn't this be documented? Maybe even better: somehow enabled by default? This may confuse many people learning Haskell with Intellij and not able to make simple "Hello world" examples work 😞
Alternative: In the Run/Debug configuration window, display a warning that it may be necessary to add this for basic IO, like getLine:
import System.IO
main = do
hSetBuffering stdout NoBuffering
-- Do whatever IO you want here
What do you think?
No problem :smile:
I do not know how to enable it by default because it's in the Haskell code. Also do not see a Stack option for this.
Alternative: In the Run/Debug configuration window, display a warning that it may be necessary to add this for basic IO, like
Yes, that is the most simple alternative solution.