on master help sign in
Allow the use of the default foreground colour. Make it the colour of the prompt.
aadfef8David Christiansen
src/Idris/Colours.hs+8−6
@@ -9,7 +9,7 @@ module Idris.Colours (
9
9
10import System.Console.ANSI
10import System.Console.ANSI
11
11
12−data IdrisColour = IdrisColour { colour :: Color
12+data IdrisColour = IdrisColour { colour :: Maybe Color
13 , vivid :: Bool
13 , vivid :: Bool
14 , underline :: Bool
14 , underline :: Bool
15 , bold :: Bool
15 , bold :: Bool
@@ -18,7 +18,7 @@ data IdrisColour = IdrisColour { colour :: Color
18 deriving (Eq, Show)
18 deriving (Eq, Show)
19
19
20mkColour :: Color -> IdrisColour
20mkColour :: Color -> IdrisColour
21−mkColour c = IdrisColour c True False False False
21+mkColour c = IdrisColour (Just c) True False False False
22
22
23data ColourTheme = ColourTheme { keywordColour :: IdrisColour
23data ColourTheme = ColourTheme { keywordColour :: IdrisColour
24 , boundVarColour :: IdrisColour
24 , boundVarColour :: IdrisColour
@@ -31,22 +31,24 @@ data ColourTheme = ColourTheme { keywordColour :: IdrisColour
31 deriving (Eq, Show)
31 deriving (Eq, Show)
32
32
33defaultTheme :: ColourTheme
33defaultTheme :: ColourTheme
34−defaultTheme = ColourTheme { keywordColour = IdrisColour Black True True True False
34+defaultTheme = ColourTheme { keywordColour = IdrisColour Nothing True True True False
35 , boundVarColour = mkColour Magenta
35 , boundVarColour = mkColour Magenta
36− , implicitColour = IdrisColour Magenta True True False False
36+ , implicitColour = IdrisColour (Just Magenta) True True False False
37 , functionColour = mkColour Green
37 , functionColour = mkColour Green
38 , typeColour = mkColour Blue
38 , typeColour = mkColour Blue
39 , dataColour = mkColour Red
39 , dataColour = mkColour Red
40− , promptColour = IdrisColour Black True False True False
40+ , promptColour = IdrisColour Nothing True False True False
41 }
41 }
42
42
43-- Set the colour of a string using POSIX escape codes
43-- Set the colour of a string using POSIX escape codes
44colourise :: IdrisColour -> String -> String
44colourise :: IdrisColour -> String -> String
45colourise (IdrisColour c v u b i) str = setSGRCode sgr ++ str ++ setSGRCode [Reset]
45colourise (IdrisColour c v u b i) str = setSGRCode sgr ++ str ++ setSGRCode [Reset]
46− where sgr = [SetColor Foreground (if v then Vivid else Dull) c] ++
46+ where sgr = fg c ++
47 (if u then [SetUnderlining SingleUnderline] else []) ++
47 (if u then [SetUnderlining SingleUnderline] else []) ++
48 (if b then [SetConsoleIntensity BoldIntensity] else []) ++
48 (if b then [SetConsoleIntensity BoldIntensity] else []) ++
49 (if i then [SetItalicized True] else [])
49 (if i then [SetItalicized True] else [])
50+ fg Nothing = []
51+ fg (Just c) = [SetColor Foreground (if v then Vivid else Dull) c]
50
52
51colouriseKwd :: ColourTheme -> String -> String
53colouriseKwd :: ColourTheme -> String -> String
52colouriseKwd t = colourise (keywordColour t)
54colouriseKwd t = colourise (keywordColour t)
src/Idris/REPLParser.hs+12−11
@@ -107,18 +107,19 @@ pOption = do discard (P.symbol "errorcontext"); return ErrContext
107 <|> do discard (P.symbol "showimplicits"); return ShowImpl
107 <|> do discard (P.symbol "showimplicits"); return ShowImpl
108
108
109
109
110−colours :: [(String, Color)]
110+colours :: [(String, Maybe Color)]
111−colours = [ ("black", Black)
111+colours = [ ("black", Just Black)
112− , ("red", Red)
112+ , ("red", Just Red)
113− , ("green", Green)
113+ , ("green", Just Green)
114− , ("yellow", Yellow)
114+ , ("yellow", Just Yellow)
115− , ("blue", Blue)
115+ , ("blue", Just Blue)
116− , ("magenta", Magenta)
116+ , ("magenta", Just Magenta)
117− , ("cyan", Cyan)
117+ , ("cyan", Just Cyan)
118− , ("white", White)
118+ , ("white", Just White)
119+ , ("default", Nothing)
119 ]
120 ]
120
121
121−pColour :: P.IdrisParser Color
122+pColour :: P.IdrisParser (Maybe Color)
122pColour = doColour colours
123pColour = doColour colours
123 where doColour [] = fail "Unknown colour"
124 where doColour [] = fail "Unknown colour"
124 doColour ((s, c):cs) = (try (P.symbol s) >> return c) <|> doColour cs
125 doColour ((s, c):cs) = (try (P.symbol s) >> return c) <|> doColour cs
@@ -156,7 +157,7 @@ pColourType = doColourType colourTypes
156
157
157pSetColourCmd :: P.IdrisParser Command
158pSetColourCmd :: P.IdrisParser Command
158pSetColourCmd = (do c <- pColourType
159pSetColourCmd = (do c <- pColourType
159− let defaultColour = IdrisColour Black True False False False
160+ let defaultColour = IdrisColour Nothing True False False False
160 opts <- sepBy pColourMod (P.whiteSpace)
161 opts <- sepBy pColourMod (P.whiteSpace)
161 let colour = foldr ($) defaultColour $ reverse opts
162 let colour = foldr ($) defaultColour $ reverse opts
162 return $ SetColour c colour)
163 return $ SetColour c colour)