imported fquery-0.2
[fquery.git] / Adelie / Colour.hs
blobc9b88b5e04fde60555575c9fd7f370a639b68276
1 -- Colour.hs
2 --
3 -- Escape codes for colouring in output.
5 module Adelie.Colour (
6 gray, inGray,
7 red, inRed,
8 green, inGreen,
9 yellow, inYellow,
10 blue, inBlue,
11 magenta, inMagenta,
12 cyan, inCyan,
13 white, inWhite,
14 off,
15 off2
16 ) where
18 import Monad (when)
20 import Adelie.Options
22 gray, red, green, yellow, blue, magenta, cyan, white, off, off2 :: IO ()
24 gray = whenM colourEnabled $ putStr "\27[30;01m"
25 red = whenM colourEnabled $ putStr "\27[31;01m"
26 green = whenM colourEnabled $ putStr "\27[32;01m"
27 yellow = whenM colourEnabled $ putStr "\27[33;01m"
28 blue = whenM colourEnabled $ putStr "\27[34;01m"
29 magenta = whenM colourEnabled $ putStr "\27[35;01m"
30 cyan = whenM colourEnabled $ putStr "\27[36;01m"
31 white = whenM colourEnabled $ putStr "\27[37;01m"
32 off = whenM colourEnabled $ putStr "\27[0m"
33 off2 = do
34 true <- colourEnabled
35 if true
36 then putStrLn "\27[0m"
37 else putChar '\n'
39 whenM :: IO Bool -> IO () -> IO ()
40 whenM cond f = cond >>= (flip when f)
42 ----------------------------------------------------------------
44 inGray, inRed, inGreen, inYellow :: IO () -> IO ()
45 inBlue, inMagenta, inCyan, inWhite :: IO () -> IO ()
47 inGray f = gray >> f >> off
48 inRed f = red >> f >> off
49 inGreen f = yellow >> f >> off
50 inYellow f = yellow >> f >> off
51 inBlue f = blue >> f >> off
52 inMagenta f = magenta >> f >> off
53 inCyan f = cyan >> f >> off
54 inWhite f = white >> f >> off