on master help sign in
refactor input layer a bit more. closer to testable
commit2e7bc4c3fcc1ca980dbcf08de2a1a6fb1e7770ef authorCorey O'Connor <corey@ooyala.com> dateSat 14 Sep 2013, 23:56 (13 years ago) parent207c508
28 files changed+146−147
src/Data/Terminfo/Eval.hs−1 src/Data/Terminfo/Parse.hs−1 src/Graphics/Vty/Debug.hs−1 src/Graphics/Vty/Debug/Image.hs−1 src/Graphics/Vty/Input.hs+91−96 src/Graphics/Vty/Input/Data.hs+14−15 src/Graphics/Vty/PictureToSpans.hs−1 src/Graphics/Vty/Span.hs−1 src/Graphics/Vty/Terminal.hs−1 src/Graphics/Vty/Terminal/Interface.hs−1 src/Graphics/Vty/Terminal/MacOSX.hs−2 src/Graphics/Vty/Terminal/TerminfoBased.hs−2 src/Graphics/Vty/Terminal/XTermColor.hs−5 test/Test.hs−1 test/Verify.hs+1−1 test/Verify/Data/Terminfo/Parse.hs−1 test/Verify/Graphics/Vty/DisplayRegion.hs−1 test/Verify/Graphics/Vty/Terminal.hs−1 test/VerifyEmptyImageProps.hs−1 test/VerifyEvalTerminfoCaps.hs−1 test/VerifyImageOps.hs−1 test/VerifyParseTerminfoCaps.hs−1 test/VerifyTerminal.hs−1 test/VerifyUsingMockInput.hs+18−4 test/VerifyUsingMockTerminal.hs−1 test/benchmark.hs−1 test/interactive_terminal_test.hs−1 vty.cabal+22−2
src/Data/Terminfo/Eval.hs−1
@@ -1,6 +1,5 @@
11{-# LANGUAGE MagicHash #-}
22{-# LANGUAGE BangPatterns #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
43{-# LANGUAGE RecordWildCards #-}
54{-# LANGUAGE FlexibleContexts #-}
65{-# LANGUAGE NoMonomorphismRestriction #-}
src/Data/Terminfo/Parse.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21{-# LANGUAGE BangPatterns #-}
32{-# LANGUAGE FlexibleContexts #-}
43{-# LANGUAGE NoMonomorphismRestriction #-}
src/Graphics/Vty/Debug.hs−1
@@ -1,5 +1,4 @@
11-- Copyright 2009-2010 Corey O'Connor
2−{-# LANGUAGE ScopedTypeVariables #-}
32module Graphics.Vty.Debug ( module Graphics.Vty.Debug
43 , module Graphics.Vty.Debug.Image
54 )
src/Graphics/Vty/Debug/Image.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module Graphics.Vty.Debug.Image where
32
43import Graphics.Vty.Image
src/Graphics/Vty/Input.hs+91−96
@@ -1,7 +1,4 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21-- Copyright 2009-2010 Corey O'Connor
3−{-# OPTIONS_GHC -Wall #-}
4−{-# LANGUAGE ForeignFunctionInterface #-}
52module Graphics.Vty.Input ( Key(..)
63 , Modifier(..)
74 , Button(..)
@@ -42,52 +39,40 @@ import Foreign ( alloca, poke, peek, Ptr )
4239-- events, and a function for shutting down the terminal access.
4340initTermInput :: Int -> Terminal -> IO (IO Event, IO ())
4441initTermInput escDelay terminal = do
45− eventChannel <- newChan
46− inputChannel <- newChan
47− hadInput <- newEmptyMVar
48− oattr <- getTerminalAttributes stdInput
49− let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
42+ eventChannel <- newChan
43+ inputChannel <- newChan
44+ hadInput <- newEmptyMVar
45+ oattr <- getTerminalAttributes stdInput
46+ let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
5047 , EnableEcho, ProcessInput, ExtendedFunctions
5148 ]
52− setTerminalAttributes stdInput nattr Immediately
53− set_term_timing
54− let inputToEventThread :: IO ()
55− inputToEventThread = loop []
56− where loop kb = case (classify kb) of
57− Prefix -> do c <- readChan inputChannel
58− loop (kb ++ [c])
59− Invalid -> do c <- readChan inputChannel
60− loop [c]
61− MisPfx k m s -> writeChan eventChannel (EvKey k m) >> loop s
62− Valid k m -> writeChan eventChannel (EvKey k m) >> loop ""
63−
64− finishAtomicInput = writeChan inputChannel '\xFFFE'
65−
66− inputThread :: IO ()
67− inputThread = do
68− _ <- alloca $ \(input_buffer :: Ptr Word8) -> do
69− let loop = do
70− setFdOption stdInput NonBlockingRead False
71− threadWaitRead stdInput
72− setFdOption stdInput NonBlockingRead True
73− _ <- try readAll :: IO (Either IOException ())
74− when (escDelay == 0) finishAtomicInput
75− loop
76− readAll = do
77− poke input_buffer 0
78− bytes_read <- fdReadBuf stdInput input_buffer 1
79− input_char <- fmap (chr . fromIntegral) $ peek input_buffer
80− when (bytes_read > 0) $ do
81− _ <- tryPutMVar hadInput () -- signal input
82− writeChan inputChannel input_char
83− readAll
84− loop
85− return ()
86−
87− -- | If there is no input for some time, this thread puts '\xFFFE' in the
88− -- inputChannel.
89− noInputThread :: IO ()
90− noInputThread = when (escDelay > 0) loop
49+ setTerminalAttributes stdInput nattr Immediately
50+ set_term_timing
51+ let finishAtomicInput = writeChan inputChannel '\xFFFE'
52+ inputThread :: IO ()
53+ inputThread = do
54+ _ <- alloca $ \(input_buffer :: Ptr Word8) -> do
55+ let loop = do
56+ setFdOption stdInput NonBlockingRead False
57+ threadWaitRead stdInput
58+ setFdOption stdInput NonBlockingRead True
59+ _ <- try readAll :: IO (Either IOException ())
60+ when (escDelay == 0) finishAtomicInput
61+ loop
62+ readAll = do
63+ poke input_buffer 0
64+ bytes_read <- fdReadBuf stdInput input_buffer 1
65+ input_char <- fmap (chr . fromIntegral) $ peek input_buffer
66+ when (bytes_read > 0) $ do
67+ _ <- tryPutMVar hadInput () -- signal input
68+ writeChan inputChannel input_char
69+ readAll
70+ loop
71+ return ()
72+ -- | If there is no input for some time, this thread puts '\xFFFE' in the
73+ -- inputChannel.
74+ noInputThread :: IO ()
75+ noInputThread = when (escDelay > 0) loop
9176 where loop = do
9277 takeMVar hadInput -- wait for some input
9378 threadDelay escDelay -- microseconds
@@ -97,55 +82,65 @@ initTermInput escDelay terminal = do
9782 finishAtomicInput
9883 loop
9984
100−
101− compile :: [[([Char],(Key,[Modifier]))]] -> [Char] -> KClass
102− compile lst = cl' where
103− lst' = concat lst
104− pfx = S.fromList $ concatMap (init . inits . fst) $ lst'
105− mlst = M.fromList lst'
106− cl' str = case S.member str pfx of
107− True -> Prefix
108− False -> case M.lookup str mlst of
109− Just (k,m) -> Valid k m
110− Nothing -> case head $ mapMaybe (\s -> (,) s `fmap` M.lookup s mlst) $ init $ inits str of
111− (s,(k,m)) -> MisPfx k m (drop (length s) str)
112−
113− -- ANSI specific bits
114−
115−
116− classify, classifyTab :: [Char] -> KClass
117−
118− -- As soon as
119− classify "\xFFFE" = Invalid
120− classify s@(c:_) | ord c >= 0xC2 =
121− if utf8Length (ord c) > length s then Prefix else classifyUtf8 s -- beginning of an utf8 sequence
122− classify other = classifyTab other
123−
124− classifyUtf8 s = case decode ((map (fromIntegral . ord) s) :: [Word8]) of
125− Just (unicodeChar, _) -> Valid (KASCII unicodeChar) []
126− _ -> Invalid -- something bad happened; just ignore and continue.
127−
128− classifyTab = compile (caps_classify_table : ansi_classify_table)
129−
130− caps_classify_table
131− = map_to_legacy_table [(x,y) | (Just x,y) <- map (first (getCapability terminal . tiGetStr)) $ caps_table]
132−
133− eventThreadId <- forkIO $ inputToEventThread
134− inputThreadId <- forkIO $ inputThread
135− noInputThreadId <- forkIO $ noInputThread
136− let pokeIO = (Catch $ do let e = error "(getsize in input layer)"
137− setTerminalAttributes stdInput nattr Immediately
138− writeChan eventChannel (EvResize e e))
139− _ <- installHandler windowChange pokeIO Nothing
140− _ <- installHandler continueProcess pokeIO Nothing
141− -- TODO(corey): killThread is a bit risky for my tastes.
142− let uninit = do killThread eventThreadId
143− killThread inputThreadId
144− killThread noInputThreadId
145− _ <- installHandler windowChange Ignore Nothing
146− _ <- installHandler continueProcess Ignore Nothing
147− setTerminalAttributes stdInput oattr Immediately
148− return (readChan eventChannel, uninit)
85+ extract_cap = first (getCapability terminal . tiGetStr)
86+ caps_classify_table = map_to_legacy_table [(x,y) | (Just x,y) <- map extract_cap caps_table]
87+ term_event_classify_table = concat $ caps_classify_table : ansi_classify_table
88+ term_event_classifier = classify term_event_classify_table
89+
90+ eventThreadId <- forkIO $ inputToEventThread term_event_classifier inputChannel eventChannel
91+ inputThreadId <- forkIO $ inputThread
92+ noInputThreadId <- forkIO $ noInputThread
93+ let pokeIO = Catch $ do
94+ let e = error "(getsize in input layer)"
95+ setTerminalAttributes stdInput nattr Immediately
96+ writeChan eventChannel (EvResize e e)
97+ _ <- installHandler windowChange pokeIO Nothing
98+ _ <- installHandler continueProcess pokeIO Nothing
99+ -- TODO(corey): killThread is a bit risky for my tastes.
100+ let uninit = do
101+ killThread eventThreadId
102+ killThread inputThreadId
103+ killThread noInputThreadId
104+ _ <- installHandler windowChange Ignore Nothing
105+ _ <- installHandler continueProcess Ignore Nothing
106+ setTerminalAttributes stdInput oattr Immediately
107+ return (readChan eventChannel, uninit)
108+
109+inputToEventThread :: (String -> KClass) -> Chan Char -> Chan Event -> IO ()
110+inputToEventThread classifier inputChannel eventChannel = loop []
111+ where loop kb = case (classifier kb) of
112+ Prefix -> do c <- readChan inputChannel
113+ loop (kb ++ [c])
114+ Invalid -> do c <- readChan inputChannel
115+ loop [c]
116+ MisPfx k m s -> writeChan eventChannel (EvKey k m) >> loop s
117+ Valid k m -> writeChan eventChannel (EvKey k m) >> loop ""
118+
119+compile :: ClassifyTable -> [Char] -> KClass
120+compile table = cl' where
121+ pfx = S.fromList $ concatMap (init . inits . fst) $ table
122+ mlst = M.fromList table
123+ cl' str = case S.member str pfx of
124+ True -> Prefix
125+ False -> case M.lookup str mlst of
126+ Just (k,m) -> Valid k m
127+ Nothing -> case head $ mapMaybe (\s -> (,) s `fmap` M.lookup s mlst) $ init $ inits str of
128+ (s,(k,m)) -> MisPfx k m (drop (length s) str)
129+
130+classify, classifyTab :: ClassifyTable -> [Char] -> KClass
131+
132+-- As soon as
133+classify _table "\xFFFE" = Invalid
134+classify _table s@(c:_) | ord c >= 0xC2
135+ = if utf8Length (ord c) > length s then Prefix else classifyUtf8 s -- beginning of an utf8 sequence
136+classify table other
137+ = classifyTab table other
138+
139+classifyUtf8 s = case decode ((map (fromIntegral . ord) s) :: [Word8]) of
140+ Just (unicodeChar, _) -> Valid (KASCII unicodeChar) []
141+ _ -> Invalid -- something bad happened; just ignore and continue.
142+
143+classifyTab table = compile table
149144
150145first :: (a -> b) -> (a,c) -> (b,c)
151146first f (x,y) = (f x, y)
src/Graphics/Vty/Input/Data.hs+14−15
@@ -1,5 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−{-# LANGUAGE ForeignFunctionInterface #-}
31-- Copyright Corey O'Connor
42module Graphics.Vty.Input.Data where
53
@@ -27,7 +25,8 @@ data Event = EvKey Key [Modifier] | EvMouse Int Int Button [Modifier]
2725data KClass = Valid Key [Modifier] | Invalid | Prefix | MisPfx Key [Modifier] [Char]
2826 deriving(Show)
2927
30−map_to_legacy_table :: [(String, Event)] -> [(String, (Key, [Modifier]))]
28+type ClassifyTable = [(String, (Key, [Modifier]))]
29+map_to_legacy_table :: [(String, Event)] -> ClassifyTable
3130map_to_legacy_table = map f
3231 where f (s, EvKey k mods) = (s, (k, mods))
3332 f _ = error "no mapping for mouse or resize events"
@@ -46,7 +45,7 @@ caps_table =
4645 , ("kRIT", EvKey KRight [MShift])
4746 ]
4847
49−nav_keys_0 :: [([Char], (Key, [Modifier]))]
48+nav_keys_0 :: ClassifyTable
5049nav_keys_0 =
5150 [ k "G" KNP5
5251 , k "P" KPause
@@ -61,7 +60,7 @@ nav_keys_0 =
6160 where k c s = ("\ESC["++c,(s,[]))
6261
6362-- Support for arrows and KHome/KEnd
64−nav_keys_1 :: [([Char], (Key, [Modifier]))]
63+nav_keys_1 :: ClassifyTable
6564nav_keys_1 =
6665 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
6766 | charCnt <- ["1;", ""], -- we can have a count or not
@@ -70,36 +69,36 @@ nav_keys_1 =
7069 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
7170 ]
7271
73−nav_keys_2 :: [([Char], (Key, [Modifier]))]
72+nav_keys_2 :: ClassifyTable
7473nav_keys_2 =
7574 let k n s = ("\ESC["++show n++"~",(s,[]))
7675 in zipWith k [2::Int,3,5,6,1,4]
7776 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
7877
79−nav_keys_3 :: [([Char], (Key, [Modifier]))]
78+nav_keys_3 :: ClassifyTable
8079nav_keys_3 =
8180 let k n s = ("\ESC["++show n++";5~",(s,[MCtrl]))
8281 in zipWith k [2::Int,3,5,6,1,4]
8382 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
8483
8584-- Support for simple characters.
86−simple_chars :: [([Char], (Key, [Modifier]))]
85+simple_chars :: ClassifyTable
8786simple_chars = [ (x:[],(KASCII x,[])) | x <- map toEnum [0..255] ]
8887
8988-- Support for function keys (should use terminfo)
90−function_keys_0 :: [([Char], (Key, [Modifier]))]
89+function_keys_0 :: ClassifyTable
9190function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
9291
93−function_keys_1 :: [([Char], (Key, [Modifier]))]
92+function_keys_1 :: ClassifyTable
9493function_keys_1 =
9594 let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
9695 concat [ f 6 [17..21] [], f 11 [23,24] [], f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
9796
98−function_keys_2 :: [([Char], (Key, [Modifier]))]
97+function_keys_2 :: ClassifyTable
9998function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\ESC':'\t':[' ' .. '\DEL'] ]
10099
101100-- Ctrl+Char
102−ctrl_char_keys :: [([Char], (Key, [Modifier]))]
101+ctrl_char_keys :: ClassifyTable
103102ctrl_char_keys =
104103 [ ([toEnum x],(KASCII y,[MCtrl]))
105104 | (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_']),
@@ -107,12 +106,12 @@ ctrl_char_keys =
107106 ]
108107
109108-- Ctrl+Meta+Char
110−ctrl_meta_keys :: [([Char], (Key, [Modifier]))]
109+ctrl_meta_keys :: ClassifyTable
111110ctrl_meta_keys =
112111 [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']) ]
113112
114113-- Special support
115−special_support_keys :: [([Char], (Key, [Modifier]))]
114+special_support_keys :: ClassifyTable
116115special_support_keys =
117116 [ -- special support for ESC
118117 ("\ESC",(KEsc,[])) , ("\ESC\ESC",(KEsc,[MMeta]))
@@ -123,7 +122,7 @@ special_support_keys =
123122 ]
124123
125124-- | classify table for ANSI terminals
126−ansi_classify_table :: [[([Char], (Key, [Modifier]))]]
125+ansi_classify_table :: [ClassifyTable]
127126ansi_classify_table =
128127 [ nav_keys_0
129128 , nav_keys_1
src/Graphics/Vty/PictureToSpans.hs−1
@@ -3,7 +3,6 @@
33{-# LANGUAGE TemplateHaskell #-}
44{-# LANGUAGE BangPatterns #-}
55{-# LANGUAGE ExistentialQuantification #-}
6−{-# LANGUAGE ScopedTypeVariables #-}
76{-# LANGUAGE NamedFieldPuns #-}
87{- | Transforms an image into rows of operations.
98 -}
src/Graphics/Vty/Span.hs−1
@@ -2,7 +2,6 @@
22{-# LANGUAGE BangPatterns #-}
33{-# LANGUAGE NamedFieldPuns #-}
44{-# LANGUAGE GADTs #-}
5−{-# LANGUAGE ScopedTypeVariables #-}
65{- | A picture is translated into a sequences of state changes and character spans.
76 - State changes are currently limited to new attribute values. The attribute is applied to all
87 - following spans. Including spans of the next row. The nth element of the sequence represents the
src/Graphics/Vty/Terminal.hs−1
@@ -18,7 +18,6 @@
1818-- control codes as possible.
1919--
2020-- Copyright 2009-2010 Corey O'Connor
21−{-# LANGUAGE ScopedTypeVariables #-}
2221module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
2322 , Terminal(..) -- \todo hide constructors
2423 , AssumedState(..)
src/Graphics/Vty/Terminal/Interface.hs−1
@@ -2,7 +2,6 @@
22-- General philosophy is: MonadIO is for equations exposed to clients.
33{-# LANGUAGE BangPatterns #-}
44{-# LANGUAGE RankNTypes #-}
5−{-# LANGUAGE ScopedTypeVariables #-}
65{-# LANGUAGE ExistentialQuantification #-}
76{-# LANGUAGE GADTs #-}
87{-# LANGUAGE FlexibleContexts #-}
src/Graphics/Vty/Terminal/MacOSX.hs−2
@@ -5,8 +5,6 @@
55--
66-- This terminal implementation modifies the standard terminfo terminal as required for complete OS
77-- X support.
8−{-# LANGUAGE ForeignFunctionInterface #-}
9−{-# LANGUAGE ScopedTypeVariables #-}
108{-# LANGUAGE MagicHash #-}
119{-# LANGUAGE FlexibleInstances #-}
1210{-# LANGUAGE TypeFamilies #-}
src/Graphics/Vty/Terminal/TerminfoBased.hs−2
@@ -5,8 +5,6 @@
55-- assumptions mixed in.
66--
77-- Copyright Corey O'Connor (coreyoconnor@gmail.com)
8−{-# LANGUAGE ForeignFunctionInterface #-}
9−{-# LANGUAGE ScopedTypeVariables #-}
108{-# LANGUAGE FlexibleInstances #-}
119{-# OPTIONS_GHC -D_XOPEN_SOURCE=500 #-}
1210module Graphics.Vty.Terminal.TerminfoBased ( reserve_terminal )
src/Graphics/Vty/Terminal/XTermColor.hs−5
@@ -1,9 +1,4 @@
11-- Copyright 2009-2010 Corey O'Connor
2−{-# LANGUAGE ForeignFunctionInterface #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4−{-# LANGUAGE MagicHash #-}
5−{-# LANGUAGE FlexibleInstances #-}
6−{-# LANGUAGE TypeFamilies #-}
72module Graphics.Vty.Terminal.XTermColor ( reserve_terminal )
83 where
94
test/Test.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module Main where
32
43import Graphics.Vty
test/Verify.hs+1−1
@@ -1,6 +1,6 @@
1+{-# LANGUAGE RankNTypes #-}
12{-# LANGUAGE GADTs #-}
23{-# LANGUAGE RecordWildCards #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE CPP #-}
55{-# LANGUAGE TypeSynonymInstances #-}
66{-# LANGUAGE FlexibleInstances #-}
test/Verify/Data/Terminfo/Parse.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module Verify.Data.Terminfo.Parse ( module Verify.Data.Terminfo.Parse
32 , module Data.Terminfo.Parse
43 )
test/Verify/Graphics/Vty/DisplayRegion.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module Verify.Graphics.Vty.DisplayRegion ( module Verify.Graphics.Vty.DisplayRegion
32 , module Graphics.Vty.DisplayRegion
43 , MockWindow(..)
test/Verify/Graphics/Vty/Terminal.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module Verify.Graphics.Vty.Terminal where
32
43import Graphics.Vty.Terminal.Mock
test/VerifyEmptyImageProps.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module VerifyEmptyImageProps where
32
43import Verify
test/VerifyEvalTerminfoCaps.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE BangPatterns #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
32{-# LANGUAGE NamedFieldPuns #-}
43module VerifyEvalTerminfoCaps where
54
test/VerifyImageOps.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module VerifyImageOps where
32
43import Graphics.Vty.Attributes
test/VerifyParseTerminfoCaps.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21{-# LANGUAGE NamedFieldPuns #-}
32module VerifyParseTerminfoCaps where
43
test/VerifyTerminal.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21{- We setup the environment to envoke certain terminals of interest.
32 - This assumes appropriate definitions exist in the current environment for the terminals of
43 - interest.
test/VerifyUsingMockInput.hs+18−4
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21{- We setup the environment to envoke certain terminals of interest.
32 - This assumes appropriate definitions exist in the current environment for the terminals of
43 - interest.
@@ -8,17 +7,32 @@ import Verify
87
98import Graphics.Vty
109
10+import Control.Concurrent
1111import Control.Monad
1212
1313import System.Posix.Env
1414import System.IO
1515
16−data InputSpec
17− = KeySeq String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
18− | Delay Int -- | millisecond delay
16+data InputEvent
17+ = Bytes String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
18+ | Delay Int -- | millisecond delay
19+
20+type InputSpec = [InputEvent]
1921
2022type ExpectedSpec = [Event]
2123
24+exec_input_spec :: InputSpec -> Handle -> IO ()
25+exec_input_spec input out_handle = forM_ input f
26+ where
27+ f (Bytes str) = hPutStr out_handle str >> hFlush out_handle
28+ f (Delay t) = threadDelay (t*1000)
29+
30+assert_events_from_IO_reads :: InputSpec -> ExpectedSpec -> IO Result
31+assert_events_from_IO_reads input events = undefined
32+
33+assert_events_from_input_block :: InputSpec -> ExpectedSpec -> Result
34+assert_events_from_input_block input events = undefined
35+
2236tests :: IO [Test]
2337tests = return []
2438
test/VerifyUsingMockTerminal.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
21module VerifyUsingMockTerminal where
32
43import Verify.Graphics.Vty.DisplayRegion
test/benchmark.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE QuasiQuotes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
32module Main where
43
54import Graphics.Vty
test/interactive_terminal_test.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE QuasiQuotes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
32module Main where
43
54import Graphics.Vty
vty.cabal+22−2
@@ -27,8 +27,7 @@ description:
2727 &#169; 2006-2007 Stefan O'Rear; BSD3 license.
2828 .
2929 &#169; Corey O'Connor; BSD3 license.
30−-- the test suites require >= 1.17.0
31−cabal-version: >= 1.14.0
30+cabal-version: >= 1.18.0
3231build-type: Simple
3332data-files: README.md,
3433 TODO,
@@ -38,6 +37,7 @@ data-files: README.md,
3837
3938library
4039 default-language: Haskell2010
40+ extensions: ScopedTypeVariables
4141 build-depends: base >= 4 && < 5,
4242 bytestring,
4343 containers,
@@ -90,6 +90,9 @@ library
9090
9191 hs-source-dirs: src
9292
93+ extensions: ScopedTypeVariables
94+ ForeignFunctionInterface
95+
9396 ghc-options: -O2 -funbox-strict-fields -Wall -fno-full-laziness -fspec-constr -fspec-constr-count=10
9497
9598 ghc-prof-options: -O2 -funbox-strict-fields -caf-all -Wall -fno-full-laziness -fspec-constr -fspec-constr-count=10
@@ -98,6 +101,7 @@ library
98101
99102test-suite verify-attribute-ops
100103 default-language: Haskell2010
104+ extensions: ScopedTypeVariables
101105 type: detailed-0.9
102106 hs-source-dirs: test
103107 test-module: VerifyAttributeOps
@@ -117,6 +121,7 @@ test-suite verify-attribute-ops
117121
118122test-suite verify-using-mock-terminal
119123 default-language: Haskell2010
124+ extensions: ScopedTypeVariables
120125
121126 type: detailed-0.9
122127
@@ -148,6 +153,7 @@ test-suite verify-using-mock-terminal
148153
149154test-suite verify-terminal
150155 default-language: Haskell2010
156+ extensions: ScopedTypeVariables
151157
152158 type: detailed-0.9
153159
@@ -180,6 +186,7 @@ test-suite verify-terminal
180186
181187test-suite verify-display-attributes
182188 default-language: Haskell2010
189+ extensions: ScopedTypeVariables
183190
184191 type: detailed-0.9
185192
@@ -210,6 +217,7 @@ test-suite verify-display-attributes
210217
211218test-suite verify-empty-image-props
212219 default-language: Haskell2010
220+ extensions: ScopedTypeVariables
213221
214222 type: detailed-0.9
215223
@@ -235,6 +243,7 @@ test-suite verify-empty-image-props
235243
236244test-suite verify-eval-terminfo-caps
237245 default-language: Haskell2010
246+ extensions: ScopedTypeVariables
238247
239248 type: detailed-0.9
240249
@@ -261,6 +270,7 @@ test-suite verify-eval-terminfo-caps
261270
262271test-suite verify-image-ops
263272 default-language: Haskell2010
273+ extensions: ScopedTypeVariables
264274
265275 type: detailed-0.9
266276
@@ -288,6 +298,7 @@ test-suite verify-image-ops
288298
289299test-suite verify-image-trans
290300 default-language: Haskell2010
301+ extensions: ScopedTypeVariables
291302
292303 type: detailed-0.9
293304
@@ -315,6 +326,7 @@ test-suite verify-image-trans
315326
316327test-suite verify-inline
317328 default-language: Haskell2010
329+ extensions: ScopedTypeVariables
318330
319331 type: detailed-0.9
320332
@@ -341,6 +353,7 @@ test-suite verify-inline
341353
342354test-suite verify-parse-terminfo-caps
343355 default-language: Haskell2010
356+ extensions: ScopedTypeVariables
344357
345358 type: detailed-0.9
346359
@@ -368,6 +381,7 @@ test-suite verify-parse-terminfo-caps
368381
369382test-suite verify-simple-span-generation
370383 default-language: Haskell2010
384+ extensions: ScopedTypeVariables
371385
372386 type: detailed-0.9
373387
@@ -399,6 +413,7 @@ test-suite verify-simple-span-generation
399413
400414test-suite verify-crop-span-generation
401415 default-language: Haskell2010
416+ extensions: ScopedTypeVariables
402417
403418 type: detailed-0.9
404419
@@ -430,6 +445,7 @@ test-suite verify-crop-span-generation
430445
431446test-suite verify-layers-span-generation
432447 default-language: Haskell2010
448+ extensions: ScopedTypeVariables
433449
434450 type: detailed-0.9
435451
@@ -460,6 +476,7 @@ test-suite verify-layers-span-generation
460476
461477test-suite verify-utf8-width
462478 default-language: Haskell2010
479+ extensions: ScopedTypeVariables
463480
464481 type: detailed-0.9
465482
@@ -485,6 +502,7 @@ test-suite verify-utf8-width
485502
486503test-suite verify-using-mock-input
487504 default-language: Haskell2010
505+ extensions: ScopedTypeVariables
488506
489507 type: detailed-0.9
490508
@@ -513,6 +531,7 @@ executable vty-interactive-terminal-test
513531 main-is: interactive_terminal_test.hs
514532
515533 default-language: Haskell2010
534+ extensions: ScopedTypeVariables
516535
517536 hs-source-dirs: test
518537
@@ -537,6 +556,7 @@ executable vty-benchmark
537556 main-is: benchmark.hs
538557
539558 default-language: Haskell2010
559+ extensions: ScopedTypeVariables
540560
541561 hs-source-dirs: test
542562