@@ -19,6 +19,7 @@ import Graphics.Vty.Input.Events
20import Control.Applicative
20import Control.Applicative
21import Control.Concurrent
21import Control.Concurrent
22+import Control.Concurrent.STM
22import Control.Exception (mask, try, SomeException)
23import Control.Exception (mask, try, SomeException)
23import Control.Lens
24import Control.Lens
24import Control.Monad (when, mzero, forM_)
25import Control.Monad (when, mzero, forM_)
@@ -43,7 +44,7 @@ import Text.Printf (hPrintf)
43data Input = Input
44data Input = Input
44 { -- | Channel of events direct from input processing. Unlike 'nextEvent' this will not refresh
45 { -- | Channel of events direct from input processing. Unlike 'nextEvent' this will not refresh
45 -- the display if the next event is an 'EvResize'.
46 -- the display if the next event is an 'EvResize'.
46− _eventChannel :: Chan Event
47+ _eventChannel :: TChan Event
47 -- | Shuts down the input processing. This should return the terminal input state to before
48 -- | Shuts down the input processing. This should return the terminal input state to before
48 -- the input initialized.
49 -- the input initialized.
49 , shutdownInput :: IO ()
50 , shutdownInput :: IO ()
@@ -96,7 +97,7 @@ addBytesToProcess block = unprocessedBytes <>= block
96emit :: Event -> InputM ()
97emit :: Event -> InputM ()
97emit event = do
98emit event = do
98 logMsg $ "parsed event: " ++ show event
99 logMsg $ "parsed event: " ++ show event
99− view eventChannel >>= liftIO . flip writeChan event
100+ view eventChannel >>= liftIO . atomically . flip writeTChan event
101-- The timing requirements are assured by the VMIN and VTIME set for the device.
102-- The timing requirements are assured by the VMIN and VTIME set for the device.
@@ -192,7 +193,7 @@ initInput config classifyTable = do
192 setFdOption fd NonBlockingRead False
193 setFdOption fd NonBlockingRead False
193 applyConfig fd config
194 applyConfig fd config
194 stopSync <- newEmptyMVar
195 stopSync <- newEmptyMVar
195− input <- Input <$> newChan
196+ input <- Input <$> atomically newTChan
196 <*> pure (return ())
197 <*> pure (return ())
197 <*> newIORef config
198 <*> newIORef config
198 <*> maybe (return Nothing)
199 <*> maybe (return Nothing)