@@ -2,31 +2,53 @@ module Idris.Colours where
22
33import System.Console.ANSI
44
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+
531-- Set the colour of a string using POSIX escape codes
6−colourise :: Color -> ColorIntensity -> String -> String
7−colourise c i str = let sgr = [SetColor Foreground i c]
8− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
32+colourise :: IdrisColour -> String -> String
33+colourise (IdrisColour c v u b) str = setSGRCode sgr ++ str ++ setSGRCode [Reset]
34+ where sgr = [SetColor Foreground (if v then Vivid else Dull) c] ++
35+ (if u then [SetUnderlining SingleUnderline] else []) ++
36+ (if b then [SetConsoleIntensity BoldIntensity] else [])
937
1038colouriseKwd :: String -> String
11−colouriseKwd kwd = setSGRCode [SetUnderlining SingleUnderline
12− , SetConsoleIntensity BoldIntensity
13− , SetColor Foreground Vivid Black
14− ] ++ kwd ++ setSGRCode [Reset]
39+colouriseKwd = colourise (keywordColour defaultTheme)
1540
1641colouriseBound :: String -> String
17−colouriseBound = colourise Magenta Vivid
42+colouriseBound = colourise (boundVarColour defaultTheme)
1843
1944colouriseImplicit :: String -> String
20−colouriseImplicit str = let sgr = [ SetColor Foreground Vivid Magenta
21− , SetUnderlining SingleUnderline
22− ]
23− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
45+colouriseImplicit = colourise (implicitColour defaultTheme)
2446
2547colouriseFun :: String -> String
26−colouriseFun = colourise Green Vivid
48+colouriseFun = colourise (functionColour defaultTheme)
2749
2850colouriseType :: String -> String
29−colouriseType = colourise Blue Vivid
51+colouriseType = colourise (typeColour defaultTheme)
3052
3153colouriseData :: String -> String
32−colouriseData = colourise Red Vivid
54+colouriseData = colourise (dataColour defaultTheme)