on master help sign in
Config: support specifying character width map paths

This change adds a new Config record field, termWidthMaps, which holds a list of pairs that map terminal names to width table file paths. This change also extends the configuration parser to support lines of the form widthMap <Terminal> <Path> where <Terminal> must be a double-quoted string literal indicating the value of TERM for which the specified map should be active, and <Path> must be a double-quoted string literal specifying the file path to the width table file to use. E.g., widthMap "xterm" "/home/user/.vty/width_table_xterm.dat"

commitb73efb4b7312d8159818e41e5f76036a004c938c authorJonathan Daugherty <cygnus@foobox.com> dateMon 2 Mar 2020, 14:24 (7 years ago) parente882198
1 file changed+12−1
src/Graphics/Vty/Config.hs+12−1
src/Graphics/Vty/Config.hs+12−1
@@ -146,6 +146,8 @@ data Config = Config
146146 -- | The terminal name used to look up terminfo capabilities.
147147 -- The default is the value of the TERM environment variable.
148148 , termName :: Maybe String
149+ -- | Terminal width map files.
150+ , termWidthMaps :: [(String, FilePath)]
149151 } deriving (Show, Eq)
150152
151153defaultConfig :: Config
@@ -163,6 +165,7 @@ instance Semigroup Config where
163165 , inputFd = inputFd c1 <|> inputFd c0
164166 , outputFd = outputFd c1 <|> outputFd c0
165167 , termName = termName c1 <|> termName c0
168+ , termWidthMaps = termWidthMaps c1 <|> termWidthMaps c0
166169 }
167170
168171instance Monoid Config where
@@ -176,6 +179,7 @@ instance Monoid Config where
176179 , inputFd = Nothing
177180 , outputFd = Nothing
178181 , termName = Nothing
182+ , termWidthMaps = []
179183 }
180184#if !(MIN_VERSION_base(4,11,0))
181185 mappend = (<>)
@@ -283,13 +287,20 @@ debugLogDecl = do
283287 path <- P.stringLiteral configLexer
284288 return defaultConfig { debugLog = Just path }
285289
290+widthMapDecl :: Parser Config
291+widthMapDecl = do
292+ "widthMap" <- P.identifier configLexer
293+ tName <- P.stringLiteral configLexer
294+ path <- P.stringLiteral configLexer
295+ return defaultConfig { termWidthMaps = [(tName, path)] }
296+
286297ignoreLine :: Parser ()
287298ignoreLine = void $ manyTill anyChar newline
288299
289300parseConfig :: Parser Config
290301parseConfig = liftM mconcat $ many $ do
291302 P.whiteSpace configLexer
292− let directives = [try mapDecl, try debugLogDecl]
303+ let directives = [try mapDecl, try debugLogDecl, try widthMapDecl]
293304 choice directives <|> (ignoreLine >> return defaultConfig)
294305
295306class Parse a where parseValue :: Parser a