on master help sign in
remove duplicate ANST/VT modules and just use a single module
commit857cb6152fbc0a35c87f814965399eb46eb94dcc authorCorey O'Connor <coreyoconnor@gmail.com> dateSun 25 May 2014, 22:35 (12 years ago) parente010924
4 files changed+24−111
src/Graphics/Vty/Input/Terminfo.hs+10−10 src/Graphics/Vty/Input/Terminfo/ANSI.hs−85 src/Graphics/Vty/Input/Terminfo/XTerm7Bit.hs → src/Graphics/Vty/Input/Terminfo/ANSIVT.hs+13−14 vty.cabal+1−2
src/Graphics/Vty/Input/Terminfo.hs+10−10
@@ -1,8 +1,7 @@
11module Graphics.Vty.Input.Terminfo where
22
33import Graphics.Vty.Input.Events
4−import qualified Graphics.Vty.Input.Terminfo.ANSI as ANSI
5−import qualified Graphics.Vty.Input.Terminfo.XTerm7Bit as XTerm7Bit
4+import qualified Graphics.Vty.Input.Terminfo.ANSIVT as ANSIVT
65
76import Control.Arrow
87import System.Console.Terminfo
@@ -26,11 +25,11 @@ import System.Console.Terminfo
2625--
2726-- 1. build terminfo table for all caps. Missing caps are not added.
2827--
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
3029--
3130-- 3. add internally defined table for given terminal type.
3231--
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.
3433--
3534-- \todo terminfo meta is not supported.
3635-- \todo no 8bit
@@ -38,9 +37,11 @@ classifyTableForTerm :: String -> Terminal -> ClassifyTable
3837classifyTableForTerm termName term =
3938 concat $ capsClassifyTable term keysFromCapsTable
4039 : universalTable
41− : termSpecificTables termName
40+ : termSpecificTable termName
4241
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.
4445universalTable :: ClassifyTable
4546universalTable = concat [visibleChars, ctrlChars, ctrlMetaChars, specialSupportKeys]
4647
@@ -49,11 +50,10 @@ capsClassifyTable terminal table = [(x,y) | (Just x,y) <- map extractCap table]
4950 where extractCap = first (getCapability terminal . tiGetStr)
5051
5152-- | 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.
5255termSpecificTables :: String -> [ClassifyTable]
53−termSpecificTables termName
54− | ANSI.supports termName = ANSI.tables
55− | XTerm7Bit.supports termName = XTerm7Bit.tables
56− | otherwise = []
56+termSpecificTables _termName = ANSIVT.classifyTable
5757
5858-- | Visible characters in the ISO-8859-1 and UTF-8 common set.
5959--
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−module Graphics.Vty.Input.Terminfo.XTerm7Bit where
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.
6+module Graphics.Vty.Input.Terminfo.ANSIVT where
27
38import Graphics.Vty.Input.Events
49
510import Data.List (isInfixOf, isPrefixOf)
611
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−
1212-- | Encoding for navigation keys.
1313--
1414-- TODO: This is not the same as the input bytes pulled from teh caps table.
@@ -26,7 +26,7 @@ navKeys0 =
2626 ]
2727 where k c s = ("\ESC["++c,EvKey s [])
2828
29−-- | VT 100 (?) encoding for shift, meta and ctrl plus arrows/home/end
29+-- | encoding for shift, meta and ctrl plus arrows/home/end
3030navKeys1 :: ClassifyTable
3131navKeys1 =
3232 [("\ESC[" ++ charCnt ++ show mc++c,EvKey s m)
@@ -36,21 +36,21 @@ navKeys1 =
3636 (c,s) <- [("A", KUp), ("B", KDown), ("C", KRight), ("D", KLeft), ("H", KHome), ("F", KEnd)] -- directions and their codes
3737 ]
3838
39−-- | VT 100 (?) encoding for ins, del, pageup, pagedown, home, end
39+-- | encoding for ins, del, pageup, pagedown, home, end
4040navKeys2 :: ClassifyTable
4141navKeys2 =
4242 let k n s = ("\ESC["++show n++"~",EvKey s [])
4343 in zipWith k [2::Int,3,5,6,1,4]
4444 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
4545
46−-- | VT 100 (?) encoding for ctrl + ins, del, pageup, pagedown, home, end
46+-- | encoding for ctrl + ins, del, pageup, pagedown, home, end
4747navKeys3 :: ClassifyTable
4848navKeys3 =
4949 let k n s = ("\ESC["++show n++";5~",EvKey s [MCtrl])
5050 in zipWith k [2::Int,3,5,6,1,4]
5151 [KIns,KDel,KPageUp,KPageDown,KHome,KEnd]
5252
53−-- | VT 100 (?) encoding for shift plus function keys
53+-- | encoding for shift plus function keys
5454--
5555-- TODO: I suspect this should be generated by interpretting the terminals use of meta mode:
5656-- "If the terminal has a ``meta key'' which acts as a shift key, setting the 8th bit of any
@@ -64,7 +64,7 @@ functionKeys1 =
6464 let f ff nrs m = [ ("\ESC["++show n++"~",EvKey (KFun $ n-(nrs!!0)+ff) m) | n <- nrs ] in
6565 concat [f 1 [25,26] [MShift], f 3 [28,29] [MShift], f 5 [31..34] [MShift] ]
6666
67−-- | VT 100 (?) encoding for meta plus char
67+-- | encoding for meta plus char
6868--
6969-- TODO: resolve -
7070--
@@ -79,9 +79,8 @@ functionKeys2 = [ ('\ESC':[x],EvKey (KChar x) [MMeta])
7979 , x /= '['
8080 ]
8181
82−-- | classify table for ANSI terminals
83−tables :: [ClassifyTable]
84−tables =
82+classifyTable :: [ClassifyTable]
83+classifyTable =
8584 [ navKeys0
8685 , navKeys1
8786 , navKeys2
vty.cabal+1−2
@@ -96,8 +96,7 @@ library
9696
9797 other-modules: Graphics.Vty.Attributes.Color
9898 Graphics.Vty.Attributes.Color240
99− Graphics.Vty.Input.Terminfo.ANSI
100− Graphics.Vty.Input.Terminfo.XTerm7Bit
99+ Graphics.Vty.Input.Terminfo.ANSIVT
101100
102101 c-sources: cbits/gwinsz.c
103102 cbits/set_term_timing.c