@@ -29,7 +29,7 @@ import Reflex
29import Reflex.Host.Class
29import Reflex.Host.Class
30import qualified Graphics.Vty as V
30import qualified Graphics.Vty as V
32−-- | The output of a 'VtyApp'
32+-- | The output of a 'VtyApp'.
33data VtyResult t = VtyResult
33data VtyResult t = VtyResult
34 { _vtyResult_picture :: Behavior t V.Picture
34 { _vtyResult_picture :: Behavior t V.Picture
35 -- ^ The current vty output. 'runVtyAppWith' samples this value every time an
35 -- ^ The current vty output. 'runVtyAppWith' samples this value every time an
@@ -38,7 +38,7 @@ data VtyResult t = VtyResult
38 -- ^ An event that requests application termination.
38 -- ^ An event that requests application termination.
41−-- | A functional reactive vty application
41+-- | A functional reactive vty application.
42type VtyApp t m =
42type VtyApp t m =
43 ( Reflex t
43 ( Reflex t
44 , MonadHold t m
44 , MonadHold t m
@@ -51,7 +51,7 @@ type VtyApp t m =
51 , MonadRef (HostFrame t)
51 , MonadRef (HostFrame t)
53 => Event t (V.Event)
53 => Event t (V.Event)
54− -- ^ Vty input events
54+ -- ^ Vty input events.
55 -> TriggerEventT t (PostBuildT t (PerformEventT t m)) (VtyResult t)
55 -> TriggerEventT t (PostBuildT t (PerformEventT t m)) (VtyResult t)
56 -- ^ The output of the 'VtyApp'. The application runs in a context that
56 -- ^ The output of the 'VtyApp'. The application runs in a context that
57 -- allows new events to be created and triggered ('TriggerEventT'), provides
57 -- allows new events to be created and triggered ('TriggerEventT'), provides
@@ -59,12 +59,12 @@ type VtyApp t m =
59 -- ('PostBuildT'), and allows actions to be run upon occurrences
59 -- ('PostBuildT'), and allows actions to be run upon occurrences
60 -- of events ('PerformEventT').
60 -- of events ('PerformEventT').
62−-- | Runs a 'VtyApp' in a given 'Vty'
62+-- | Runs a 'VtyApp' in a given 'Vty'.
63runVtyAppWith
63runVtyAppWith
65− -- ^ A 'Vty' handle
65+ -- ^ A 'Vty' handle.
66 -> (forall t m. VtyApp t m)
66 -> (forall t m. VtyApp t m)
67− -- ^ A functional reactive vty application
67+ -- ^ A functional reactive vty application.
69runVtyAppWith vty vtyGuest =
69runVtyAppWith vty vtyGuest =
70 -- We are using the 'Spider' implementation of reflex. Running the host
70 -- We are using the 'Spider' implementation of reflex. Running the host
@@ -91,21 +91,22 @@ runVtyAppWith vty vtyGuest =
91 -- result is a 'VtyResult', and a 'FireCommand' that will be used to
91 -- result is a 'VtyResult', and a 'FireCommand' that will be used to
92 -- trigger events.
92 -- trigger events.
93 (vtyResult, fc@(FireCommand fire)) <- do
93 (vtyResult, fc@(FireCommand fire)) <- do
94− hostPerformEventT $ -- TODO document
94+ hostPerformEventT $ -- Allows the guest app to run
95+ -- 'performEvent', so that actions
96+ -- (e.g., IO actions) can be run when
96− flip runPostBuildT postBuild $ -- Runs the guest app in a context
99+ flip runPostBuildT postBuild $ -- Allows the guest app to access to
97− -- that provides access to a
98− -- "post-build" 'Event'
100+ -- a "post-build" 'Event'
100− flip runTriggerEventT events $ -- Runs the guest app in a context
102+ flip runTriggerEventT events $ -- Allows the guest app to create new
101− -- that allows new events and
102− -- triggers to be created and writes
103+ -- events and triggers and writes
103 -- those triggers to a channel from
104 -- those triggers to a channel from
104 -- which they will be read and
105 -- which they will be read and
105− -- triggered.
106+ -- processed.
107 vtyGuest vtyEvent -- The guest app is provided an
108 vtyGuest vtyEvent -- The guest app is provided an
108− -- 'Event' of vty inputs
109+ -- 'Event' of vty inputs.
110 -- Reads the current value of the 'Picture' behavior and updates the
111 -- Reads the current value of the 'Picture' behavior and updates the
111 -- display with it. This will be called whenever we determine that a
112 -- display with it. This will be called whenever we determine that a
@@ -152,7 +153,7 @@ runVtyAppWith vty vtyGuest =
152 -- have subscribers, and update the display. If we detect a shutdown
153 -- have subscribers, and update the display. If we detect a shutdown
153 -- request, the application terminates.
154 -- request, the application terminates.
154 fix $ \loop -> do
155 fix $ \loop -> do
155− -- Read the next event (blocking)
156+ -- Read the next event (blocking).
156 ers <- liftIO $ readChan events
157 ers <- liftIO $ readChan events
157 stop <- do
158 stop <- do
158 -- Fire events that have subscribers.
159 -- Fire events that have subscribers.
@@ -166,7 +167,7 @@ runVtyAppWith vty vtyGuest =
166 killThread nextEventThread -- then stop reading input events and
167 killThread nextEventThread -- then stop reading input events and
167 V.shutdown vty -- call the 'Vty's shutdown command.
168 V.shutdown vty -- call the 'Vty's shutdown command.
169− else do -- Otherwise, update the display and loop
170+ else do -- Otherwise, update the display and loop.
170 updateVty
171 updateVty