on master help sign in
resolve the failure to parse reads from the terminal that contained 2 or more ESC prefixed keys.
commita20928d6109996a41b3be8ee135c395be62ad2ca authorCorey O'Connor <corey@ooyala.com> dateFri 31 Jan 2014, 12:10 (13 years ago) parent24b6a9d
2 files changed+9−7
src/Graphics/Vty/Input/Internal.hs+7−4 test/VerifyUsingMockInput.hs+2−3
src/Graphics/Vty/Input/Internal.hs+7−4
@@ -20,7 +20,7 @@ import Control.Monad.Trans.Reader (ReaderT(..))
2020import Data.Char
2121import Data.Default
2222import Data.IORef
23−import Data.List( inits )
23+import Data.List(tails,inits)
2424import qualified Data.Map as M( fromList, lookup )
2525import Data.Maybe ( mapMaybe )
2626import qualified Data.Set as S( fromList, member )
@@ -160,12 +160,15 @@ compile table = cl' where
160160 True -> Prefix
161161 -- if the input_block is exactly what is expected for an event then consume the whole
162162 -- block and return the event
163− -- look up progressively large prefixes of the input block until an event is found
163+ -- look up progressively smaller tails of the input block until an event is found
164+ -- The assumption is that the event that consumes the most input bytes should be
165+ -- produced.
166+ -- The test verify_full_syn_input_to_event_2x verifies this.
164167 -- H: There will always be one match. The prefix_set contains, by definition, all
165168 -- prefixes of an event.
166169 False ->
167− let input_prefixes = init $ inits input_block
168− in case mapMaybe (\s -> (,) s `fmap` M.lookup s event_for_input) input_prefixes of
170+ let input_tails = init $ tail $ tails input_block
171+ in case mapMaybe (\s -> (,) s `fmap` M.lookup s event_for_input) input_tails of
169172 (s,e) : _ -> Valid e (drop (length s) input_block)
170173 -- neither a prefix or a full event. Might be interesting to log.
171174 [] -> Invalid
test/VerifyUsingMockInput.hs+2−3
@@ -1,8 +1,7 @@
11{-# LANGUAGE MultiParamTypeClasses #-}
22{-# LANGUAGE FlexibleInstances #-}
3−{- We setup the environment to envoke certain terminals of interest.
4− - This assumes appropriate definitions exist in the current environment for the terminals of
5− - interest.
3+{- Generate some input bytes and delays between blocks of input bytes. Verify the events produced
4+ - are as expected.
65 -}
76module Main where
87