on master help sign in
Wrap internal events in a new InternalEvent type to improve how signal handling is done
2cd98a8Jonathan Daugherty
src/Graphics/Vty.hs+11−8
@@ -48,6 +48,7 @@ where
48
48
49import Graphics.Vty.Config
49import Graphics.Vty.Config
50import Graphics.Vty.Input
50import Graphics.Vty.Input
51+import Graphics.Vty.Input.Events
51import Graphics.Vty.Output
52import Graphics.Vty.Output
52import Graphics.Vty.Output.Interface
53import Graphics.Vty.Output.Interface
53import Graphics.Vty.Picture
54import Graphics.Vty.Picture
@@ -209,16 +210,18 @@ internalMkVty input out = do
209 maybe (return ()) innerUpdate mPic
210 maybe (return ()) innerUpdate mPic
210
211
211 let mkResize = uncurry EvResize <$> displayBounds out
212 let mkResize = uncurry EvResize <$> displayBounds out
213+
214+ handleInternalEvent ResumeAfterSignal = mkResize
215+ handleInternalEvent (InputEvent e) = return e
216+
212 gkey = do
217 gkey = do
213− k <- atomically $ readTChan $ _eventChannel input
218+ e <- atomically $ readTChan $ _eventChannel input
214− case k of
219+ handleInternalEvent e
215− (EvResize _ _) -> mkResize
216− _ -> return k
217 gkey' = do
220 gkey' = do
218− k <- atomically $ tryReadTChan $ _eventChannel input
221+ mEv <- atomically $ tryReadTChan $ _eventChannel input
219− case k of
222+ case mEv of
220− (Just (EvResize _ _)) -> Just <$> mkResize
223+ Just e -> Just <$> handleInternalEvent e
221− _ -> return k
224+ Nothing -> return Nothing
222
225
223 return $ Vty { update = innerUpdate
226 return $ Vty { update = innerUpdate
224 , nextEvent = gkey
227 , nextEvent = gkey
src/Graphics/Vty/Input.hs+1−2
@@ -158,9 +158,8 @@ inputForConfig config@Config{ termName = Just termName
158 setAttrs
158 setAttrs
159 input <- initInput config activeInputMap
159 input <- initInput config activeInputMap
160 let pokeIO = Catch $ do
160 let pokeIO = Catch $ do
161− let e = error "vty internal failure: this value should not propagate to users"
162 setAttrs
161 setAttrs
163− atomically $ writeTChan (input^.eventChannel) (EvResize e e)
162+ atomically $ writeTChan (input^.eventChannel) ResumeAfterSignal
164 _ <- installHandler windowChange pokeIO Nothing
163 _ <- installHandler windowChange pokeIO Nothing
165 _ <- installHandler continueProcess pokeIO Nothing
164 _ <- installHandler continueProcess pokeIO Nothing
166
165
src/Graphics/Vty/Input/Events.hs+10
@@ -76,3 +76,13 @@ data Event
76instance NFData Event
76instance NFData Event
77
77
78type ClassifyMap = [(String,Event)]
78type ClassifyMap = [(String,Event)]
79+
80+-- | The type of internal events that drive the internal Vty event
81+-- dispatching to the application.
82+data InternalEvent =
83+ ResumeAfterSignal
84+ -- ^ Vty resumed operation after the process was interrupted with a
85+ -- signal. In practice this translates into a screen redraw in the
86+ -- input event loop.
87+ | InputEvent Event
88+ -- ^ An input event was received.
src/Graphics/Vty/Input/Loop.hs+2−2
@@ -55,7 +55,7 @@ data Input = Input
55 { -- | Channel of events direct from input processing. Unlike
55 { -- | Channel of events direct from input processing. Unlike
56 -- 'nextEvent' this will not refresh the display if the next event
56 -- 'nextEvent' this will not refresh the display if the next event
57 -- is an 'EvResize'.
57 -- is an 'EvResize'.
58− _eventChannel :: TChan Event
58+ _eventChannel :: TChan InternalEvent
59 -- | Shuts down the input processing. As part of shutting down the
59 -- | Shuts down the input processing. As part of shutting down the
60 -- input, this should also restore the input state.
60 -- input, this should also restore the input state.
61 , shutdownInput :: IO ()
61 , shutdownInput :: IO ()
@@ -115,7 +115,7 @@ addBytesToProcess block = unprocessedBytes <>= block
115emit :: Event -> InputM ()
115emit :: Event -> InputM ()
116emit event = do
116emit event = do
117 logMsg $ "parsed event: " ++ show event
117 logMsg $ "parsed event: " ++ show event
118− view eventChannel >>= liftIO . atomically . flip writeTChan event
118+ view eventChannel >>= liftIO . atomically . flip writeTChan (InputEvent event)
119
119
120-- The timing requirements are assured by the VMIN and VTIME set for the
120-- The timing requirements are assured by the VMIN and VTIME set for the
121-- device.
121-- device.