@@ -86,6 +86,8 @@ makeLenses ''InputState
8686
8787type InputM a = StateT InputState (ReaderT Input IO) a
8888
89+-- this must be run on an OS thread dedicated to this input handling.
90+-- otherwise the terminal timing read behavior will block the execution of the lightweight threads.
8991loop_input_processor :: InputM ()
9092loop_input_processor = do
9193 read_from_device >>= add_bytes_to_process
@@ -117,7 +119,7 @@ read_from_device = do
117119apply_timing_config :: Fd -> Config -> IO ()
118120apply_timing_config fd config =
119121 let vtime = min 255 $ singleEscPeriod config `div` 100000
120− in set_term_timing fd 0 vtime
122+ in set_term_timing fd 1 vtime
121123
122124parse_event :: InputM Event
123125parse_event = do
@@ -152,16 +154,16 @@ compile table = cl' where
152154 -- create a map from strings to event
153155 event_for_input = flip M.lookup (M.fromList table)
154156 cl' [] = Prefix
155− cl' input_block = case S.member input_block prefix_set of
156− True -> Prefix
157− -- if the input_block is exactly what is expected for an event then consume the whole
158− -- block and return the event
159− False -> case event_for_input input_block of
160− Just (EvKey k m) -> Valid k m []
157+ cl' input_block = case event_for_input input_block of
158+ Just (EvKey k m) -> Valid k m []
159+ Nothing -> case S.member input_block prefix_set of
160+ True -> Prefix
161+ -- if the input_block is exactly what is expected for an event then consume the whole
162+ -- block and return the event
161163 -- look up progressively large prefixes of the input block until an event is found
162164 -- H: There will always be one match. The prefix_set contains, by definition, all
163165 -- prefixes of an event.
164− Nothing ->
166+ False ->
165167 let input_prefixes = init $ inits input_block
166168 in case mapMaybe (\s -> (,) s `fmap` event_for_input s) input_prefixes of
167169 (s,EvKey k m) : _ -> Valid k m (drop (length s) input_block)
@@ -218,7 +220,7 @@ initInputForFd config_ref classify_table input_fd = do
218220 <*> pure (writeIORef stop_flag True)
219221 <*> pure config_ref
220222 <*> pure input_fd
221− _ <- forkIO $ run_input_processor_loop classify_table input stop_flag
223+ _ <- forkOS $ run_input_processor_loop classify_table input stop_flag
222224 return input
223225
224226foreign import ccall "vty_set_term_timing" set_term_timing :: Fd -> Int -> Int -> IO ()