如何防止输入被冲刷成输出? [英] How to prevent inputs being flushed into output?
本文介绍了如何防止输入被冲刷成输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Ubuntu上.当我在终端上运行ghci
并执行以下操作时:
I'm on Ubuntu. When I run ghci
on Terminal and do this:
Prelude Control.Monad System.IO> forever $ getChar >>= print
结果是这样的:
a'a'
b'b'
C'C'
%'%'
\'\\'
1'1'
''\''
"'"'
^X'\CAN'
^?'\DEL'
^CInterrupted.
也就是说,我在键盘上输入的字符将被刷新到输出中.如何防止这种情况并且只将print
作为作者?
That is, the characters I type in my keyboard are being flushed into output. How can I prevent this and have only print
as the writer?
推荐答案
To prevent input being flushed into the output (or "echoed"), use 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'
这可用于执行输入密码之类的事情.
This can be used to do things like read in a password.
这篇关于如何防止输入被冲刷成输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文