on master help sign in
Merge pull request #640 from david-christiansen/color-theme-default-option

Allow the use of the default foreground colour. Make it the colour of the prompt.

commit27a6ec74ae2ba79532789f8bcb5c414fce0370f2 authorEdwin Brady <edwin.brady@gmail.com> dateTue 19 Nov 2013, 12:34 (13 years ago) parent32852afaadfef8
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
@@ -106,18 +106,19 @@ pOption = do discard (P.symbol "errorcontext"); return ErrContext
106106 <|> do discard (P.symbol "showimplicits"); return ShowImpl
107107
108108
109−colours :: [(String, Color)]
110−colours = [ ("black", Black)
111− , ("red", Red)
112− , ("green", Green)
113− , ("yellow", Yellow)
114− , ("blue", Blue)
115− , ("magenta", Magenta)
116− , ("cyan", Cyan)
117− , ("white", White)
109+colours :: [(String, Maybe Color)]
110+colours = [ ("black", Just Black)
111+ , ("red", Just Red)
112+ , ("green", Just Green)
113+ , ("yellow", Just Yellow)
114+ , ("blue", Just Blue)
115+ , ("magenta", Just Magenta)
116+ , ("cyan", Just Cyan)
117+ , ("white", Just White)
118+ , ("default", Nothing)
118119 ]
119120
120−pColour :: P.IdrisParser Color
121+pColour :: P.IdrisParser (Maybe Color)
121122pColour = doColour colours
122123 where doColour [] = fail "Unknown colour"
123124 doColour ((s, c):cs) = (try (P.symbol s) >> return c) <|> doColour cs
@@ -155,7 +156,7 @@ pColourType = doColourType colourTypes
155156
156157pSetColourCmd :: P.IdrisParser Command
157158pSetColourCmd = (do c <- pColourType
158− let defaultColour = IdrisColour Black True False False False
159+ let defaultColour = IdrisColour Nothing True False False False
159160 opts <- sepBy pColourMod (P.whiteSpace)
160161 let colour = foldr ($) defaultColour $ reverse opts
161162 return $ SetColour c colour)