on master help sign in
doc the proposed user config options
commite78f057378417584e93e9a169347160596ebed2b authorCorey O'Connor <coreyoconnor@gmail.com> dateTue 15 Apr 2014, 11:29 (13 years ago) parent8abf7f9
5 files changed+56−7
src/Graphics/Vty/Input.hs+7−3 src/Graphics/Vty/Input/Events.hs+4−3 src/Graphics/Vty/Input/Internal.hs+4 src/Graphics/Vty/Input/Terminfo.hs+33 src/Graphics/Vty/Output/TerminfoBased.hs+8−1
src/Graphics/Vty/Input.hs+7−3
@@ -44,9 +44,12 @@ import Graphics.Vty.Input.Events
4444import Graphics.Vty.Input.Internal
4545import Graphics.Vty.Input.Terminfo
4646
47+import Control.Applicative
4748import Control.Concurrent
4849import Control.Lens
4950
51+import Data.Monoid
52+
5053import qualified System.Console.Terminfo as Terminfo
5154import System.Environment
5255import System.Posix.Signals.Exts
@@ -63,9 +66,9 @@ inputForCurrentTerminal config = do
6366-- | Set up the terminal attached to the given Fd for input. Returns a 'Input'.
6467--
6568-- 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'.
6770--
68−-- The terminal is modified as follows:
71+-- The terminal device is configured with the attributes:
6972--
7073-- * IXON disabled
7174-- - disables software flow control on outgoing data. This stops the process from being
@@ -91,7 +94,8 @@ inputForCurrentTerminal config = do
9194inputForNameAndIO :: Config -> String -> Fd -> IO Input
9295inputForNameAndIO config termName termFd = do
9396 terminal <- Terminfo.setupTerm termName
94− let classifyTable = classifyTableForTerm termName terminal
97+ classifyTable <- mappend <$> pure (classifyTableForTerm termName terminal)
98+ <*> classifyTableUserOverrides
9599 (setAttrs,unsetAttrs) <- attributeControl termFd
96100 setAttrs
97101 input <- initInputForFd config classifyTable termFd
src/Graphics/Vty/Input/Events.hs+4−3
@@ -13,13 +13,13 @@ data Key = KEsc | KChar Char | KBS | KEnter
1313 | KUpLeft | KUpRight | KDownLeft | KDownRight | KCenter
1414 | KFun Int | KBackTab | KPrtScr | KPause | KIns
1515 | KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KMenu
16− deriving (Eq,Show,Ord)
16+ deriving (Eq,Show,Read,Ord)
1717
1818-- | Modifier keys. Key codes are interpreted such that users are more likely to
1919-- have Meta than Alt; for instance on the PC Linux console, 'MMeta' will
2020-- generally correspond to the physical Alt key.
2121data Modifier = MShift | MCtrl | MMeta | MAlt
22− deriving (Eq,Show,Ord)
22+ deriving (Eq,Show,Read,Ord)
2323
2424-- | Mouse buttons.
2525--
@@ -38,5 +38,6 @@ data Event
3838 | EvResize Int Int
3939 deriving (Eq,Show,Ord)
4040
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.
4243type ClassifyTable = [(String, Event)]
src/Graphics/Vty/Input/Internal.hs+4
@@ -35,11 +35,13 @@ import System.Posix.Types (Fd(..))
3535
3636data Config = Config
3737 { 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.
3839 } deriving (Show, Eq)
3940
4041instance Default Config where
4142 def = Config
4243 { singleEscPeriod = 100000
44+ , debugInputLog = Nothing
4345 }
4446
4547data Input = Input
@@ -148,6 +150,8 @@ stopIfRequested = do
148150-- I did not write this so I might just rewrite it for better understanding. Not the best of
149151-- reasons...
150152-- TODO: measure and rewrite if required.
153+-- TODO: The ClassifyTable interface requires this code to always assure later entries override
154+-- earlier.
151155compile :: ClassifyTable -> [Char] -> KClass
152156compile table = cl' where
153157 -- take all prefixes and create a set of these
src/Graphics/Vty/Input/Terminfo.hs+33
@@ -40,6 +40,39 @@ classifyTableForTerm termName term =
4040 : universalTable
4141 : termSpecificTables termName
4242
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+
4376-- | key table assumed to be applicable to all terminals.
4477universalTable :: ClassifyTable
4578universalTable = concat [visibleChars, ctrlChars, ctrlMetaChars, specialSupportKeys]
src/Graphics/Vty/Output/TerminfoBased.hs+8−1
@@ -92,10 +92,11 @@ sendCapToTerminal t cap capParams = do
9292
9393{- | Uses terminfo for all control codes. While this should provide the most compatible terminal
9494 - terminfo does not support some features that would increase efficiency and improve compatibility:
95+ -
9596 - * determine the character encoding supported by the terminal. Should this be taken from the LANG
9697 - environment variable?
97− - * Provide independent string capabilities for all display attributes.
9898 -
99+ - * Provide independent string capabilities for all display attributes.
99100 -
100101 - todo: Some display attributes like underline and bold have independent string capabilities that
101102 - should be used instead of the generic "sgr" string capability.
@@ -238,15 +239,21 @@ terminfoDisplayContext tActual terminfoCaps r = return dc
238239-- directly ; and, for no good reason, resets the colors to the default) this procedure is used:
239240--
240241-- 0. set the style attributes. This resets the fore and back color.
242+--
241243-- 1, If a foreground color is to be set then set the foreground color
244+--
242245-- 2. likewise with the background color
243246--
244247-- If the terminal does not support the sgr cap then:
245248-- if there is a change from an applied color to the default (in either the fore or back color)
246249-- then:
250+--
247251-- 0. reset all display attributes (sgr0)
252+--
248253-- 1. enter required style modes
254+--
249255-- 2. set the fore color if required
256+--
250257-- 3. set the back color if required
251258--
252259-- Entering the required style modes could require a reset of the display attributes. If this is