Skip to content

Commit c9f50ca

Browse files
committed
Config parser: parse "colorMode" field
1 parent 9d100d7 commit c9f50ca

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Graphics/Vty/Config.hs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
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))
114128
import Data.Semigroup (Semigroup(..))
115129
#endif
130+
import Text.Read (readMaybe)
116131

132+
import Graphics.Vty.Attributes.Color (ColorMode(..))
117133
import Graphics.Vty.Input.Events
118134

119135
import 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+
294316
widthMapDecl :: Parser VtyUserConfig
295317
widthMapDecl = do
296318
"widthMap" <- P.identifier configLexer
@@ -304,7 +326,7 @@ ignoreLine = void $ manyTill anyChar newline
304326
parseConfig :: Parser VtyUserConfig
305327
parseConfig = 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

310332
class Parse a where parseValue :: Parser a

0 commit comments

Comments
 (0)