on master help sign in
Move colourisation to a separate module
6c14565David Christiansen
idris.cabal+1−1
@@ -250,7 +250,7 @@ Executable idris
250 Core.ShellParser, Core.Unify, Core.Elaborate,
250 Core.ShellParser, Core.Unify, Core.Elaborate,
251 Core.CaseTree, Core.Constraints,
251 Core.CaseTree, Core.Constraints,
252
252
253− Idris.AbsSyntax, Idris.AbsSyntaxTree,
253+ Idris.AbsSyntax, Idris.AbsSyntaxTree, Idris.Colours,
254 Idris.Parser, Idris.Help, Idris.IdeSlave, Idris.REPL,
254 Idris.Parser, Idris.Help, Idris.IdeSlave, Idris.REPL,
255 Idris.REPLParser, Idris.ElabDecls, Idris.Error,
255 Idris.REPLParser, Idris.ElabDecls, Idris.Error,
256 Idris.Delaborate, Idris.Primitives, Idris.Imports,
256 Idris.Delaborate, Idris.Primitives, Idris.Imports,
src/Idris/AbsSyntaxTree.hs+3−31
@@ -12,11 +12,12 @@ import IRTS.CodegenCommon
12import Util.Pretty
12import Util.Pretty
13import Util.DynamicLinker
13import Util.DynamicLinker
14
14
15+import Idris.Colours
16+
15import Paths_idris
17import Paths_idris
16
18
17import System.Console.Haskeline
19import System.Console.Haskeline
18−import System.Console.ANSI ( Color(..), ConsoleLayer(..), SGR(..), setSGRCode,
20+
19− ColorIntensity(..), Underlining(..), ConsoleIntensity(..) )
20
21
21import Control.Monad.Trans.State.Strict
22import Control.Monad.Trans.State.Strict
22
23
@@ -790,35 +791,6 @@ expandNS syn n = case syn_namespace syn of
790
791
791--- Pretty printing declarations and terms
792--- Pretty printing declarations and terms
792
793
793−-- Set the colour of a string using POSIX escape codes
794−colourise :: Color -> ColorIntensity -> String -> String
795−colourise c i str = let sgr = [SetColor Foreground i c]
796− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
797−
798−colouriseKwd :: String -> String
799−colouriseKwd kwd = setSGRCode [SetUnderlining SingleUnderline
800− , SetConsoleIntensity BoldIntensity
801− , SetColor Foreground Vivid Black
802− ] ++ kwd ++ setSGRCode [Reset]
803−
804−colouriseBound :: String -> String
805−colouriseBound = colourise Magenta Vivid
806−
807−colouriseImplicit :: String -> String
808−colouriseImplicit str = let sgr = [ SetColor Foreground Vivid Magenta
809− , SetUnderlining SingleUnderline
810− ]
811− in setSGRCode sgr ++ str ++ setSGRCode [Reset]
812−
813−colouriseFun :: String -> String
814−colouriseFun = colourise Green Vivid
815−
816−colouriseType :: String -> String
817−colouriseType = colourise Blue Vivid
818−
819−colouriseData :: String -> String
820−colouriseData = colourise Red Vivid
821−
822instance Show PTerm where
794instance Show PTerm where
823 show tm = showImp Nothing False False tm
795 show tm = showImp Nothing False False tm
824
796
src/Idris/Colours.hsnew file+32
@@ -0,0 +1,32 @@
1+module Idris.Colours where
2+
3+import System.Console.ANSI
4+
5+-- 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]
9+
10+colouriseKwd :: String -> String
11+colouriseKwd kwd = setSGRCode [SetUnderlining SingleUnderline
12+ , SetConsoleIntensity BoldIntensity
13+ , SetColor Foreground Vivid Black
14+ ] ++ kwd ++ setSGRCode [Reset]
15+
16+colouriseBound :: String -> String
17+colouriseBound = colourise Magenta Vivid
18+
19+colouriseImplicit :: String -> String
20+colouriseImplicit str = let sgr = [ SetColor Foreground Vivid Magenta
21+ , SetUnderlining SingleUnderline
22+ ]
23+ in setSGRCode sgr ++ str ++ setSGRCode [Reset]
24+
25+colouriseFun :: String -> String
26+colouriseFun = colourise Green Vivid
27+
28+colouriseType :: String -> String
29+colouriseType = colourise Blue Vivid
30+
31+colouriseData :: String -> String
32+colouriseData = colourise Red Vivid