on master help sign in
doc the proposed user config options
e78f057Corey O'Connor
src/Graphics/Vty/Input.hs+7−3
@@ -44,9 +44,12 @@ import Graphics.Vty.Input.Events
44import Graphics.Vty.Input.Internal
44import Graphics.Vty.Input.Internal
45import Graphics.Vty.Input.Terminfo
45import Graphics.Vty.Input.Terminfo
46
46
47+import Control.Applicative
47import Control.Concurrent
48import Control.Concurrent
48import Control.Lens
49import Control.Lens
49
50
51+import Data.Monoid
52+
50import qualified System.Console.Terminfo as Terminfo
53import qualified System.Console.Terminfo as Terminfo
51import System.Environment
54import System.Environment
52import System.Posix.Signals.Exts
55import System.Posix.Signals.Exts
@@ -63,9 +66,9 @@ inputForCurrentTerminal config = do
63-- | Set up the terminal attached to the given Fd for input. Returns a 'Input'.
66-- | Set up the terminal attached to the given Fd for input. Returns a 'Input'.
64--
67--
65-- The table used to determine the 'Events' to produce for the input bytes comes from
68-- The table used to determine the 'Events' to produce for the input bytes comes from
66−-- 'classifyTableForTerm'.
69+-- 'classifyTableForTerm'. Which is then overridden by the table from 'classifyTableUserOverrides'.
67--
70--
68−-- The terminal is modified as follows:
71+-- The terminal device is configured with the attributes:
69--
72--
70-- * IXON disabled
73-- * IXON disabled
71-- - disables software flow control on outgoing data. This stops the process from being
74-- - disables software flow control on outgoing data. This stops the process from being
@@ -91,7 +94,8 @@ inputForCurrentTerminal config = do
91inputForNameAndIO :: Config -> String -> Fd -> IO Input
94inputForNameAndIO :: Config -> String -> Fd -> IO Input
92inputForNameAndIO config termName termFd = do
95inputForNameAndIO config termName termFd = do
93 terminal <- Terminfo.setupTerm termName
96 terminal <- Terminfo.setupTerm termName
94− let classifyTable = classifyTableForTerm termName terminal
97+ classifyTable <- mappend <$> pure (classifyTableForTerm termName terminal)
98+ <*> classifyTableUserOverrides
95 (setAttrs,unsetAttrs) <- attributeControl termFd
99 (setAttrs,unsetAttrs) <- attributeControl termFd
96 setAttrs
100 setAttrs
97 input <- initInputForFd config classifyTable termFd
101 input <- initInputForFd config classifyTable termFd
src/Graphics/Vty/Input/Events.hs+4−3
@@ -13,13 +13,13 @@ data Key = KEsc | KChar Char | KBS | KEnter
13 | KUpLeft | KUpRight | KDownLeft | KDownRight | KCenter
13 | KUpLeft | KUpRight | KDownLeft | KDownRight | KCenter
14 | KFun Int | KBackTab | KPrtScr | KPause | KIns
14 | KFun Int | KBackTab | KPrtScr | KPause | KIns
15 | KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KMenu
15 | KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KMenu
16− deriving (Eq,Show,Ord)
16+ deriving (Eq,Show,Read,Ord)
17
17
18-- | Modifier keys. Key codes are interpreted such that users are more likely to
18-- | Modifier keys. Key codes are interpreted such that users are more likely to
19-- have Meta than Alt; for instance on the PC Linux console, 'MMeta' will
19-- have Meta than Alt; for instance on the PC Linux console, 'MMeta' will
20-- generally correspond to the physical Alt key.
20-- generally correspond to the physical Alt key.
21data Modifier = MShift | MCtrl | MMeta | MAlt
21data Modifier = MShift | MCtrl | MMeta | MAlt
22− deriving (Eq,Show,Ord)
22+ deriving (Eq,Show,Read,Ord)
23
23
24-- | Mouse buttons.
24-- | Mouse buttons.
25--
25--
@@ -38,5 +38,6 @@ data Event
38 | EvResize Int Int
38 | EvResize Int Int
39 deriving (Eq,Show,Ord)
39 deriving (Eq,Show,Ord)
40
40
41−-- | representation of mapping from input bytes to event
41+-- | representation of mapping from input bytes to event. Later entries take precedence over earlier
42+-- in the case multiple entries have the same byte string.
42type ClassifyTable = [(String, Event)]
43type ClassifyTable = [(String, Event)]
src/Graphics/Vty/Input/Internal.hs+4
@@ -35,11 +35,13 @@ import System.Posix.Types (Fd(..))
35
35
36data Config = Config
36data Config = Config
37 { singleEscPeriod :: Int -- ^ AKA VTIME. The default is 100000 microseconds or 0.1 seconds.
37 { singleEscPeriod :: Int -- ^ AKA VTIME. The default is 100000 microseconds or 0.1 seconds.
38+ , debugInputLog :: Maybe FilePath -- ^ Debug information about the input process is appended to the file.
38 } deriving (Show, Eq)
39 } deriving (Show, Eq)
39
40
40instance Default Config where
41instance Default Config where
41 def = Config
42 def = Config
42 { singleEscPeriod = 100000
43 { singleEscPeriod = 100000
44+ , debugInputLog = Nothing
43 }
45 }
44
46
45data Input = Input
47data Input = Input
@@ -148,6 +150,8 @@ stopIfRequested = do
148-- I did not write this so I might just rewrite it for better understanding. Not the best of
150-- I did not write this so I might just rewrite it for better understanding. Not the best of
149-- reasons...
151-- reasons...
150-- TODO: measure and rewrite if required.
152-- TODO: measure and rewrite if required.
153+-- TODO: The ClassifyTable interface requires this code to always assure later entries override
154+-- earlier.
151compile :: ClassifyTable -> [Char] -> KClass
155compile :: ClassifyTable -> [Char] -> KClass
152compile table = cl' where
156compile table = cl' where
153 -- take all prefixes and create a set of these
157 -- take all prefixes and create a set of these
src/Graphics/Vty/Input/Terminfo.hs+33
@@ -40,6 +40,39 @@ classifyTableForTerm termName term =
40 : universalTable
40 : universalTable
41 : termSpecificTables termName
41 : termSpecificTables termName
42
42
43+-- | The user can specify a list of classify table entries in $HOME/.config/vty/input.conf and
44+-- $VTY_INPUT_CONFIG. The file at $VTY_INPUT_CONFIG takes precedence over the input.conf file. Both
45+-- take precedence over the classify tables determined by 'classifyTableForTerm'
46+--
47+-- Each line of the input config is processed individually. Lines that fail to parse are ignored.
48+-- Later entries take precedence over earlier.
49+--
50+-- Entry format:
51+--
52+-- @
53+-- entry := "map" string key modifier_list
54+-- key := KEsc | KChar Char | KBS ... (same as 'Key')
55+-- modifier_list := "[" modifier+ "]"
56+-- modifier := MShift | MCtrl | MMeta | MAlt
57+-- string := "\"" chars+ "\""
58+-- @
59+--
60+-- EG: If the contents of input.conf are
61+--
62+-- @
63+-- map "\ESC[B" KUp []
64+-- map "\ESC[1;3B" KDown [MAlt]
65+-- @
66+--
67+-- Then the bytes "\ESC[B" will result in the KUp event. The bytes "\ESC[1;3B" will result in the
68+-- event KDown with the MAlt modifier.
69+--
70+classifyTableUserOverrides :: IO ClassifyTable
71+classifyTableUserOverrides = return []
72+
73+parseOverrideFile :: FilePath -> IO ClassifyTable
74+parseOverrideFile _ = return []
75+
43-- | key table assumed to be applicable to all terminals.
76-- | key table assumed to be applicable to all terminals.
44universalTable :: ClassifyTable
77universalTable :: ClassifyTable
45universalTable = concat [visibleChars, ctrlChars, ctrlMetaChars, specialSupportKeys]
78universalTable = concat [visibleChars, ctrlChars, ctrlMetaChars, specialSupportKeys]
src/Graphics/Vty/Output/TerminfoBased.hs+8−1
@@ -92,10 +92,11 @@ sendCapToTerminal t cap capParams = do
92
92
93{- | Uses terminfo for all control codes. While this should provide the most compatible terminal
93{- | Uses terminfo for all control codes. While this should provide the most compatible terminal
94 - terminfo does not support some features that would increase efficiency and improve compatibility:
94 - terminfo does not support some features that would increase efficiency and improve compatibility:
95+ -
95 - * determine the character encoding supported by the terminal. Should this be taken from the LANG
96 - * determine the character encoding supported by the terminal. Should this be taken from the LANG
96 - environment variable?
97 - environment variable?
97− - * Provide independent string capabilities for all display attributes.
98 -
98 -
99+ - * Provide independent string capabilities for all display attributes.
99 -
100 -
100 - todo: Some display attributes like underline and bold have independent string capabilities that
101 - todo: Some display attributes like underline and bold have independent string capabilities that
101 - should be used instead of the generic "sgr" string capability.
102 - should be used instead of the generic "sgr" string capability.
@@ -238,15 +239,21 @@ terminfoDisplayContext tActual terminfoCaps r = return dc
238-- directly ; and, for no good reason, resets the colors to the default) this procedure is used:
239-- directly ; and, for no good reason, resets the colors to the default) this procedure is used:
239--
240--
240-- 0. set the style attributes. This resets the fore and back color.
241-- 0. set the style attributes. This resets the fore and back color.
242+--
241-- 1, If a foreground color is to be set then set the foreground color
243-- 1, If a foreground color is to be set then set the foreground color
244+--
242-- 2. likewise with the background color
245-- 2. likewise with the background color
243--
246--
244-- If the terminal does not support the sgr cap then:
247-- If the terminal does not support the sgr cap then:
245-- if there is a change from an applied color to the default (in either the fore or back color)
248-- if there is a change from an applied color to the default (in either the fore or back color)
246-- then:
249-- then:
250+--
247-- 0. reset all display attributes (sgr0)
251-- 0. reset all display attributes (sgr0)
252+--
248-- 1. enter required style modes
253-- 1. enter required style modes
254+--
249-- 2. set the fore color if required
255-- 2. set the fore color if required
256+--
250-- 3. set the back color if required
257-- 3. set the back color if required
251--
258--
252-- Entering the required style modes could require a reset of the display attributes. If this is
259-- Entering the required style modes could require a reset of the display attributes. If this is