-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatting.ps1
294 lines (282 loc) Β· 6.39 KB
/
formatting.ps1
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# Colors and text style, based on https://en.wikipedia.org/wiki/ANSI_escape_code
enum TextStyles {
reset
bold
thin
italic
underline
slowBlink
rapidBlink
inverse
conceal
crossedOut
fontPrimary
fontAlt1
fontAlt2
fontAlt3
fontAlt4
fontAlt5
fontAlt6
fontAlt7
fontAlt8
fontAlt9
fraktur
underlineDouble
resetItalic
resetFraktur
resetUnderline
resetBlink
resetInverse
resetConceal
resetCrossedOut
}
enum TextColors {
fgDarkBlack = 30
fgDarkRed
fgDarkGreen
fgDarkYellow
fgDarkBlue
fgDarkMagenta
fgDarkCyan
fgDarkWhite
bgDarkBlack = 40
bgDarkRed
bgDarkGreen
bgDarkYellow
bgDarkBlue
bgDarkMagenta
bgDarkCyan
bgDarkWhite
fgBlack = 90
fgRed
fgGreen
fgYellow
fgBlue
fgMagenta
fgCyan
fgWhite
bgBlack = 100
bgRed
bgGreen
bgYellow
bgBlue
bgMagenta
bgCyan
bgWhite
}
function Try-Styles {
[TextStyles].GetEnumNames() | ForEach-Object {
$style = [int]([TextStyles]::$_)
$escaped = (escape $style)
$reset = "$([char]27)[m"
"$escaped{0,-20}$reset{1,3}" -f $_, $style
}
}
function Try-Colors {
[TextColors].GetEnumNames() | ForEach-Object {
$style = [int]([TextColors]::$_)
$escaped = (escape $style)
$reset = "$([char]27)[m"
"$escaped{0,-20}$reset{1,3}" -f $_, $style
}
}
function escape ($attr) {
return "$([char]27)[$([int]$attr)m"
}
function Length-Without-ANSI([string] $str) {
return ($str -replace "`e[\[0-9]*m").Length
}
function With-Style([TextStyles] $style, $message) {
return "{0}{1}{2}" -f (escape $style), $message, (escape $reset)
}
function With-Color ([TextColors] $color, $message) {
return "{0}{1}{2}" -f (escape $color), $message, (escape $reset)
}
# Styles
function With-Reset ($message) {
return With-Style reset $message
}
function With-Bold ($message) {
return With-Style bold $message
}
function With-Thin ($message) {
return With-Style thin $message
}
function With-Italic ($message) {
return With-Style italic $message
}
function With-Underline ($message) {
return With-Style underline $message
}
function With-SlowBlink ($message) {
return With-Style slowBlink $message
}
function With-RapidBlink ($message) {
return With-Style rapidBlink $message
}
function With-Inverse ($message) {
return With-Style inverse $message
}
function With-Conceal ($message) {
return With-Style conceal $message
}
function With-CrossedOut ($message) {
return With-Style crossedOut $message
}
function With-FontPrimary ($message) {
return With-Style fontPrimary $message
}
function With-FontAlt1 ($message) {
return With-Style fontAlt1 $message
}
function With-FontAlt2 ($message) {
return With-Style fontAlt2 $message
}
function With-FontAlt3 ($message) {
return With-Style fontAlt3 $message
}
function With-FontAlt4 ($message) {
return With-Style fontAlt4 $message
}
function With-FontAlt5 ($message) {
return With-Style fontAlt5 $message
}
function With-FontAlt6 ($message) {
return With-Style fontAlt6 $message
}
function With-FontAlt7 ($message) {
return With-Style fontAlt7 $message
}
function With-FontAlt8 ($message) {
return With-Style fontAlt8 $message
}
function With-FontAlt9 ($message) {
return With-Style fontAlt9 $message
}
function With-Fraktur ($message) {
return With-Style fraktur $message
}
function With-UnderlineDouble ($message) {
return With-Style underlineDouble $message
}
function With-ResetItalic ($message) {
return With-Style resetItalic $message
}
function With-ResetFraktur ($message) {
return With-Style resetFraktur $message
}
function With-ResetUnderline ($message) {
return With-Style resetUnderline $message
}
function With-ResetBlink ($message) {
return With-Style resetBlink $message
}
function With-ResetInverse ($message) {
return With-Style resetInverse $message
}
function With-ResetConceal ($message) {
return With-Style resetConceal $message
}
function With-ResetCrossedOut ($message) {
return With-Style resetCrossedOut $message
}
# Foreground colors
function With-Black ($message) {
return With-Color fgBlack $message
}
function With-Red ($message) {
return With-Color fgRed $message
}
function With-Green ($message) {
return With-Color fgGreen $message
}
function With-Yellow ($message) {
return With-Color fgYellow $message
}
function With-Blue ($message) {
return With-Color fgBlue $message
}
function With-Magenta ($message) {
return With-Color fgMagenta $message
}
function With-Cyan ($message) {
return With-Color fgCyan $message
}
function With-White ($message) {
return With-Color fgWhite $message
}
# Dark foreground colors
function With-DarkBlack ($message) {
return With-Color fgDarkBlack $message
}
function With-DarkRed ($message) {
return With-Color fgDarkRed $message
}
function With-DarkGreen ($message) {
return With-Color fgDarkGreen $message
}
function With-DarkYellow ($message) {
return With-Color fgDarkYellow $message
}
function With-DarkBlue ($message) {
return With-Color fgDarkBlue $message
}
function With-DarkMagenta ($message) {
return With-Color fgDarkMagenta $message
}
function With-DarkCyan ($message) {
return With-Color fgDarkCyan $message
}
function With-DarkWhite ($message) {
return With-Color fgDarkWhite $message
}
# Background colors
function With-Background-Black ($message) {
return With-Color bgBlack $message
}
function With-Background-Red ($message) {
return With-Color bgRed $message
}
function With-Background-Green ($message) {
return With-Color bgGreen $message
}
function With-Background-Yellow ($message) {
return With-Color bgYellow $message
}
function With-Background-Blue ($message) {
return With-Color bgBlue $message
}
function With-Background-Magenta ($message) {
return With-Color bgMagenta $message
}
function With-Background-Cyan ($message) {
return With-Color bgCyan $message
}
function With-Background-White ($message) {
return With-Color bgWhite $message
}
# Dark background colors
function With-Background-DarkBlack ($message) {
return With-Color bgDarkBlack $message
}
function With-Background-DarkRed ($message) {
return With-Color bgDarkRed $message
}
function With-Background-DarkGreen ($message) {
return With-Color bgDarkGreen $message
}
function With-Background-DarkYellow ($message) {
return With-Color bgDarkYellow $message
}
function With-Background-DarkBlue ($message) {
return With-Color bgDarkBlue $message
}
function With-Background-DarkMagenta ($message) {
return With-Color bgDarkMagenta $message
}
function With-Background-DarkCyan ($message) {
return With-Color bgDarkCyan $message
}
function With-Background-DarkWhite ($message) {
return With-Color bgDarkWhite $message
}