【问题标题】:How to prevent inputs being flushed into output?如何防止输入被冲入输出?
【发布时间】:2019-12-18 03:47:49
【问题描述】:

我在 Ubuntu 上。当我在终端上运行ghci 并执行以下操作时:

Prelude Control.Monad System.IO> forever $ getChar >>= print

结果是这样的:

a'a'
b'b'
C'C'
%'%'
\'\\'
1'1'
''\''
"'"'
^X'\CAN'
^?'\DEL'
^CInterrupted.

也就是说,我在键盘上键入的字符正在刷新到输出中。我怎样才能防止这种情况并且只有print 作为作者?

【问题讨论】:

    标签: haskell input output flush gnome-terminal


    【解决方案1】:

    为防止输入被刷新到输出中(或“回显”),请使用hSetEcho stdin False

    Prelude> import System.IO
    Prelude System.IO> import Control.Monad
    Prelude System.IO Control.Monad> hSetEcho stdin False
    Prelude System.IO Control.Monad> forever $ getChar >>= print
    'a'
    '\n'
    'b'
    'c'
    

    这可以用来做read in a password之类的事情。

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      相关资源
      最近更新 更多