on master help sign in
remove duplicate ANST/VT modules and just use a single module
857cb61Corey O'Connor
src/Graphics/Vty/Input/Terminfo.hs+10−10
@@ -1,8 +1,7 @@
1module Graphics.Vty.Input.Terminfo where
1module Graphics.Vty.Input.Terminfo where
2
2
3import Graphics.Vty.Input.Events
3import Graphics.Vty.Input.Events
4−import qualified Graphics.Vty.Input.Terminfo.ANSI as ANSI
4+import qualified Graphics.Vty.Input.Terminfo.ANSIVT as ANSIVT
5−import qualified Graphics.Vty.Input.Terminfo.XTerm7Bit as XTerm7Bit
6
5
7import Control.Arrow
6import Control.Arrow
8import System.Console.Terminfo
7import System.Console.Terminfo
@@ -26,11 +25,11 @@ import System.Console.Terminfo
26--
25--
27-- 1. build terminfo table for all caps. Missing caps are not added.
26-- 1. build terminfo table for all caps. Missing caps are not added.
28--
27--
29−-- 2. add tables for visible chars, esc, del plus ctrl and meta.
28+-- 2. add tables for visible chars, esc, del plus ctrl and meta
30--
29--
31-- 3. add internally defined table for given terminal type.
30-- 3. add internally defined table for given terminal type.
32--
31--
33−-- The override is currently done in 'compile'. Which is a bit odd.
32+-- Precedence is currently implicit in the 'compile' algorithm. Which is a bit odd.
34--
33--
35-- \todo terminfo meta is not supported.
34-- \todo terminfo meta is not supported.
36-- \todo no 8bit
35-- \todo no 8bit
@@ -38,9 +37,11 @@ classifyTableForTerm :: String -> Terminal -> ClassifyTable
38classifyTableForTerm termName term =
37classifyTableForTerm termName term =
39 concat $ capsClassifyTable term keysFromCapsTable
38 concat $ capsClassifyTable term keysFromCapsTable
40 : universalTable
39 : universalTable
41− : termSpecificTables termName
40+ : termSpecificTable termName
42
41
43−-- | key table assumed to be applicable to all terminals.
42+-- | key table applicable to all terminals.
43+--
44+-- TODO: some probably only applicable to ANSI/VT100 terminals.
44universalTable :: ClassifyTable
45universalTable :: ClassifyTable
45universalTable = concat [visibleChars, ctrlChars, ctrlMetaChars, specialSupportKeys]
46universalTable = concat [visibleChars, ctrlChars, ctrlMetaChars, specialSupportKeys]
46
47
@@ -49,11 +50,10 @@ capsClassifyTable terminal table = [(x,y) | (Just x,y) <- map extractCap table]
49 where extractCap = first (getCapability terminal . tiGetStr)
50 where extractCap = first (getCapability terminal . tiGetStr)
50
51
51-- | tables specific to a given terminal that are not derivable from terminfo.
52-- | tables specific to a given terminal that are not derivable from terminfo.
53+--
54+-- TODO: Adds the ANSI/VT100/VT50 tables regardless of term identifier.
52termSpecificTables :: String -> [ClassifyTable]
55termSpecificTables :: String -> [ClassifyTable]
53−termSpecificTables termName
56+termSpecificTables _termName = ANSIVT.classifyTable
54− | ANSI.supports termName = ANSI.tables
55− | XTerm7Bit.supports termName = XTerm7Bit.tables
56− | otherwise = []
57
57
58-- | Visible characters in the ISO-8859-1 and UTF-8 common set.
58-- | Visible characters in the ISO-8859-1 and UTF-8 common set.
59--
59--
src/Graphics/Vty/Input/Terminfo/ANSI.hsdeleted−85
@@ -1,85 +0,0 @@
1−module Graphics.Vty.Input.Terminfo.ANSI where
2−
3−import Graphics.Vty.Input.Events
4−
5−-- | Terminals augmented by the built in ANSI input mapping.
6−supports :: String -> Bool
7−supports "ansi" = True
8−supports _ = False
9−
10−-- | Encoding for navigation keys.
11−navKeys0 :: ClassifyTable
12−navKeys0 =
13− [ k "G" KCenter
14− , k "P" KPause
15− , k "A" KUp
16− , k "B" KDown
17− , k "C" KRight
18− , k "D" KLeft
19− , k "H" KHome
20− , k "F" KEnd
21− , k "E" KBegin
22− ]
23− where k c s = ("\ESC["++c, EvKey s [])
24−
25−-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
26−navKeys1 :: ClassifyTable
27−navKeys1 =
28− [("\ESC[" ++ charCnt ++ show mc++c,EvKey s m)
29− | charCnt <- ["1;", ""], -- we can have a count or not
30− (m,mc) <- [([MShift],2::Int), ([MCtrl],5), ([MMeta],3),
31− ([MShift, MCtrl],6), ([MShift, MMeta],4)], -- modifiers and their codes
32− -- directions and their codes
33− (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)]
34− ]
35−
36−-- | VT 100 (?) encoding for ins, del, pageup, pagedown, home, end
37−navKeys2 :: ClassifyTable
38−navKeys2 =
39− let k n s = ("\ESC["++show n++"~",EvKey s [])
40− in zipWith k [2::Int,3,5,6,1,4]
41− [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
42−
43−-- | VT 100 (?) encoding for ctrl + ins, del, pageup, pagedown, home, end
44−navKeys3 :: ClassifyTable
45−navKeys3 =
46− let k n s = ("\ESC["++show n++";5~", EvKey s [MCtrl])
47− in zipWith k [2::Int,3,5,6,1,4]
48− [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
49−
50−-- | VT 100 (?) encoding for shift plus function keys
51−--
52−-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
53−-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
54−-- character transmitted, this fact can be indicated with km. Other- wise, software will
55−-- assume that the 8th bit is parity and it will usually be cleared. If strings exist to turn this
56−-- ``meta mode'' on and off, they can be given as smm and rmm."
57−--
58−-- That is more complex than below. I cannot fault the original author for just hard coding a table.
59−functionKeys1 :: ClassifyTable
60−functionKeys1 =
61− let f ff nrs m = [ ("\ESC["++show n++"~",EvKey (KFun $ n-(nrs!!0)+ff) m) | n <- nrs ] in
62− concat [f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
63−
64−-- | VT 100 (?) encoding for meta plus char
65−--
66−-- TODO: resolve -
67−--
68−-- 2. removed '[' from second list due to conflict with 7-bit encoding for ESC. Whether meta+[ is
69−-- the same as ESC should examine km and current encoding.
70−functionKeys2 :: ClassifyTable
71−functionKeys2 = [ ('\ESC':[x],EvKey (KChar x) [MMeta])
72− | x <- '\t':[' ' .. '~']
73− , x /= '['
74− ]
75−
76−tables :: [ClassifyTable]
77−tables =
78− [ navKeys0
79− , navKeys1
80− , navKeys2
81− , navKeys3
82− , functionKeys1
83− , functionKeys2
84− ]
85−
src/Graphics/Vty/Input/Terminfo/XTerm7Bit.hs → src/Graphics/Vty/Input/Terminfo/ANSIVT.hsrenamed+13−14
@@ -1,14 +1,14 @@
1+-- | Input mappings for ANSI/VT100/VT50 terminals that is missing from terminfo.
2+--
3+-- Or that are sent regardless of terminfo by terminal emulators. EG: Terminal emulators will often
4+-- use VT50 input bytes regardless of declared terminal type. This provides compatibility with
5+-- programs that don't follow terminfo.
1−module Graphics.Vty.Input.Terminfo.XTerm7Bit where
6+module Graphics.Vty.Input.Terminfo.ANSIVT where
2
7
3import Graphics.Vty.Input.Events
8import Graphics.Vty.Input.Events
4
9
5import Data.List (isInfixOf, isPrefixOf)
10import Data.List (isInfixOf, isPrefixOf)
6
11
7−-- | The built in input augmentation for XTerm supports any TERM starting with xterm except those
8−-- containing 8bit.
9−supports :: String -> Bool
10−supports termName = "xterm" `isPrefixOf` termName && not ("8bit" `isInfixOf` termName)
11−
12-- | Encoding for navigation keys.
12-- | Encoding for navigation keys.
13--
13--
14-- TODO: This is not the same as the input bytes pulled from teh caps table.
14-- TODO: This is not the same as the input bytes pulled from teh caps table.
@@ -26,7 +26,7 @@ navKeys0 =
26 ]
26 ]
27 where k c s = ("\ESC["++c,EvKey s [])
27 where k c s = ("\ESC["++c,EvKey s [])
28
28
29−-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
29+-- | encoding for shift, meta and ctrl plus arrows/home/end
30navKeys1 :: ClassifyTable
30navKeys1 :: ClassifyTable
31navKeys1 =
31navKeys1 =
32 [("\ESC[" ++ charCnt ++ show mc++c,EvKey s m)
32 [("\ESC[" ++ charCnt ++ show mc++c,EvKey s m)
@@ -36,21 +36,21 @@ navKeys1 =
36 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
36 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
37 ]
37 ]
38
38
39−-- | VT 100 (?) encoding for ins, del, pageup, pagedown, home, end
39+-- | encoding for ins, del, pageup, pagedown, home, end
40navKeys2 :: ClassifyTable
40navKeys2 :: ClassifyTable
41navKeys2 =
41navKeys2 =
42 let k n s = ("\ESC["++show n++"~",EvKey s [])
42 let k n s = ("\ESC["++show n++"~",EvKey s [])
43 in zipWith k [2::Int,3,5,6,1,4]
43 in zipWith k [2::Int,3,5,6,1,4]
44 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
44 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
45
45
46−-- | VT 100 (?) encoding for ctrl + ins, del, pageup, pagedown, home, end
46+-- | encoding for ctrl + ins, del, pageup, pagedown, home, end
47navKeys3 :: ClassifyTable
47navKeys3 :: ClassifyTable
48navKeys3 =
48navKeys3 =
49 let k n s = ("\ESC["++show n++";5~",EvKey s [MCtrl])
49 let k n s = ("\ESC["++show n++";5~",EvKey s [MCtrl])
50 in zipWith k [2::Int,3,5,6,1,4]
50 in zipWith k [2::Int,3,5,6,1,4]
51 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
51 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
52
52
53−-- | VT 100 (?) encoding for shift plus function keys
53+-- | encoding for shift plus function keys
54--
54--
55-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
55-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
56-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
56-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
@@ -64,7 +64,7 @@ functionKeys1 =
64 let f ff nrs m = [ ("\ESC["++show n++"~",EvKey (KFun $ n-(nrs!!0)+ff) m) | n <- nrs ] in
64 let f ff nrs m = [ ("\ESC["++show n++"~",EvKey (KFun $ n-(nrs!!0)+ff) m) | n <- nrs ] in
65 concat [f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
65 concat [f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
66
66
67−-- | VT 100 (?) encoding for meta plus char
67+-- | encoding for meta plus char
68--
68--
69-- TODO: resolve -
69-- TODO: resolve -
70--
70--
@@ -79,9 +79,8 @@ functionKeys2 = [ ('\ESC':[x],EvKey (KChar x) [MMeta])
79 , x /= '['
79 , x /= '['
80 ]
80 ]
81
81
82−-- | classify table for ANSI terminals
83−tables :: [ClassifyTable]
82+classifyTable :: [ClassifyTable]
84−tables =
83+classifyTable =
85 [ navKeys0
84 [ navKeys0
86 , navKeys1
85 , navKeys1
87 , navKeys2
86 , navKeys2
vty.cabal+1−2
@@ -96,8 +96,7 @@ library
96
96
97 other-modules: Graphics.Vty.Attributes.Color
97 other-modules: Graphics.Vty.Attributes.Color
98 Graphics.Vty.Attributes.Color240
98 Graphics.Vty.Attributes.Color240
99− Graphics.Vty.Input.Terminfo.ANSI
99+ Graphics.Vty.Input.Terminfo.ANSIVT
100− Graphics.Vty.Input.Terminfo.XTerm7Bit
101
100
102 c-sources: cbits/gwinsz.c
101 c-sources: cbits/gwinsz.c
103 cbits/set_term_timing.c
102 cbits/set_term_timing.c