on master help sign in
Allow the use of the default foreground colour. Make it the colour of the prompt.

Fixes #633.

commitaadfef8a7ab88de6a91d92062208a35003be6106 authorDavid Christiansen <david@davidchristiansen.dk> dateTue 19 Nov 2013, 17:25 (13 years ago) parent8856187
2 files changed+20−17
src/Idris/Colours.hs+8−6 src/Idris/REPLParser.hs+12−11
src/Idris/Colours.hs+8−6
@@ -9,7 +9,7 @@ module Idris.Colours (
99
1010import System.Console.ANSI
1111
12−data IdrisColour = IdrisColour { colour :: Color
12+data IdrisColour = IdrisColour { colour :: Maybe Color
1313 , vivid :: Bool
1414 , underline :: Bool
1515 , bold :: Bool
@@ -18,7 +18,7 @@ data IdrisColour = IdrisColour { colour :: Color
1818 deriving (Eq, Show)
1919
2020mkColour :: Color -> IdrisColour
21−mkColour c = IdrisColour c True False False False
21+mkColour c = IdrisColour (Just c) True False False False
2222
2323data ColourTheme = ColourTheme { keywordColour :: IdrisColour
2424 , boundVarColour :: IdrisColour
@@ -31,22 +31,24 @@ data ColourTheme = ColourTheme { keywordColour :: IdrisColour
3131 deriving (Eq, Show)
3232
3333defaultTheme :: ColourTheme
34−defaultTheme = ColourTheme { keywordColour = IdrisColour Black True True True False
34+defaultTheme = ColourTheme { keywordColour = IdrisColour Nothing True True True False
3535 , boundVarColour = mkColour Magenta
36− , implicitColour = IdrisColour Magenta True True False False
36+ , implicitColour = IdrisColour (Just Magenta) True True False False
3737 , functionColour = mkColour Green
3838 , typeColour = mkColour Blue
3939 , dataColour = mkColour Red
40− , promptColour = IdrisColour Black True False True False
40+ , promptColour = IdrisColour Nothing True False True False
4141 }
4242
4343-- Set the colour of a string using POSIX escape codes
4444colourise :: IdrisColour -> String -> String
4545colourise (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 ++
4747 (if u then [SetUnderlining SingleUnderline] else []) ++
4848 (if b then [SetConsoleIntensity BoldIntensity] else []) ++
4949 (if i then [SetItalicized True] else [])
50+ fg Nothing = []
51+ fg (Just c) = [SetColor Foreground (if v then Vivid else Dull) c]
5052
5153colouriseKwd :: ColourTheme -> String -> String
5254colouriseKwd t = colourise (keywordColour t)
src/Idris/REPLParser.hs+12−11
@@ -107,18 +107,19 @@ pOption = do discard (P.symbol "errorcontext"); return ErrContext
107107 <|> do discard (P.symbol "showimplicits"); return ShowImpl
108108
109109
110−colours :: [(String, Color)]
111−colours = [ ("black", Black)
112− , ("red", Red)
113− , ("green", Green)
114− , ("yellow", Yellow)
115− , ("blue", Blue)
116− , ("magenta", Magenta)
117− , ("cyan", Cyan)
118− , ("white", White)
110+colours :: [(String, Maybe Color)]
111+colours = [ ("black", Just Black)
112+ , ("red", Just Red)
113+ , ("green", Just Green)
114+ , ("yellow", Just Yellow)
115+ , ("blue", Just Blue)
116+ , ("magenta", Just Magenta)
117+ , ("cyan", Just Cyan)
118+ , ("white", Just White)
119+ , ("default", Nothing)
119120 ]
120121
121−pColour :: P.IdrisParser Color
122+pColour :: P.IdrisParser (Maybe Color)
122123pColour = doColour colours
123124 where doColour [] = fail "Unknown colour"
124125 doColour ((s, c):cs) = (try (P.symbol s) >> return c) <|> doColour cs
@@ -156,7 +157,7 @@ pColourType = doColourType colourTypes
156157
157158pSetColourCmd :: P.IdrisParser Command
158159pSetColourCmd = (do c <- pColourType
159− let defaultColour = IdrisColour Black True False False False
160+ let defaultColour = IdrisColour Nothing True False False False
160161 opts <- sepBy pColourMod (P.whiteSpace)
161162 let colour = foldr ($) defaultColour $ reverse opts
162163 return $ SetColour c colour)