1 module Render ( ekitaiMain ) where
6 import Brick.Widgets.Core
7 import Brick.BChan (newBChan, writeBChan)
10 import Control.Monad (forever, void)
11 import Control.Monad.IO.Class (liftIO)
12 import Control.Concurrent (threadDelay, forkIO)
14 import qualified Data.Vector as V
17 type ResourceName = String
19 data EkitaiState = EkitaiState
20 { ekitaiStateSim :: Simulation
26 ekitaiApp :: App EkitaiState Tick ResourceName
28 { appDraw = drawEkitai
29 , appChooseCursor = showFirstCursor
30 , appHandleEvent = handleEkitaiEvent
31 , appStartEvent = pure
32 , appAttrMap = const $ attrMap mempty []
41 let buildVty = Graphics.Vty.mkVty Graphics.Vty.defaultConfig
42 initialVty <- buildVty
43 initialState <- buildInitialState sim
44 endState <- customMain initialVty buildVty (Just chan) ekitaiApp initialState
47 buildInitialState :: Simulation -> IO EkitaiState
48 buildInitialState sim =
50 { ekitaiStateSim = sim
53 drawEkitai :: EkitaiState -> [Widget ResourceName]
54 drawEkitai state = [ vBox [str $ simToString $ ekitaiStateSim state] ]
56 handleEkitaiEvent :: EkitaiState -> BrickEvent n Tick -> EventM n (Next EkitaiState)
57 handleEkitaiEvent s (VtyEvent (EvKey (KChar 'q') [])) = halt s
58 handleEkitaiEvent s (AppEvent Tick) = continue s { ekitaiStateSim = physStep $ ekitaiStateSim s }
59 handleEkitaiEvent s _ = continue s