@@ -2,31 +2,53 @@ module Idris.Colours where
3import System.Console.ANSI
3import System.Console.ANSI
5+data IdrisColour = IdrisColour { colour :: Color
11+mkColour :: Color -> IdrisColour
12+mkColour c = IdrisColour c True False False
14+data ColourTheme = ColourTheme { keywordColour :: IdrisColour
15+ , boundVarColour :: IdrisColour
16+ , implicitColour :: IdrisColour
17+ , functionColour :: IdrisColour
18+ , typeColour :: IdrisColour
19+ , dataColour :: IdrisColour
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
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 [])
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]
16colouriseBound :: String -> String
41colouriseBound :: String -> String
17−colouriseBound = colourise Magenta Vivid
42+colouriseBound = colourise (boundVarColour defaultTheme)
19colouriseImplicit :: String -> String
44colouriseImplicit :: String -> String
20−colouriseImplicit str = let sgr = [ SetColor Foreground Vivid Magenta
45+colouriseImplicit = colourise (implicitColour defaultTheme)
21− , SetUnderlining SingleUnderline
23− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
25colouriseFun :: String -> String
47colouriseFun :: String -> String
26−colouriseFun = colourise Green Vivid
48+colouriseFun = colourise (functionColour defaultTheme)
28colouriseType :: String -> String
50colouriseType :: String -> String
29−colouriseType = colourise Blue Vivid
51+colouriseType = colourise (typeColour defaultTheme)
31colouriseData :: String -> String
53colouriseData :: String -> String
32−colouriseData = colourise Red Vivid
54+colouriseData = colourise (dataColour defaultTheme)