Last active
October 30, 2015 19:27
-
-
Save skatenerd/ef3bab81ba6ec979025d to your computer and use it in GitHub Desktop.
run ncurses in state monad?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import UI.NCurses | |
import Data.Maybe | |
import Control.Monad | |
import Control.Monad.State | |
main :: IO () | |
main = runCurses $ void (runStateT top []) | |
top = do | |
lift $ setEcho False | |
w <- lift $ defaultWindow | |
gameLoop w | |
gameLoop w = do | |
c <- lift $ getCharInput w | |
stuff <- get | |
put $ c : stuff | |
newstuff <- get | |
lift $ updateWindow w $ do | |
moveCursor 0 0 | |
drawString $ "it was " ++ newstuff | |
lift render | |
unless (c == 'q') $ gameLoop w | |
getCharInput w = loop where | |
loop = do | |
ev <- getEvent w Nothing | |
case ev of | |
Just (EventCharacter c) -> return c | |
Nothing -> loop | |
Just _ -> loop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment