-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConsole.hs
48 lines (39 loc) · 1.4 KB
/
Console.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Console (MessageE(..), putMessage, putMessageLn, highLight, highLightLn, intense) where
import System.Console.ANSI
import qualified Source
data MessageE = Error | Warning | Note
colorForMessageE :: MessageE -> Color
colorForMessageE Error = Red
colorForMessageE Warning = Magenta
colorForMessageE Note = Black
stringForMessageE :: MessageE -> String
stringForMessageE Error = "error: "
stringForMessageE Warning = "warning: "
stringForMessageE Note = "note: "
putMessage :: MessageE -> String -> Source.Location -> String -> IO ()
putMessage kind file loc err = do
setSGR [SetConsoleIntensity BoldIntensity]
putStr (file ++ ":" ++ show (1 + fst loc) ++ ":" ++ show (1 + snd loc) ++ ": ")
setSGR [SetColor Foreground Vivid (colorForMessageE kind), SetConsoleIntensity BoldIntensity]
putStr (stringForMessageE kind)
setSGR [Reset, SetConsoleIntensity BoldIntensity]
putStr err
setSGR []
putMessageLn :: MessageE -> String -> Source.Location -> String -> IO ()
putMessageLn kind file loc err = do
putMessage kind file loc err
putStr "\n"
highLight :: String -> IO ()
highLight str = do
setSGR [SetColor Foreground Vivid Yellow, SetColor Background Dull Red, SetConsoleIntensity BoldIntensity]
putStr str
setSGR []
highLightLn :: String -> IO ()
highLightLn str = do
highLight str
putStr "\n"
intense :: String -> IO ()
intense str = do
setSGR [Reset, SetConsoleIntensity BoldIntensity]
putStr str
setSGR []