on master help sign in
Basic colour theme infrastructure
1beb71cDavid Christiansen
src/Idris/Colours.hs+37−15
@@ -2,31 +2,53 @@ module Idris.Colours where
2
2
3import System.Console.ANSI
3import System.Console.ANSI
4
4
5+data IdrisColour = IdrisColour { colour :: Color
6+ , vivid :: Bool
7+ , underline :: Bool
8+ , bold :: Bool
9+ }
10+
11+mkColour :: Color -> IdrisColour
12+mkColour c = IdrisColour c True False False
13+
14+data ColourTheme = ColourTheme { keywordColour :: IdrisColour
15+ , boundVarColour :: IdrisColour
16+ , implicitColour :: IdrisColour
17+ , functionColour :: IdrisColour
18+ , typeColour :: IdrisColour
19+ , dataColour :: IdrisColour
20+ }
21+
22+defaultTheme :: ColourTheme
23+defaultTheme = ColourTheme { keywordColour = IdrisColour Black True True True
24+ , boundVarColour = mkColour Magenta
25+ , implicitColour = IdrisColour Magenta True True False
26+ , functionColour = mkColour Green
27+ , typeColour = mkColour Blue
28+ , dataColour = mkColour Red
29+ }
30+
5-- Set the colour of a string using POSIX escape codes
31-- Set the colour of a string using POSIX escape codes
6−colourise :: Color -> ColorIntensity -> String -> String
32+colourise :: IdrisColour -> String -> String
33+colourise (IdrisColour c v u b) str = setSGRCode sgr ++ str ++ setSGRCode [Reset]
7−colourise c i str = let sgr = [SetColor Foreground i c]
34+ where sgr = [SetColor Foreground (if v then Vivid else Dull) c] ++
8− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
35+ (if u then [SetUnderlining SingleUnderline] else []) ++
36+ (if b then [SetConsoleIntensity BoldIntensity] else [])
9
37
10colouriseKwd :: String -> String
38colouriseKwd :: String -> String
11−colouriseKwd kwd = setSGRCode [SetUnderlining SingleUnderline
39+colouriseKwd = colourise (keywordColour defaultTheme)
12− , SetConsoleIntensity BoldIntensity
13− , SetColor Foreground Vivid Black
14− ] ++ kwd ++ setSGRCode [Reset]
15
40
16colouriseBound :: String -> String
41colouriseBound :: String -> String
17−colouriseBound = colourise Magenta Vivid
42+colouriseBound = colourise (boundVarColour defaultTheme)
18
43
19colouriseImplicit :: String -> String
44colouriseImplicit :: String -> String
20−colouriseImplicit str = let sgr = [ SetColor Foreground Vivid Magenta
45+colouriseImplicit = colourise (implicitColour defaultTheme)
21− , SetUnderlining SingleUnderline
22− ]
23− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
24
46
25colouriseFun :: String -> String
47colouriseFun :: String -> String
26−colouriseFun = colourise Green Vivid
48+colouriseFun = colourise (functionColour defaultTheme)
27
49
28colouriseType :: String -> String
50colouriseType :: String -> String
29−colouriseType = colourise Blue Vivid
51+colouriseType = colourise (typeColour defaultTheme)
30
52
31colouriseData :: String -> String
53colouriseData :: String -> String
32−colouriseData = colourise Red Vivid
54+colouriseData = colourise (dataColour defaultTheme)