module Rasa (rasa) where
import Rasa.Internal.Editor
import Rasa.Internal.Action
import Rasa.Internal.Events
import Rasa.Internal.Listeners
import Control.Lens
import Control.Monad
import Control.Monad.IO.Class
import Data.Maybe
import Pipes
import Pipes.Concurrent
import Pipes.Parse
rasa :: Action () -> IO ()
rasa initilize = do
(output, input) <- spawn unbounded
evalAction (mkActionState output) $ do
initilize
dispatchEvent Init
eventLoop $ fromInput input
dispatchEvent Exit
eventLoop :: Producer (Action ()) IO () -> Action ()
eventLoop producer = do
dispatchEvent BeforeRender
dispatchEvent OnRender
dispatchEvent AfterRender
dispatchEvent BeforeEvent
(mAction, nextProducer) <- liftIO $ runStateT draw producer
fromMaybe (return ()) mAction
isExiting <- use exiting
unless isExiting $ eventLoop nextProducer