on master help sign in
move some function keys to be read from caps. disambiguate some keys. expand input test
commitc231f4763eb8d844202af908f28a5de256f5a5fc authorCorey O'Connor <corey@ooyala.com> dateWed 13 Nov 2013, 23:23 (13 years ago) parent0b66c1a
3 files changed+68−25
src/Graphics/Vty/Input/Data.hs+37−10 src/Graphics/Vty/Input/Internal.hs+1−1 test/VerifyUsingMockInput.hs+30−14
src/Graphics/Vty/Input/Data.hs+37−10
@@ -2,6 +2,8 @@
22module Graphics.Vty.Input.Data where
33
44-- | Representations of non-modifier keys.
5+--
6+-- KFun is indexed from 0 to 63. Range of supported FKeys varies by terminal and keyboard.
57data Key = KEsc | KFun Int | KBackTab | KPrtScr | KPause | KASCII Char | KBS | KIns
68 | KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KNP5 | KUp | KMenu
79 | KLeft | KDown | KRight | KEnter
@@ -41,7 +43,10 @@ keys_from_caps_table =
4143 , ("kcub1", EvKey KLeft [])
4244 , ("kLFT", EvKey KLeft [MShift])
4345 , ("kRIT", EvKey KRight [MShift])
44− ]
46+ ] ++ function_key_caps_table
47+
48+function_key_caps_table :: [(String, Event)]
49+function_key_caps_table = flip map [0..63] $ \n -> ("key_f" ++ show n, EvKey (KFun n) [])
4550
4651nav_keys_0 :: ClassifyTable
4752nav_keys_0 =
@@ -82,22 +87,41 @@ nav_keys_3 =
8287-- Support for simple characters.
8388-- we limit to < 0xC1. The UTF8 sequence detector will catch all values 0xC2 and above before this
8489-- classify table is reached.
90+--
91+-- TODO: resolve
92+-- 1. start at ' '. The earlier characters are all ctrl_char_keys
8593simple_chars :: ClassifyTable
86−simple_chars = [ (x:[],(KASCII x,[])) | x <- map toEnum [0..0xC1] ]
94+simple_chars = [(x:[],(KASCII x,[])) | x <- [' ' .. toEnum 0xC1]]
8795
8896-- TODO: Support for function keys (should use terminfo)
8997--
9098-- (corey): yes. This definitely should. On my terminal these keys do not operate as expected.
91−function_keys_0 :: ClassifyTable
92−function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
93−
99+-- function_keys_0 :: ClassifyTable
100+-- function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
101+
102+-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
103+-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
104+-- character transmitted, this fact can be indicated with km. Other- wise, software will
105+-- assume that the 8th bit is parity and it will usually be cleared. If strings exist to turn this
106+-- ``meta mode'' on and off, they can be given as smm and rmm."
107+--
108+-- That is more complex that below. I cannot fault the original author for just hard coding a table
109+-- ;-)
94110function_keys_1 :: ClassifyTable
95111function_keys_1 =
96112 let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
97− concat [ f 6 [17..21] [], f 11 [23,24] [], f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
98−
113+ concat [f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
114+
115+-- TODO: resolve -
116+--
117+-- 1. removed 'ESC' from second list due to duplication with "special_support_keys".
118+-- 2. removed '[' from second list due to conflict with 7-bit encoding for ESC. Whether meta+[ is
119+-- the same as ESC should examine km and current encoding.
120+-- 3. stopped enumeration at '~' instead of '\DEL'. The latter is mapped to KBS by
121+-- special_support_keys.
99122function_keys_2 :: ClassifyTable
100−function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\ESC':'\t':[' ' .. '\DEL'] ]
123+function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\t':[' ' .. '~'],
124+ x /= '[']
101125
102126-- Ctrl+Char
103127ctrl_char_keys :: ClassifyTable
@@ -108,9 +132,13 @@ ctrl_char_keys =
108132 ]
109133
110134-- Ctrl+Meta+Char
135+--
136+-- TODO: CTRL-i is the same as tab thing
111137ctrl_meta_keys :: ClassifyTable
112138ctrl_meta_keys =
113− [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']) ]
139+ [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']),
140+ y /= 'i'
141+ ]
114142
115143-- Special support
116144special_support_keys :: ClassifyTable
@@ -131,7 +159,6 @@ ansi_classify_table =
131159 , nav_keys_2
132160 , nav_keys_3
133161 , simple_chars
134− , function_keys_0
135162 , function_keys_1
136163 , function_keys_2
137164 , ctrl_char_keys
src/Graphics/Vty/Input/Internal.hs+1−1
@@ -4,7 +4,7 @@ import Graphics.Vty.Input.Data
44
55import Codec.Binary.UTF8.Generic (decode)
66import Control.Concurrent
7−import Control.Exception (try, IOException(..))
7+import Control.Exception (try, IOException)
88import Control.Monad (when, void)
99
1010import Data.Char
test/VerifyUsingMockInput.hs+30−14
@@ -8,7 +8,7 @@ module Main where
88
99import Verify.Graphics.Vty.Terminal
1010
11−import Data.List (intersperse, permutations)
11+import Data.List (intersperse)
1212
1313import Graphics.Vty hiding (resize)
1414import Graphics.Vty.Input.Data
@@ -36,6 +36,9 @@ import Test.SmallCheck.Series
3636max_block_size :: Int
3737max_block_size = 16
3838
39+max_table_size :: Int
40+max_table_size = 28
41+
3942forEachOf :: (Show a, Testable m b) => [a] -> (a -> b) -> Property m
4043forEachOf l = over (generate (\n -> take n l))
4144
@@ -81,7 +84,6 @@ assert_events_from_syn_input :: ClassifyTable -> InputSpec -> ExpectedSpec -> IO
8184assert_events_from_syn_input table input_spec expected_events = do
8285 let max_duration = sum [t | Delay t <- input_spec] + min_detectable_delay
8386 event_count = length expected_events
84− -- create pipe
8587 (output_fd, input_fd) <- createPipe
8688 (output, shutdown_input) <- initInputForFd test_esc_sample_delay table output_fd
8789 events_ref <- newIORef []
@@ -93,13 +95,13 @@ assert_events_from_syn_input table input_spec expected_events = do
9395 closeFd input_fd
9496 closeFd output_fd
9597 -- drain output pipe
96− let read_all_events = read_loop event_count
98+ let read_events = read_loop event_count
9799 read_loop 0 = return ()
98100 read_loop n = do
99101 e <- readChan output
100102 modifyIORef events_ref ((:) e)
101103 read_loop (n - 1)
102− gen_events_using_io_actions max_duration write_wait_close read_all_events
104+ gen_events_using_io_actions max_duration write_wait_close read_events
103105 out_events <- reverse <$> readIORef events_ref
104106 print (input_spec, expected_events, out_events)
105107 return $ out_events == expected_events
@@ -139,8 +141,11 @@ instance Show (InputBlocksUsingTable event) where
139141
140142instance Monad m => Serial m (InputBlocksUsingTable event) where
141143 series = do
142− n :: Int <- localDepth (max max_block_size) series -- what elements to select from the table
143− return $ InputBlocksUsingTable $ \table -> concat (take n (permutations table))
144+ n :: Int <- localDepth (const max_table_size) series
145+ return $ InputBlocksUsingTable $ \table -> concat (take n (selections table))
146+ where
147+ selections [] = []
148+ selections (x:xs) = let z = selections xs in [x] : (z ++ map ((:) x) z)
144149
145150verify_simple_input_block_to_event :: Property IO
146151verify_simple_input_block_to_event = forAll $ \(InputBlocksUsingTable gen) -> do
@@ -161,7 +166,16 @@ verify_keys_from_caps_table_block_to_event = forAll $ \(InputBlocksUsingTable ge
161166 assert_events_from_input_block (map_to_legacy_table table) input events
162167
163168verify_simple_syn_input_to_event :: Property IO
164−verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
169+verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
170+ let table = simple_chars
171+ input_seq = gen table
172+ events = [EvKey k ms | (_,(k,ms)) <- input_seq]
173+ keydowns = [Bytes s | (s,_) <- input_seq]
174+ input = intersperse (Delay test_key_delay) keydowns
175+ assert_events_from_syn_input (concat ansi_classify_table) input events
176+
177+verify_caps_syn_input_to_event :: Property IO
178+verify_caps_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
165179 forEachOf terminals_of_interest $ \term_name -> monadic $ do
166180 term <- setupTerm term_name
167181 let table = caps_classify_table term keys_from_caps_table
@@ -171,9 +185,9 @@ verify_simple_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) ->
171185 input = intersperse (Delay test_key_delay) keydowns
172186 assert_events_from_syn_input (map_to_legacy_table table) input events
173187
174−verify_fkeys_syn_input_to_event :: Property IO
175−verify_fkeys_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
176− let table = function_keys_0
188+verify_special_syn_input_to_event :: Property IO
189+verify_special_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monadic $ do
190+ let table = function_keys_1 ++ function_keys_2
177191 input_seq = gen table
178192 events = [EvKey k ms | (_,(k,ms)) <- input_seq]
179193 keydowns = [Bytes s | (s,_) <- input_seq]
@@ -182,13 +196,15 @@ verify_fkeys_syn_input_to_event = forAll $ \(InputBlocksUsingTable gen) -> monad
182196
183197main :: IO ()
184198main = defaultMain
185− [ testProperty "basic block generated from a single ansi chars to event translation"
199+ [ testProperty "basic block generated from a single visible chars to event translation"
186200 verify_simple_input_block_to_event
187201 , testProperty "key sequences read from caps table map to expected events"
188202 verify_keys_from_caps_table_block_to_event
189− , testProperty "synthesized typing from basic blocks translates to expected events"
203+ , testProperty "synthesized typing from single visible chars translates to expected events"
190204 verify_simple_syn_input_to_event
191− , testProperty "synthesized typing from function keys translates to expected events"
192− verify_fkeys_syn_input_to_event
205+ , testProperty "synthesized typing from keys from capabilities tables translates to expected events"
206+ verify_caps_syn_input_to_event
207+ , testProperty "synthesized typing from hard coded special keys translates to expected events"
208+ verify_special_syn_input_to_event
193209 ]
194210