mischief-ecs-0.2.0.0: src/Mischief/ECS/Stdin.hs
module Mischief.ECS.Stdin where
import Control.Monad.IO.Class
import GHC.IO.Handle
import Mischief.ECS.World
import System.IO
import Prelude hiding (read)
init :: System ()
init = liftIO $ do
hSetBuffering stdin NoBuffering
hSetEcho stdin False
-- | Gets the characters inputted by the user into the terminal since the lasts call. Only to be used for examples and test applications. Make sure to call 'Mischief.ECS.Stdin.init' first.
read :: System String
read = do
ready <- liftIO $ hReady stdin
if ready
then do
c <- liftIO getChar
([c] ++) <$> read
else do
return []
-- | Gets the last character inputted by the user into the terminal. Only to be used for examples and test applications. Make sure to call 'Mischief.ECS.Stdin.init' first.
readLast :: System (Maybe Char)
readLast = do
r <- read
return $ case r of
[] -> Nothing
x -> Just $ last x