1010--
1111-- = Debug
1212--
13+ -- == @colorMode@
14+ --
15+ -- Format:
16+ --
17+ -- @
18+ -- colorMode \"<ColorMode8|ColorMode16|ColorMode240 <int>|FullColor>\"
19+ -- @
20+ --
21+ -- The preferred color mode to use, chosen from the constructors of the
22+ -- 'ColorMode' type. If absent, the backend driver may detect and choose
23+ -- an appropriate color mode. Implementor's note: backend packages
24+ -- should respect this setting when it is present even when their
25+ -- detection indicates that a different color mode should be used.
26+ --
1327-- == @debugLog@
1428--
1529-- Format:
@@ -113,7 +127,9 @@ import Data.Monoid (Monoid(..))
113127#if !(MIN_VERSION_base(4,11,0))
114128import Data.Semigroup (Semigroup (.. ))
115129#endif
130+ import Text.Read (readMaybe )
116131
132+ import Graphics.Vty.Attributes.Color (ColorMode (.. ))
117133import Graphics.Vty.Input.Events
118134
119135import GHC.Generics
@@ -291,6 +307,12 @@ debugLogDecl = do
291307 path <- P. stringLiteral configLexer
292308 return defaultConfig { configDebugLog = Just path }
293309
310+ colorModeDecl :: Parser VtyUserConfig
311+ colorModeDecl = do
312+ " colorMode" <- P. identifier configLexer
313+ mode <- P. stringLiteral configLexer
314+ return defaultConfig { configPreferredColorMode = readMaybe mode }
315+
294316widthMapDecl :: Parser VtyUserConfig
295317widthMapDecl = do
296318 " widthMap" <- P. identifier configLexer
@@ -304,7 +326,7 @@ ignoreLine = void $ manyTill anyChar newline
304326parseConfig :: Parser VtyUserConfig
305327parseConfig = liftM mconcat $ many $ do
306328 P. whiteSpace configLexer
307- let directives = [try mapDecl, try debugLogDecl, try widthMapDecl]
329+ let directives = [try mapDecl, try debugLogDecl, try widthMapDecl, try colorModeDecl ]
308330 choice directives <|> (ignoreLine >> return defaultConfig)
309331
310332class Parse a where parseValue :: Parser a
0 commit comments