on master help sign in
cleanup
commit424e6a858dfb378597e3485f76aefc00d9447e3b authorCorey O'Connor <corey@ooyala.com> dateSun 13 Oct 2013, 03:01 (13 years ago) parentdc74901
8 files changed+38−98
src/Graphics/Vty/Input.hs+4−4 src/Graphics/Vty/Input/Data.hs+2−2 test/Verify.hs+3 test/Verify/Graphics/Vty/Terminal.hs+4−1 test/VerifyEvalTerminfoCaps.hs+1−41 test/VerifyParseTerminfoCaps.hs+2−42 test/VerifyUsingMockInput.hs+19−8 vty.cabal+3
src/Graphics/Vty/Input.hs+4−4
@@ -22,9 +22,9 @@ import System.Console.Terminfo
2222import System.Posix.Signals.Exts
2323import System.Posix.Terminal
2424import System.Posix.IO ( stdInput
25− ,fdReadBuf
26− ,setFdOption
27− ,FdOption(..)
25+ , fdReadBuf
26+ , setFdOption
27+ , FdOption(..)
2828 )
2929
3030import Foreign ( alloca, poke, peek, Ptr )
@@ -77,7 +77,7 @@ initTermInput escDelay terminal = do
7777 loop
7878
7979 extract_cap = first (getCapability terminal . tiGetStr)
80− caps_classify_table = map_to_legacy_table [(x,y) | (Just x,y) <- map extract_cap caps_table]
80+ caps_classify_table = map_to_legacy_table [(x,y) | (Just x,y) <- map extract_cap keys_from_caps_table]
8181 term_event_classify_table = concat $ caps_classify_table : ansi_classify_table
8282 term_event_classifier = classify term_event_classify_table
8383
src/Graphics/Vty/Input/Data.hs+2−2
@@ -38,8 +38,8 @@ map_to_legacy_table = map f
3838 f _ = error "no mapping for mouse or resize events"
3939
4040-- | classify table directly generated from terminfo cap strings
41−caps_table :: [(String, Event)]
42−caps_table =
41+keys_from_caps_table :: [(String, Event)]
42+keys_from_caps_table =
4343 [ ("khome", EvKey KHome [])
4444 , ("kend", EvKey KEnd [])
4545 , ("cbt", EvKey KBackTab [])
test/Verify.hs+3
@@ -14,6 +14,7 @@ module Verify ( module Verify
1414 , module Control.Monad
1515 , module Test.QuickCheck
1616 , module Test.QuickCheck.Modifiers
17+ , module Text.Printf
1718 , succeeded
1819 , failed
1920 , result
@@ -37,6 +38,8 @@ import Test.QuickCheck.Property hiding ( Result(..) )
3738import qualified Test.QuickCheck.Property as Prop
3839import Test.QuickCheck.Monadic ( monadicIO )
3940
41+import Text.Printf
42+
4043import qualified Codec.Binary.UTF8.String as UTF8
4144
4245import Control.Applicative hiding ( (<|>) )
test/Verify/Graphics/Vty/Terminal.hs+4−1
@@ -8,9 +8,12 @@ import qualified Data.String.UTF8 as UTF8
88
99import Test.QuickCheck.Property
1010
11+import Verify
12+
1113-- A list of terminals that should be supported.
1214-- This started with a list of terminals ubuntu supported. Then those terminals that really could
13−-- not be supported were removed.
15+-- not be supported were removed. Then a few more were pruned until a reasonable looking set was
16+-- made.
1417terminals_of_interest =
1518 [ "vt100"
1619 , "vt220"
test/VerifyEvalTerminfoCaps.hs+1−41
@@ -11,6 +11,7 @@ import Control.DeepSeq
1111import qualified System.Console.Terminfo as Terminfo
1212
1313import Verify
14+import Verify.Graphics.Vty.Terminal
1415
1516import Control.Applicative ( (<$>) )
1617import Control.Exception ( try, SomeException(..) )
@@ -22,47 +23,6 @@ import Data.Word
2223
2324import Numeric
2425
25−-- A list of terminals that ubuntu includes a terminfo cap file for.
26−-- Assuming that is a good place to start.
27−terminals_of_interest =
28− [ "wsvt25"
29− , "wsvt25m"
30− , "vt52"
31− , "vt100"
32− , "vt220"
33− , "vt102"
34− , "xterm-r5"
35− , "xterm-xfree86"
36− , "xterm-r6"
37− , "xterm-256color"
38− , "xterm-vt220"
39− , "xterm-debian"
40− , "xterm-mono"
41− , "xterm-color"
42− , "xterm"
43− , "mach"
44− , "mach-bold"
45− , "mach-color"
46− , "linux"
47− , "ansi"
48− , "hurd"
49− , "Eterm"
50− , "pcansi"
51− , "screen-256color"
52− , "screen-bce"
53− , "screen-s"
54− , "screen-w"
55− , "screen"
56− , "screen-256color-bce"
57− , "sun"
58− , "rxvt"
59− , "rxvt-unicode"
60− , "rxvt-basic"
61− , "cygwin"
62− , "cons25"
63− , "dumb"
64− ]
65−
6626-- If a terminal defines one of the caps then it's expected to be parsable.
6727caps_of_interest =
6828 [ "cup"
test/VerifyParseTerminfoCaps.hs+2−42
@@ -6,6 +6,7 @@ import Prelude hiding ( catch )
66import qualified System.Console.Terminfo as Terminfo
77
88import Verify.Data.Terminfo.Parse
9+import Verify.Graphics.Vty.Terminal
910import Verify
1011
1112import Data.Maybe ( catMaybes, fromJust )
@@ -13,48 +14,8 @@ import Data.Word
1314
1415import Numeric
1516
16−-- A list of terminals that ubuntu includes a terminfo cap file for.
17−-- Assuming that is a good place to start.
18−terminals_of_interest =
19− [ "wsvt25"
20− , "wsvt25m"
21− , "vt52"
22− , "vt100"
23− , "vt220"
24− , "vt102"
25− , "xterm-r5"
26− , "xterm-xfree86"
27− , "xterm-r6"
28− , "xterm-256color"
29− , "xterm-vt220"
30− , "xterm-debian"
31− , "xterm-mono"
32− , "xterm-color"
33− , "xterm"
34− , "mach"
35− , "mach-bold"
36− , "mach-color"
37− , "linux"
38− , "ansi"
39− , "hurd"
40− , "Eterm"
41− , "pcansi"
42− , "screen-256color"
43− , "screen-bce"
44− , "screen-s"
45− , "screen-w"
46− , "screen"
47− , "screen-256color-bce"
48− , "sun"
49− , "rxvt"
50− , "rxvt-unicode"
51− , "rxvt-basic"
52− , "cygwin"
53− , "cons25"
54− , "dumb"
55− ]
56−
5717-- If a terminal defines one of the caps then it's expected to be parsable.
18+-- TODO: reduce duplication with terminfo terminal implementation.
5819caps_of_interest =
5920 [ "cup"
6021 , "sc"
@@ -80,7 +41,6 @@ from_capname ti name = fromJust $ Terminfo.getCapability ti (Terminfo.tiGetStr n
8041tests :: IO [Test]
8142tests = do
8243 parse_tests <- concat <$> forM terminals_of_interest ( \term_name -> do
83− putStrLn $ "testing parsing of caps for terminal: " ++ term_name
8444 mti <- liftIO $ try $ Terminfo.setupTerm term_name
8545 case mti of
8646 Left (_e :: SomeException)
test/VerifyUsingMockInput.hs+19−8
@@ -5,6 +5,8 @@
55module VerifyUsingMockInput where
66import Verify hiding (classify)
77
8+import Verify.Graphics.Vty.Terminal
9+
810import Graphics.Vty hiding (resize)
911import Graphics.Vty.Input
1012import Graphics.Vty.Input.Data
@@ -46,12 +48,15 @@ assert_events_from_input_block table input_spec expected_events = do
4648 input <- newChan
4749 output <- newChan
4850 forkIO $ write_input_spec_to_chan input input_spec
49− handle (\(e :: BlockedIndefinitelyOnMVar) ->
50− return $ failed { reason = show expected_events ++ " -> " ++ show e }
51− ) $ do
52− inputToEventThread classifier input output
53− out_events <- replicateM (length expected_events) (readChan output)
54− return $ out_events ?== expected_events
51+ inputToEventThread classifier input output
52+ -- H: all events are available in output channel
53+ -- TODO: switch to using explicit control events. Currently the channel is passing around a
54+ -- magic FFFX characters
55+ -- TODO: use STM channel
56+ let collect_events = handle (\(e :: BlockedIndefinitelyOnMVar) -> return [])
57+ ((:) <$> readChan output <*> collect_events)
58+ out_events <- collect_events
59+ return $ out_events ?== expected_events
5560
5661write_input_spec_to_chan :: Chan Char -> InputSpec -> IO ()
5762write_input_spec_to_chan chan [] = writeChan chan '\xFFFD'
@@ -62,15 +67,21 @@ write_input_spec_to_chan chan (Delay t : input_spec')
6267
6368verify_simple_input_block_to_event :: Property
6469verify_simple_input_block_to_event = do
70+ -- Ouch! 16 is as high as this can go without taking far too long. :-\
6571 Positive block_length <- resize 16 $ arbitrary
6672 block_event_pairs <- vectorOf block_length $ elements $ simple_chars
6773 let input = [Bytes $ concatMap fst block_event_pairs]
6874 events = map (\(k,ms) -> EvKey k ms) $ map snd block_event_pairs
6975 morallyDubiousIOProperty $ assert_events_from_input_block simple_chars input events
7076
77+verify_keys_from_caps_table :: String -> Result
78+verify_keys_from_caps_table term_name = succeeded
79+
7180tests :: IO [Test]
7281tests = return
73− [ verify "basic block generated from ansi table to event translation"
74− verify_simple_input_block_to_event
82+ [ verify "basic block generated from single ansi chars to event translation"
83+ verify_simple_input_block_to_event
84+ , verify "keys from caps table are parsed to the same key"
85+ verify_keys_from_caps_table
7586 ]
7687
vty.cabal+3
@@ -148,6 +148,7 @@ test-suite verify-using-mock-terminal
148148 deepseq >= 1.1 && < 1.4,
149149 mtl >= 1.1.1.0 && < 2.2,
150150 text >= 0.11.3,
151+ terminfo,
151152 unix,
152153 utf8-string >= 0.3 && < 0.4,
153154 vector >= 0.7
@@ -253,6 +254,7 @@ test-suite verify-eval-terminfo-caps
253254 test-module: VerifyEvalTerminfoCaps
254255
255256 other-modules: Verify
257+ Verify.Graphics.Vty.Terminal
256258
257259 build-depends: vty,
258260 Cabal == 1.18.*,
@@ -364,6 +366,7 @@ test-suite verify-parse-terminfo-caps
364366
365367 other-modules: Verify
366368 Verify.Data.Terminfo.Parse
369+ Verify.Graphics.Vty.Terminal
367370
368371 build-depends: vty,
369372 Cabal == 1.18.*,