-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANSIEscapes.hs
99 lines (85 loc) · 2.79 KB
/
ANSIEscapes.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module ANSIEscapes
(upLine,
downLine,
up,
down,
forward,
backward,
killLine,
restoreCursor,
saveCursor,
clearScreen,
yellow,
brown,
red,
blue,
purple,
green,
orange,
white,
yellowOnGrey,
brownOnGrey,
redOnGrey,
blueOnGrey,
purpleOnGrey,
greenOnGrey,
whiteOnGrey,
onBlack,
onGrey,
onGreyEsc,
onWhiteEsc,
resetCursor,
initTermSize) where
data Dir = UpDir | DownDir | RightDir | LeftDir
instance Show Dir where
show UpDir = "A"
show DownDir = "B"
show RightDir = "C"
show LeftDir = "D"
upLine, downLine :: IO ()
upLine = putStr "\ESC[1A"
downLine = putStr "\ESC[1B"
up, down, backward, forward :: Int -> IO ()
up = moveCursor UpDir
down = moveCursor DownDir
backward = moveCursor LeftDir
forward = moveCursor RightDir
moveCursor :: Dir -> Int -> IO ()
moveCursor dir 0 = return ()
moveCursor dir n = putStr $ "\ESC[" ++ show n ++ show dir
ctrlX :: IO ()
ctrlX = putStr "0;45"
killLine, restoreCursor, saveCursor, resetCursor, clearScreen, initTermSize :: IO ()
killLine = escape "K"
restoreCursor = escape "u"
saveCursor = escape "s"
clearScreen = escape "2J"
initTermSize = (escape "[=3h")
resetCursor = escape "0;0H"
escape :: [Char] -> IO ()
escape e = putStr $ "\ESC[" ++ e
yellow, brown, blue, red, green, purple, white :: [Char] -> [Char]
yellow str = "\ESC[1;33m" ++ str ++ "\ESC[0m"
brown str = "\ESC[0;33m" ++ str ++ "\ESC[0m"
blue str = "\ESC[1;34m" ++ str ++ "\ESC[0m"
red str = "\ESC[1;31m" ++ str ++ "\ESC[0m"
green str = "\ESC[1;32m" ++ str ++ "\ESC[0m"
purple str = "\ESC[1;35m" ++ str ++ "\ESC[0m"
white str = "\ESC[37m" ++ str ++ "\ESC[0m"
--Be careful, these assume someone else will reset the background colour
yellowOnGrey, brownOnGrey, blueOnGrey, redOnGrey, greenOnGrey, purpleOnGrey, whiteOnGrey :: [Char] -> [Char]
yellowOnGrey str = "\ESC[1;33m\ESC[47m" ++ str ++ "\ESC[0m\ESC[47m"
brownOnGrey str = "\ESC[0;33m\ESC[47m" ++ str ++ "\ESC[0m\ESC[47m"
blueOnGrey str = "\ESC[1;34m\ESC[47m" ++ str ++ "\ESC[0m\ESC[47m"
redOnGrey str = "\ESC[1;31m\ESC[47m" ++ str ++ "\ESC[0m\ESC[47m"
greenOnGrey str = "\ESC[1;32m\ESC[47m" ++ str ++ "\ESC[0m\ESC[47m"
purpleOnGrey str = "\ESC[1;35m\ESC[47m" ++ str ++ "\ESC[0m\ESC[47m"
whiteOnGrey str = "\ESC[37m" ++ str ++ "\ESC[0m"
onBlack, onGrey :: [Char] -> [Char]
onBlack str = "\ESC[40m" ++ str ++ "\ESC[0m"
onGrey str = onGreyEsc ++ str ++ onWhiteEsc
onGreyEsc, onWhiteEsc :: [Char]
onGreyEsc = "\ESC[47m"
onWhiteEsc = "\ESC[0m"
orange :: t -> t
orange str = str