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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
module System.Console.ANSI.Codes
(
cursorPos
, cursorHome
, cursorUp
, cursorDown
, cursorFwd
, cursorBack
, saveCursor
, restoreCursor
, clear
, eraseLine
, normal
, bold
, faint
, italic
, underline
, blinkSlow
, blinkRapid
, inverse
, concealed
, crossedout
, black
, red
, green
, yellow
, blue
, cyan
, magenta
, white
, fgDefault
, bgBlack
, bgRed
, bgGreen
, bgYellow
, bgBlue
, bgCyan
, bgMagenta
, bgWhite
, bgDefault
) where
import List (isSuffixOf)
cursorPos :: Int -> Int -> String
cursorPos r c = cmd (show r ++ ";" ++ show c ++ "H")
cursorHome :: String
cursorHome = cmd "H"
cursorUp :: Int -> String
cursorUp = moveCursor "A"
cursorDown :: Int -> String
cursorDown = moveCursor "B"
cursorFwd :: Int -> String
cursorFwd = moveCursor "C"
cursorBack :: Int -> String
cursorBack = moveCursor "D"
saveCursor :: String
saveCursor = cmd "s"
restoreCursor :: String
restoreCursor = cmd "u"
clear :: String
clear = cmd "2J"
eraseLine :: String
eraseLine = cmd "K"
normal :: String -> String
normal = mode 0
bold :: String -> String
bold = mode 1
faint :: String -> String
faint = mode 2
italic :: String -> String
italic = mode 3
underline :: String -> String
underline = mode 4
blinkSlow :: String -> String
blinkSlow = mode 5
blinkRapid :: String -> String
blinkRapid = mode 6
inverse :: String -> String
inverse = mode 7
concealed :: String -> String
concealed = mode 8
crossedout :: String -> String
crossedout = mode 9
black :: String -> String
black = mode 30
red :: String -> String
red = mode 31
green :: String -> String
green = mode 32
yellow :: String -> String
yellow = mode 33
blue :: String -> String
blue = mode 34
magenta :: String -> String
magenta = mode 35
cyan :: String -> String
cyan = mode 36
white :: String -> String
white = mode 37
fgDefault :: String -> String
fgDefault = mode 39
bgBlack :: String -> String
bgBlack = mode 40
bgRed :: String -> String
bgRed = mode 41
bgGreen :: String -> String
bgGreen = mode 42
bgYellow :: String -> String
bgYellow = mode 43
bgBlue :: String -> String
bgBlue = mode 44
bgMagenta :: String -> String
bgMagenta = mode 45
bgCyan :: String -> String
bgCyan = mode 46
bgWhite :: String -> String
bgWhite = mode 47
bgDefault :: String -> String
bgDefault = mode 49
moveCursor :: String -> Int -> String
moveCursor s n = cmd (show n ++ s)
mode :: Int -> String -> String
mode n s = cmd (show n ++ "m") ++ s ++ if end `isSuffixOf` s then "" else end
where end = cmd "0m"
cmd :: String -> String
cmd s = '\ESC' : '[' : s
|