Haskell: read input character from console immediately, not after newline

前端 未结 4 411
暗喜
暗喜 2020-12-09 08:17

I\'ve tried this:

main = do
    hSetBuffering stdin NoBuffering 
    c <- getChar

but it waits until the enter is pressed, which is not

4条回答
  •  自闭症患者
    2020-12-09 08:37

    Hmm.. Actually I can't see this feature to be a bug. When you read stdin that means that you want to work with a "file" and when you turn of buffering you are saying that there is no need for read buffer. But that doesn't mean that application which is emulating that "file" should not use write buffer. For linux if your terminal is in "icanon" mode it doesn't send any input until some special event will occur (like Enter pressed or Ctrl+D). Probably console in Windows have some similar modes.

提交回复
热议问题