Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Last active October 30, 2015 19:27
Show Gist options
  • Save skatenerd/ef3bab81ba6ec979025d to your computer and use it in GitHub Desktop.
Save skatenerd/ef3bab81ba6ec979025d to your computer and use it in GitHub Desktop.
run ncurses in state monad?
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