on master help sign in
Vty: add nextEventNonblocking (fixes #87)
bf96356Jonathan Daugherty
src/Graphics/Vty.hs+14−5
@@ -80,6 +80,8 @@ data Vty = Vty
80 update :: Picture -> IO ()
80 update :: Picture -> IO ()
81 -- | Return the next 'Event' or block until one becomes available.
81 -- | Return the next 'Event' or block until one becomes available.
82 , nextEvent :: IO Event
82 , nextEvent :: IO Event
83+ -- | Non-blocking version of 'nextEvent'.
84+ , nextEventNonblocking :: IO (Maybe Event)
83 -- | The input interface. See 'Input'.
85 -- | The input interface. See 'Input'.
84 , inputIface :: Input
86 , inputIface :: Input
85 -- | The output interface. See 'Output'.
87 -- | The output interface. See 'Output'.
@@ -148,14 +150,21 @@ intMkVty input out = do
148 mPic <- readIORef lastPicRef
150 mPic <- readIORef lastPicRef
149 maybe (return ()) innerUpdate mPic
151 maybe (return ()) innerUpdate mPic
150
152
151− let gkey = do k <- atomically $ readTChan $ _eventChannel input
152− case k of
153− (EvResize _ _) -> displayBounds out
153+ let mkResize = uncurry EvResize <$> displayBounds out
154− >>= return . (\(w,h)-> EvResize w h)
154+ gkey = do
155+ k <- atomically $ readTChan $ _eventChannel input
156+ case k of
157+ (EvResize _ _) -> mkResize
158+ _ -> return k
159+ gkey' = do
160+ k <- atomically $ tryReadTChan $ _eventChannel input
161+ case k of
162+ (Just (EvResize _ _)) -> Just <$> mkResize
155− _ -> return k
163+ _ -> return k
156
164
157 return $ Vty { update = innerUpdate
165 return $ Vty { update = innerUpdate
158 , nextEvent = gkey
166 , nextEvent = gkey
167+ , nextEventNonblocking = gkey'
159 , inputIface = input
168 , inputIface = input
160 , outputIface = out
169 , outputIface = out
161 , refresh = innerRefresh
170 , refresh = innerRefresh