on master help sign in
refactor input layer a bit more. closer to testable
2e7bc4cCorey O'Connor
src/Data/Terminfo/Eval.hs−1
@@ -1,6 +1,5 @@
1{-# LANGUAGE MagicHash #-}
1{-# LANGUAGE MagicHash #-}
2{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE BangPatterns #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE RecordWildCards #-}
5{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
6{-# LANGUAGE NoMonomorphismRestriction #-}
5{-# LANGUAGE NoMonomorphismRestriction #-}
src/Data/Terminfo/Parse.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE BangPatterns #-}
1{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE NoMonomorphismRestriction #-}
3{-# LANGUAGE NoMonomorphismRestriction #-}
src/Graphics/Vty/Debug.hs−1
@@ -1,5 +1,4 @@
1-- Copyright 2009-2010 Corey O'Connor
1-- Copyright 2009-2010 Corey O'Connor
2−{-# LANGUAGE ScopedTypeVariables #-}
3module Graphics.Vty.Debug ( module Graphics.Vty.Debug
2module Graphics.Vty.Debug ( module Graphics.Vty.Debug
4 , module Graphics.Vty.Debug.Image
3 , module Graphics.Vty.Debug.Image
5 )
4 )
src/Graphics/Vty/Debug/Image.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module Graphics.Vty.Debug.Image where
1module Graphics.Vty.Debug.Image where
3
2
4import Graphics.Vty.Image
3import Graphics.Vty.Image
src/Graphics/Vty/Input.hs+91−96
@@ -1,7 +1,4 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2-- Copyright 2009-2010 Corey O'Connor
1-- Copyright 2009-2010 Corey O'Connor
3−{-# OPTIONS_GHC -Wall #-}
4−{-# LANGUAGE ForeignFunctionInterface #-}
5module Graphics.Vty.Input ( Key(..)
2module Graphics.Vty.Input ( Key(..)
6 , Modifier(..)
3 , Modifier(..)
7 , Button(..)
4 , Button(..)
@@ -42,52 +39,40 @@ import Foreign ( alloca, poke, peek, Ptr )
42-- events, and a function for shutting down the terminal access.
39-- events, and a function for shutting down the terminal access.
43initTermInput :: Int -> Terminal -> IO (IO Event, IO ())
40initTermInput :: Int -> Terminal -> IO (IO Event, IO ())
44initTermInput escDelay terminal = do
41initTermInput escDelay terminal = do
45− eventChannel <- newChan
42+ eventChannel <- newChan
46− inputChannel <- newChan
43+ inputChannel <- newChan
47− hadInput <- newEmptyMVar
44+ hadInput <- newEmptyMVar
48− oattr <- getTerminalAttributes stdInput
45+ oattr <- getTerminalAttributes stdInput
49− let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
46+ let nattr = foldl withoutMode oattr [ StartStopOutput, KeyboardInterrupts
50 , EnableEcho, ProcessInput, ExtendedFunctions
47 , EnableEcho, ProcessInput, ExtendedFunctions
51 ]
48 ]
52− setTerminalAttributes stdInput nattr Immediately
49+ setTerminalAttributes stdInput nattr Immediately
53− set_term_timing
50+ 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'
51+ let finishAtomicInput = writeChan inputChannel '\xFFFE'
65−
66− inputThread :: IO ()
52+ inputThread :: IO ()
67− inputThread = do
53+ inputThread = do
68− _ <- alloca $ \(input_buffer :: Ptr Word8) -> do
54+ _ <- alloca $ \(input_buffer :: Ptr Word8) -> do
69− let loop = do
55+ let loop = do
70− setFdOption stdInput NonBlockingRead False
56+ setFdOption stdInput NonBlockingRead False
71− threadWaitRead stdInput
57+ threadWaitRead stdInput
72− setFdOption stdInput NonBlockingRead True
58+ setFdOption stdInput NonBlockingRead True
73− _ <- try readAll :: IO (Either IOException ())
59+ _ <- try readAll :: IO (Either IOException ())
74− when (escDelay == 0) finishAtomicInput
60+ when (escDelay == 0) finishAtomicInput
75− loop
61+ loop
76− readAll = do
62+ readAll = do
77− poke input_buffer 0
63+ poke input_buffer 0
78− bytes_read <- fdReadBuf stdInput input_buffer 1
64+ bytes_read <- fdReadBuf stdInput input_buffer 1
79− input_char <- fmap (chr . fromIntegral) $ peek input_buffer
65+ input_char <- fmap (chr . fromIntegral) $ peek input_buffer
80− when (bytes_read > 0) $ do
66+ when (bytes_read > 0) $ do
81− _ <- tryPutMVar hadInput () -- signal input
67+ _ <- tryPutMVar hadInput () -- signal input
82− writeChan inputChannel input_char
68+ writeChan inputChannel input_char
83− readAll
69+ readAll
84− loop
70+ loop
85− return ()
71+ return ()
86−
87− -- | If there is no input for some time, this thread puts '\xFFFE' in the
72+ -- | If there is no input for some time, this thread puts '\xFFFE' in the
88− -- inputChannel.
73+ -- inputChannel.
89− noInputThread :: IO ()
74+ noInputThread :: IO ()
90− noInputThread = when (escDelay > 0) loop
75+ noInputThread = when (escDelay > 0) loop
91 where loop = do
76 where loop = do
92 takeMVar hadInput -- wait for some input
77 takeMVar hadInput -- wait for some input
93 threadDelay escDelay -- microseconds
78 threadDelay escDelay -- microseconds
@@ -97,55 +82,65 @@ initTermInput escDelay terminal = do
97 finishAtomicInput
82 finishAtomicInput
98 loop
83 loop
99
84
100−
85+ extract_cap = first (getCapability terminal . tiGetStr)
101− compile :: [[([Char],(Key,[Modifier]))]] -> [Char] -> KClass
86+ caps_classify_table = map_to_legacy_table [(x,y) | (Just x,y) <- map extract_cap caps_table]
102− compile lst = cl' where
87+ term_event_classify_table = concat $ caps_classify_table : ansi_classify_table
103− lst' = concat lst
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
104− pfx = S.fromList $ concatMap (init . inits . fst) $ lst'
121+ pfx = S.fromList $ concatMap (init . inits . fst) $ table
105− mlst = M.fromList lst'
122+ mlst = M.fromList table
106− cl' str = case S.member str pfx of
123+ cl' str = case S.member str pfx of
107− True -> Prefix
124+ True -> Prefix
108− False -> case M.lookup str mlst of
125+ False -> case M.lookup str mlst of
109− Just (k,m) -> Valid k m
126+ Just (k,m) -> Valid k m
110− Nothing -> case head $ mapMaybe (\s -> (,) s `fmap` M.lookup s mlst) $ init $ inits str of
127+ 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)
128+ (s,(k,m)) -> MisPfx k m (drop (length s) str)
112−
129+
113− -- ANSI specific bits
114−
115−
116− classify, classifyTab :: [Char] -> KClass
130+classify, classifyTab :: ClassifyTable -> [Char] -> KClass
117−
131+
118− -- As soon as
132+-- As soon as
119− classify "\xFFFE" = Invalid
133+classify _table "\xFFFE" = Invalid
120− classify s@(c:_) | ord c >= 0xC2 =
134+classify _table s@(c:_) | ord c >= 0xC2
121− if utf8Length (ord c) > length s then Prefix else classifyUtf8 s -- beginning of an utf8 sequence
135+ = if utf8Length (ord c) > length s then Prefix else classifyUtf8 s -- beginning of an utf8 sequence
136+classify table other
122− classify other = classifyTab other
137+ = classifyTab table other
123−
138+
124− classifyUtf8 s = case decode ((map (fromIntegral . ord) s) :: [Word8]) of
139+classifyUtf8 s = case decode ((map (fromIntegral . ord) s) :: [Word8]) of
125− Just (unicodeChar, _) -> Valid (KASCII unicodeChar) []
140+ Just (unicodeChar, _) -> Valid (KASCII unicodeChar) []
126− _ -> Invalid -- something bad happened; just ignore and continue.
141+ _ -> Invalid -- something bad happened; just ignore and continue.
127−
142+
128− classifyTab = compile (caps_classify_table : ansi_classify_table)
143+classifyTab table = compile 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)
149
144
150first :: (a -> b) -> (a,c) -> (b,c)
145first :: (a -> b) -> (a,c) -> (b,c)
151first f (x,y) = (f x, y)
146first f (x,y) = (f x, y)
src/Graphics/Vty/Input/Data.hs+14−15
@@ -1,5 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−{-# LANGUAGE ForeignFunctionInterface #-}
3-- Copyright Corey O'Connor
1-- Copyright Corey O'Connor
4module Graphics.Vty.Input.Data where
2module Graphics.Vty.Input.Data where
5
3
@@ -27,7 +25,8 @@ data Event = EvKey Key [Modifier] | EvMouse Int Int Button [Modifier]
27data KClass = Valid Key [Modifier] | Invalid | Prefix | MisPfx Key [Modifier] [Char]
25data KClass = Valid Key [Modifier] | Invalid | Prefix | MisPfx Key [Modifier] [Char]
28 deriving(Show)
26 deriving(Show)
29
27
28+type ClassifyTable = [(String, (Key, [Modifier]))]
30−map_to_legacy_table :: [(String, Event)] -> [(String, (Key, [Modifier]))]
29+map_to_legacy_table :: [(String, Event)] -> ClassifyTable
31map_to_legacy_table = map f
30map_to_legacy_table = map f
32 where f (s, EvKey k mods) = (s, (k, mods))
31 where f (s, EvKey k mods) = (s, (k, mods))
33 f _ = error "no mapping for mouse or resize events"
32 f _ = error "no mapping for mouse or resize events"
@@ -46,7 +45,7 @@ caps_table =
46 , ("kRIT", EvKey KRight [MShift])
45 , ("kRIT", EvKey KRight [MShift])
47 ]
46 ]
48
47
49−nav_keys_0 :: [([Char], (Key, [Modifier]))]
48+nav_keys_0 :: ClassifyTable
50nav_keys_0 =
49nav_keys_0 =
51 [ k "G" KNP5
50 [ k "G" KNP5
52 , k "P" KPause
51 , k "P" KPause
@@ -61,7 +60,7 @@ nav_keys_0 =
61 where k c s = ("\ESC["++c,(s,[]))
60 where k c s = ("\ESC["++c,(s,[]))
62
61
63-- Support for arrows and KHome/KEnd
62-- Support for arrows and KHome/KEnd
64−nav_keys_1 :: [([Char], (Key, [Modifier]))]
63+nav_keys_1 :: ClassifyTable
65nav_keys_1 =
64nav_keys_1 =
66 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
65 [("\ESC[" ++ charCnt ++ show mc++c,(s,m))
67 | charCnt <- ["1;", ""], -- we can have a count or not
66 | charCnt <- ["1;", ""], -- we can have a count or not
@@ -70,36 +69,36 @@ nav_keys_1 =
70 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
69 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
71 ]
70 ]
72
71
73−nav_keys_2 :: [([Char], (Key, [Modifier]))]
72+nav_keys_2 :: ClassifyTable
74nav_keys_2 =
73nav_keys_2 =
75 let k n s = ("\ESC["++show n++"~",(s,[]))
74 let k n s = ("\ESC["++show n++"~",(s,[]))
76 in zipWith k [2::Int,3,5,6,1,4]
75 in zipWith k [2::Int,3,5,6,1,4]
77 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
76 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
78
77
79−nav_keys_3 :: [([Char], (Key, [Modifier]))]
78+nav_keys_3 :: ClassifyTable
80nav_keys_3 =
79nav_keys_3 =
81 let k n s = ("\ESC["++show n++";5~",(s,[MCtrl]))
80 let k n s = ("\ESC["++show n++";5~",(s,[MCtrl]))
82 in zipWith k [2::Int,3,5,6,1,4]
81 in zipWith k [2::Int,3,5,6,1,4]
83 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
82 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
84
83
85-- Support for simple characters.
84-- Support for simple characters.
86−simple_chars :: [([Char], (Key, [Modifier]))]
85+simple_chars :: ClassifyTable
87simple_chars = [ (x:[],(KASCII x,[])) | x <- map toEnum [0..255] ]
86simple_chars = [ (x:[],(KASCII x,[])) | x <- map toEnum [0..255] ]
88
87
89-- Support for function keys (should use terminfo)
88-- Support for function keys (should use terminfo)
90−function_keys_0 :: [([Char], (Key, [Modifier]))]
89+function_keys_0 :: ClassifyTable
91function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
90function_keys_0 = [ ("\ESC[["++[toEnum(64+i)],(KFun i,[])) | i <- [1..5] ]
92
91
93−function_keys_1 :: [([Char], (Key, [Modifier]))]
92+function_keys_1 :: ClassifyTable
94function_keys_1 =
93function_keys_1 =
95 let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
94 let f ff nrs m = [ ("\ESC["++show n++"~",(KFun (n-(nrs!!0)+ff), m)) | n <- nrs ] in
96 concat [ f 6 [17..21] [], f 11 [23,24] [], f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
95 concat [ f 6 [17..21] [], f 11 [23,24] [], f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
97
96
98−function_keys_2 :: [([Char], (Key, [Modifier]))]
97+function_keys_2 :: ClassifyTable
99function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\ESC':'\t':[' ' .. '\DEL'] ]
98function_keys_2 = [ ('\ESC':[x],(KASCII x,[MMeta])) | x <- '\ESC':'\t':[' ' .. '\DEL'] ]
100
99
101-- Ctrl+Char
100-- Ctrl+Char
102−ctrl_char_keys :: [([Char], (Key, [Modifier]))]
101+ctrl_char_keys :: ClassifyTable
103ctrl_char_keys =
102ctrl_char_keys =
104 [ ([toEnum x],(KASCII y,[MCtrl]))
103 [ ([toEnum x],(KASCII y,[MCtrl]))
105 | (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_']),
104 | (x,y) <- zip ([0..31]) ('@':['a'..'z']++['['..'_']),
@@ -107,12 +106,12 @@ ctrl_char_keys =
107 ]
106 ]
108
107
109-- Ctrl+Meta+Char
108-- Ctrl+Meta+Char
110−ctrl_meta_keys :: [([Char], (Key, [Modifier]))]
109+ctrl_meta_keys :: ClassifyTable
111ctrl_meta_keys =
110ctrl_meta_keys =
112 [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']) ]
111 [ ('\ESC':[toEnum x],(KASCII y,[MMeta,MCtrl])) | (x,y) <- zip [0..31] ('@':['a'..'z']++['['..'_']) ]
113
112
114-- Special support
113-- Special support
115−special_support_keys :: [([Char], (Key, [Modifier]))]
114+special_support_keys :: ClassifyTable
116special_support_keys =
115special_support_keys =
117 [ -- special support for ESC
116 [ -- special support for ESC
118 ("\ESC",(KEsc,[])) , ("\ESC\ESC",(KEsc,[MMeta]))
117 ("\ESC",(KEsc,[])) , ("\ESC\ESC",(KEsc,[MMeta]))
@@ -123,7 +122,7 @@ special_support_keys =
123 ]
122 ]
124
123
125-- | classify table for ANSI terminals
124-- | classify table for ANSI terminals
126−ansi_classify_table :: [[([Char], (Key, [Modifier]))]]
125+ansi_classify_table :: [ClassifyTable]
127ansi_classify_table =
126ansi_classify_table =
128 [ nav_keys_0
127 [ nav_keys_0
129 , nav_keys_1
128 , nav_keys_1
src/Graphics/Vty/PictureToSpans.hs−1
@@ -3,7 +3,6 @@
3{-# LANGUAGE TemplateHaskell #-}
3{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE BangPatterns #-}
4{-# LANGUAGE BangPatterns #-}
5{-# LANGUAGE ExistentialQuantification #-}
5{-# LANGUAGE ExistentialQuantification #-}
6−{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE NamedFieldPuns #-}
6{-# LANGUAGE NamedFieldPuns #-}
8{- | Transforms an image into rows of operations.
7{- | Transforms an image into rows of operations.
9 -}
8 -}
src/Graphics/Vty/Span.hs−1
@@ -2,7 +2,6 @@
2{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE NamedFieldPuns #-}
3{-# LANGUAGE NamedFieldPuns #-}
4{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
5−{-# LANGUAGE ScopedTypeVariables #-}
6{- | A picture is translated into a sequences of state changes and character spans.
5{- | A picture is translated into a sequences of state changes and character spans.
7 - State changes are currently limited to new attribute values. The attribute is applied to all
6 - State changes are currently limited to new attribute values. The attribute is applied to all
8 - following spans. Including spans of the next row. The nth element of the sequence represents the
7 - 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 @@
18-- control codes as possible.
18-- control codes as possible.
19--
19--
20-- Copyright 2009-2010 Corey O'Connor
20-- Copyright 2009-2010 Corey O'Connor
21−{-# LANGUAGE ScopedTypeVariables #-}
22module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
21module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
23 , Terminal(..) -- \todo hide constructors
22 , Terminal(..) -- \todo hide constructors
24 , AssumedState(..)
23 , AssumedState(..)
src/Graphics/Vty/Terminal/Interface.hs−1
@@ -2,7 +2,6 @@
2-- General philosophy is: MonadIO is for equations exposed to clients.
2-- General philosophy is: MonadIO is for equations exposed to clients.
3{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE BangPatterns #-}
4{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE RankNTypes #-}
5−{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE ExistentialQuantification #-}
5{-# LANGUAGE ExistentialQuantification #-}
7{-# LANGUAGE GADTs #-}
6{-# LANGUAGE GADTs #-}
8{-# LANGUAGE FlexibleContexts #-}
7{-# LANGUAGE FlexibleContexts #-}
src/Graphics/Vty/Terminal/MacOSX.hs−2
@@ -5,8 +5,6 @@
5--
5--
6-- This terminal implementation modifies the standard terminfo terminal as required for complete OS
6-- This terminal implementation modifies the standard terminfo terminal as required for complete OS
7-- X support.
7-- X support.
8−{-# LANGUAGE ForeignFunctionInterface #-}
9−{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE MagicHash #-}
8{-# LANGUAGE MagicHash #-}
11{-# LANGUAGE FlexibleInstances #-}
9{-# LANGUAGE FlexibleInstances #-}
12{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE TypeFamilies #-}
src/Graphics/Vty/Terminal/TerminfoBased.hs−2
@@ -5,8 +5,6 @@
5-- assumptions mixed in.
5-- assumptions mixed in.
6--
6--
7-- Copyright Corey O'Connor (coreyoconnor@gmail.com)
7-- Copyright Corey O'Connor (coreyoconnor@gmail.com)
8−{-# LANGUAGE ForeignFunctionInterface #-}
9−{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE FlexibleInstances #-}
8{-# LANGUAGE FlexibleInstances #-}
11{-# OPTIONS_GHC -D_XOPEN_SOURCE=500 #-}
9{-# OPTIONS_GHC -D_XOPEN_SOURCE=500 #-}
12module Graphics.Vty.Terminal.TerminfoBased ( reserve_terminal )
10module Graphics.Vty.Terminal.TerminfoBased ( reserve_terminal )
src/Graphics/Vty/Terminal/XTermColor.hs−5
@@ -1,9 +1,4 @@
1-- Copyright 2009-2010 Corey O'Connor
1-- Copyright 2009-2010 Corey O'Connor
2−{-# LANGUAGE ForeignFunctionInterface #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4−{-# LANGUAGE MagicHash #-}
5−{-# LANGUAGE FlexibleInstances #-}
6−{-# LANGUAGE TypeFamilies #-}
7module Graphics.Vty.Terminal.XTermColor ( reserve_terminal )
2module Graphics.Vty.Terminal.XTermColor ( reserve_terminal )
8 where
3 where
9
4
test/Test.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module Main where
1module Main where
3
2
4import Graphics.Vty
3import Graphics.Vty
test/Verify.hs+1−1
@@ -1,6 +1,6 @@
1+{-# LANGUAGE RankNTypes #-}
1{-# LANGUAGE GADTs #-}
2{-# LANGUAGE GADTs #-}
2{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE RecordWildCards #-}
3−{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE CPP #-}
4{-# LANGUAGE CPP #-}
5{-# LANGUAGE TypeSynonymInstances #-}
5{-# LANGUAGE TypeSynonymInstances #-}
6{-# LANGUAGE FlexibleInstances #-}
6{-# LANGUAGE FlexibleInstances #-}
test/Verify/Data/Terminfo/Parse.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module Verify.Data.Terminfo.Parse ( module Verify.Data.Terminfo.Parse
1module Verify.Data.Terminfo.Parse ( module Verify.Data.Terminfo.Parse
3 , module Data.Terminfo.Parse
2 , module Data.Terminfo.Parse
4 )
3 )
test/Verify/Graphics/Vty/DisplayRegion.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module Verify.Graphics.Vty.DisplayRegion ( module Verify.Graphics.Vty.DisplayRegion
1module Verify.Graphics.Vty.DisplayRegion ( module Verify.Graphics.Vty.DisplayRegion
3 , module Graphics.Vty.DisplayRegion
2 , module Graphics.Vty.DisplayRegion
4 , MockWindow(..)
3 , MockWindow(..)
test/Verify/Graphics/Vty/Terminal.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module Verify.Graphics.Vty.Terminal where
1module Verify.Graphics.Vty.Terminal where
3
2
4import Graphics.Vty.Terminal.Mock
3import Graphics.Vty.Terminal.Mock
test/VerifyEmptyImageProps.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module VerifyEmptyImageProps where
1module VerifyEmptyImageProps where
3
2
4import Verify
3import Verify
test/VerifyEvalTerminfoCaps.hs−1
@@ -1,5 +1,4 @@
1{-# LANGUAGE BangPatterns #-}
1{-# LANGUAGE BangPatterns #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE NamedFieldPuns #-}
2{-# LANGUAGE NamedFieldPuns #-}
4module VerifyEvalTerminfoCaps where
3module VerifyEvalTerminfoCaps where
5
4
test/VerifyImageOps.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module VerifyImageOps where
1module VerifyImageOps where
3
2
4import Graphics.Vty.Attributes
3import Graphics.Vty.Attributes
test/VerifyParseTerminfoCaps.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE NamedFieldPuns #-}
1{-# LANGUAGE NamedFieldPuns #-}
3module VerifyParseTerminfoCaps where
2module VerifyParseTerminfoCaps where
4
3
test/VerifyTerminal.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2{- We setup the environment to envoke certain terminals of interest.
1{- We setup the environment to envoke certain terminals of interest.
3 - This assumes appropriate definitions exist in the current environment for the terminals of
2 - This assumes appropriate definitions exist in the current environment for the terminals of
4 - interest.
3 - interest.
test/VerifyUsingMockInput.hs+18−4
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2{- We setup the environment to envoke certain terminals of interest.
1{- We setup the environment to envoke certain terminals of interest.
3 - This assumes appropriate definitions exist in the current environment for the terminals of
2 - This assumes appropriate definitions exist in the current environment for the terminals of
4 - interest.
3 - interest.
@@ -8,17 +7,32 @@ import Verify
8
7
9import Graphics.Vty
8import Graphics.Vty
10
9
10+import Control.Concurrent
11import Control.Monad
11import Control.Monad
12
12
13import System.Posix.Env
13import System.Posix.Env
14import System.IO
14import System.IO
15
15
16−data InputSpec
16+data InputEvent
17− = KeySeq String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
17+ = Bytes String -- | input sequence encoded as a string. Regardless, the input is read a byte at a time.
18− | Delay Int -- | millisecond delay
18+ | Delay Int -- | millisecond delay
19+
20+type InputSpec = [InputEvent]
19
21
20type ExpectedSpec = [Event]
22type ExpectedSpec = [Event]
21
23
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+
22tests :: IO [Test]
36tests :: IO [Test]
23tests = return []
37tests = return []
24
38
test/VerifyUsingMockTerminal.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2module VerifyUsingMockTerminal where
1module VerifyUsingMockTerminal where
3
2
4import Verify.Graphics.Vty.DisplayRegion
3import Verify.Graphics.Vty.DisplayRegion
test/benchmark.hs−1
@@ -1,5 +1,4 @@
1{-# LANGUAGE QuasiQuotes #-}
1{-# LANGUAGE QuasiQuotes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3module Main where
2module Main where
4
3
5import Graphics.Vty
4import Graphics.Vty
test/interactive_terminal_test.hs−1
@@ -1,5 +1,4 @@
1{-# LANGUAGE QuasiQuotes #-}
1{-# LANGUAGE QuasiQuotes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3module Main where
2module Main where
4
3
5import Graphics.Vty
4import Graphics.Vty
vty.cabal+22−2
@@ -27,8 +27,7 @@ description:
27 &#169; 2006-2007 Stefan O'Rear; BSD3 license.
27 &#169; 2006-2007 Stefan O'Rear; BSD3 license.
28 .
28 .
29 &#169; Corey O'Connor; BSD3 license.
29 &#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
32build-type: Simple
31build-type: Simple
33data-files: README.md,
32data-files: README.md,
34 TODO,
33 TODO,
@@ -38,6 +37,7 @@ data-files: README.md,
38
37
39library
38library
40 default-language: Haskell2010
39 default-language: Haskell2010
40+ extensions: ScopedTypeVariables
41 build-depends: base >= 4 && < 5,
41 build-depends: base >= 4 && < 5,
42 bytestring,
42 bytestring,
43 containers,
43 containers,
@@ -90,6 +90,9 @@ library
90
90
91 hs-source-dirs: src
91 hs-source-dirs: src
92
92
93+ extensions: ScopedTypeVariables
94+ ForeignFunctionInterface
95+
93 ghc-options: -O2 -funbox-strict-fields -Wall -fno-full-laziness -fspec-constr -fspec-constr-count=10
96 ghc-options: -O2 -funbox-strict-fields -Wall -fno-full-laziness -fspec-constr -fspec-constr-count=10
94
97
95 ghc-prof-options: -O2 -funbox-strict-fields -caf-all -Wall -fno-full-laziness -fspec-constr -fspec-constr-count=10
98 ghc-prof-options: -O2 -funbox-strict-fields -caf-all -Wall -fno-full-laziness -fspec-constr -fspec-constr-count=10
@@ -98,6 +101,7 @@ library
98
101
99test-suite verify-attribute-ops
102test-suite verify-attribute-ops
100 default-language: Haskell2010
103 default-language: Haskell2010
104+ extensions: ScopedTypeVariables
101 type: detailed-0.9
105 type: detailed-0.9
102 hs-source-dirs: test
106 hs-source-dirs: test
103 test-module: VerifyAttributeOps
107 test-module: VerifyAttributeOps
@@ -117,6 +121,7 @@ test-suite verify-attribute-ops
117
121
118test-suite verify-using-mock-terminal
122test-suite verify-using-mock-terminal
119 default-language: Haskell2010
123 default-language: Haskell2010
124+ extensions: ScopedTypeVariables
120
125
121 type: detailed-0.9
126 type: detailed-0.9
122
127
@@ -148,6 +153,7 @@ test-suite verify-using-mock-terminal
148
153
149test-suite verify-terminal
154test-suite verify-terminal
150 default-language: Haskell2010
155 default-language: Haskell2010
156+ extensions: ScopedTypeVariables
151
157
152 type: detailed-0.9
158 type: detailed-0.9
153
159
@@ -180,6 +186,7 @@ test-suite verify-terminal
180
186
181test-suite verify-display-attributes
187test-suite verify-display-attributes
182 default-language: Haskell2010
188 default-language: Haskell2010
189+ extensions: ScopedTypeVariables
183
190
184 type: detailed-0.9
191 type: detailed-0.9
185
192
@@ -210,6 +217,7 @@ test-suite verify-display-attributes
210
217
211test-suite verify-empty-image-props
218test-suite verify-empty-image-props
212 default-language: Haskell2010
219 default-language: Haskell2010
220+ extensions: ScopedTypeVariables
213
221
214 type: detailed-0.9
222 type: detailed-0.9
215
223
@@ -235,6 +243,7 @@ test-suite verify-empty-image-props
235
243
236test-suite verify-eval-terminfo-caps
244test-suite verify-eval-terminfo-caps
237 default-language: Haskell2010
245 default-language: Haskell2010
246+ extensions: ScopedTypeVariables
238
247
239 type: detailed-0.9
248 type: detailed-0.9
240
249
@@ -261,6 +270,7 @@ test-suite verify-eval-terminfo-caps
261
270
262test-suite verify-image-ops
271test-suite verify-image-ops
263 default-language: Haskell2010
272 default-language: Haskell2010
273+ extensions: ScopedTypeVariables
264
274
265 type: detailed-0.9
275 type: detailed-0.9
266
276
@@ -288,6 +298,7 @@ test-suite verify-image-ops
288
298
289test-suite verify-image-trans
299test-suite verify-image-trans
290 default-language: Haskell2010
300 default-language: Haskell2010
301+ extensions: ScopedTypeVariables
291
302
292 type: detailed-0.9
303 type: detailed-0.9
293
304
@@ -315,6 +326,7 @@ test-suite verify-image-trans
315
326
316test-suite verify-inline
327test-suite verify-inline
317 default-language: Haskell2010
328 default-language: Haskell2010
329+ extensions: ScopedTypeVariables
318
330
319 type: detailed-0.9
331 type: detailed-0.9
320
332
@@ -341,6 +353,7 @@ test-suite verify-inline
341
353
342test-suite verify-parse-terminfo-caps
354test-suite verify-parse-terminfo-caps
343 default-language: Haskell2010
355 default-language: Haskell2010
356+ extensions: ScopedTypeVariables
344
357
345 type: detailed-0.9
358 type: detailed-0.9
346
359
@@ -368,6 +381,7 @@ test-suite verify-parse-terminfo-caps
368
381
369test-suite verify-simple-span-generation
382test-suite verify-simple-span-generation
370 default-language: Haskell2010
383 default-language: Haskell2010
384+ extensions: ScopedTypeVariables
371
385
372 type: detailed-0.9
386 type: detailed-0.9
373
387
@@ -399,6 +413,7 @@ test-suite verify-simple-span-generation
399
413
400test-suite verify-crop-span-generation
414test-suite verify-crop-span-generation
401 default-language: Haskell2010
415 default-language: Haskell2010
416+ extensions: ScopedTypeVariables
402
417
403 type: detailed-0.9
418 type: detailed-0.9
404
419
@@ -430,6 +445,7 @@ test-suite verify-crop-span-generation
430
445
431test-suite verify-layers-span-generation
446test-suite verify-layers-span-generation
432 default-language: Haskell2010
447 default-language: Haskell2010
448+ extensions: ScopedTypeVariables
433
449
434 type: detailed-0.9
450 type: detailed-0.9
435
451
@@ -460,6 +476,7 @@ test-suite verify-layers-span-generation
460
476
461test-suite verify-utf8-width
477test-suite verify-utf8-width
462 default-language: Haskell2010
478 default-language: Haskell2010
479+ extensions: ScopedTypeVariables
463
480
464 type: detailed-0.9
481 type: detailed-0.9
465
482
@@ -485,6 +502,7 @@ test-suite verify-utf8-width
485
502
486test-suite verify-using-mock-input
503test-suite verify-using-mock-input
487 default-language: Haskell2010
504 default-language: Haskell2010
505+ extensions: ScopedTypeVariables
488
506
489 type: detailed-0.9
507 type: detailed-0.9
490
508
@@ -513,6 +531,7 @@ executable vty-interactive-terminal-test
513 main-is: interactive_terminal_test.hs
531 main-is: interactive_terminal_test.hs
514
532
515 default-language: Haskell2010
533 default-language: Haskell2010
534+ extensions: ScopedTypeVariables
516
535
517 hs-source-dirs: test
536 hs-source-dirs: test
518
537
@@ -537,6 +556,7 @@ executable vty-benchmark
537 main-is: benchmark.hs
556 main-is: benchmark.hs
538
557
539 default-language: Haskell2010
558 default-language: Haskell2010
559+ extensions: ScopedTypeVariables
540
560
541 hs-source-dirs: test
561 hs-source-dirs: test
542
562