[Haskell-cafe] Unbuffered character IO under Windows XP?
Bulat Ziganshin
bulat.ziganshin at gmail.com
Sat Dec 29 02:05:17 EST 2007
Hello Ryan,
Saturday, December 29, 2007, 7:14:25 AM, you wrote:
> Is it possible to have unbuffered character IO under
> Windows XP?
> I have this problem as well and would love to hear if there is an answer.
once i had a hard day trying to figure out how to to the same in Unix.
in Windows, it was easy for me :))) now my program contains:
-- |Ask decryption password using hidden input
ask_decryption_password = syncUI $ do
withoutEcho $ do
putStr "\n Enter decryption password:"
hFlush stdout
getHiddenLine
-- |Input line not echoing it to the screen
getHiddenLine = go ""
where go s = do c <- getHiddenChar
case c of
'\r' -> do putStrLn ""; return s
'\n' -> do putStrLn ""; return s
c -> go (s++[c])
-- please note that FREEARC_WIN is specific to my program
#ifdef FREEARC_WIN
-- |Switch console into the hidden input mode
withoutEcho = id
-- |Input char without echoing it
getHiddenChar = liftM (chr.fromEnum) c_getch
foreign import ccall unsafe "conio.h getch"
c_getch :: IO CChar
#else
-- |Input char without echoing it
getHiddenChar = getChar
-- |Switch console into the hidden input mode
withoutEcho action = do
let setAttr attr = setTerminalAttributes stdInput attr Immediately
disableEcho = do origAttr <- getTerminalAttributes stdInput
setAttr$ origAttr.$ flip withMode ProcessInput
.$ flip withoutMode EnableEcho
.$ flip withMode KeyboardInterrupts
.$ flip withoutMode IgnoreBreak
.$ flip withMode InterruptOnBreak
return origAttr
--
bracketCtrlBreak disableEcho setAttr (\_ -> action)
#endif
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list