@@ -28,11 +28,13 @@ import System.Console.Terminfo
2828import System.Posix.Signals.Exts
2929import System.Posix.Terminal
3030import System.Posix.IO ( stdInput
31− ,fdRead
31+ ,fdReadBuf
3232 ,setFdOption
3333 ,FdOption(..)
3434 )
3535
36+import Foreign ( malloc, poke, peek, free )
37+
3638-- |Representations of non-modifier keys.
3739data Key = KEsc | KFun Int | KBackTab | KPrtScr | KPause | KASCII Char | KBS | KIns
3840 | KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KNP5 | KUp | KMenu
@@ -91,7 +93,11 @@ initTermInput escDelay terminal = do
9193 when (escDelay == 0) finishAtomicInput
9294 loop
9395 readAll = do
94− (bytes, bytes_read) <- fdRead stdInput 1
96+ ptr <- malloc
97+ poke ptr 0
98+ bytes_read <- fdReadBuf stdInput ptr 1
99+ bytes <- fmap ((: "") . chr . fromIntegral) $ peek ptr
100+ free ptr
95101 when (bytes_read > 0) $ do
96102 _ <- tryPutMVar hadInput () -- signal input
97103 writeChan inputChannel (head bytes)