on master help sign in
Move colourisation to a separate module

This will make it easier to selectively import it and to avoid cyclic dependencies.

commit6c145650338039b070c9ae7d1f57709e88d00cb7 authorDavid Christiansen <david@davidchristiansen.dk> dateWed 4 Sep 2013, 16:01 (13 years ago) parent7226659
3 files changed+36−32
idris.cabal+1−1 src/Idris/AbsSyntaxTree.hs+3−31 src/Idris/Colours.hs+32
idris.cabal+1−1
@@ -250,7 +250,7 @@ Executable idris
250250 Core.ShellParser, Core.Unify, Core.Elaborate,
251251 Core.CaseTree, Core.Constraints,
252252
253− Idris.AbsSyntax, Idris.AbsSyntaxTree,
253+ Idris.AbsSyntax, Idris.AbsSyntaxTree, Idris.Colours,
254254 Idris.Parser, Idris.Help, Idris.IdeSlave, Idris.REPL,
255255 Idris.REPLParser, Idris.ElabDecls, Idris.Error,
256256 Idris.Delaborate, Idris.Primitives, Idris.Imports,
src/Idris/AbsSyntaxTree.hs+3−31
@@ -12,11 +12,12 @@ import IRTS.CodegenCommon
1212import Util.Pretty
1313import Util.DynamicLinker
1414
15+import Idris.Colours
16+
1517import Paths_idris
1618
1719import System.Console.Haskeline
18−import System.Console.ANSI ( Color(..), ConsoleLayer(..), SGR(..), setSGRCode,
19− ColorIntensity(..), Underlining(..), ConsoleIntensity(..) )
20+
2021
2122import Control.Monad.Trans.State.Strict
2223
@@ -790,35 +791,6 @@ expandNS syn n = case syn_namespace syn of
790791
791792--- Pretty printing declarations and terms
792793
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−
822794instance Show PTerm where
823795 show tm = showImp Nothing False False tm
824796
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