Passed
Push — develop ( 6a6d60...d23fdb )
by nguereza
02:35
created

Color::line()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 4
nop 4
dl 0
loc 24
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Platine Console
5
 *
6
 * Platine Console is a powerful library with support of custom
7
 * style to build command line interface applications
8
 *
9
 * This content is released under the MIT License (MIT)
10
 *
11
 * Copyright (c) 2020 Platine Console
12
 * Copyright (c) 2017-2020 Jitendra Adhikari
13
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining a copy
15
 * of this software and associated documentation files (the "Software"), to deal
16
 * in the Software without restriction, including without limitation the rights
17
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
 * copies of the Software, and to permit persons to whom the Software is
19
 * furnished to do so, subject to the following conditions:
20
 *
21
 * The above copyright notice and this permission notice shall be included in all
22
 * copies or substantial portions of the Software.
23
 *
24
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
 * SOFTWARE.
31
 */
32
33
/**
34
 *  @file Color.php
35
 *
36
 *  The Output Color class
37
 *
38
 *  @package    Platine\Console\Output
39
 *  @author Platine Developers Team
40
 *  @copyright  Copyright (c) 2020
41
 *  @license    http://opensource.org/licenses/MIT  MIT License
42
 *  @link   http://www.iacademy.cf
43
 *  @version 1.0.0
44
 *  @filesource
45
 */
46
47
declare(strict_types=1);
48
49
namespace Platine\Console\Output;
50
51
use Error;
52
53
/**
54
 * Class Color
55
 * @package Platine\Console\Output
56
 *
57
 * @method string bold(string $text)
58
 * @method string dim(string $text)
59
 * @method string italic(string $text)
60
 * @method string underline(string $text)
61
 * @method string black(string $text)
62
 * @method string red(string $text)
63
 * @method string green(string $text)
64
 * @method string yellow(string $text)
65
 * @method string blue(string $text)
66
 * @method string purple(string $text)
67
 * @method string cyan(string $text)
68
 * @method string white(string $text)
69
 * @method string gray(string $text)
70
 * @method string darkgray(string $text)
71
 * @method string bgBlack(string $text)
72
 * @method string bgRed(string $text)
73
 * @method string bgGreen(string $text)
74
 * @method string bgYellow(string $text)
75
 * @method string bgBlue(string $text)
76
 * @method string bgPurple(string $text)
77
 * @method string bgCyan(string $text)
78
 * @method string bgWhite(string $text)
79
 * @method string bgGray(string $text)
80
 * @method string bgDarkgray(string $text)
81
 * @method string boldBlack(string $text)
82
 * @method string boldRed(string $text)
83
 * @method string boldGreen(string $text)
84
 * @method string boldYellow(string $text)
85
 * @method string boldBlue(string $text)
86
 * @method string boldPurple(string $text)
87
 * @method string boldCyan(string $text)
88
 * @method string boldWhite(string $text)
89
 * @method string boldGray(string $text)
90
 * @method string boldDarkgray(string $text)
91
 * @method string dimBlack(string $text)
92
 * @method string dimRed(string $text)
93
 * @method string dimGreen(string $text)
94
 * @method string dimYellow(string $text)
95
 * @method string dimBlue(string $text)
96
 * @method string dimPurple(string $text)
97
 * @method string dimCyan(string $text)
98
 * @method string dimWhite(string $text)
99
 * @method string dimGray(string $text)
100
 * @method string dimDarkgray(string $text)
101
 * @method string italicBlack(string $text)
102
 * @method string italicRed(string $text)
103
 * @method string italicGreen(string $text)
104
 * @method string italicYellow(string $text)
105
 * @method string italicBlue(string $text)
106
 * @method string italicPurple(string $text)
107
 * @method string italicCyan(string $text)
108
 * @method string italicWhite(string $text)
109
 * @method string italicGray(string $text)
110
 * @method string italicDarkgray(string $text)
111
 * @method string underlineBlack(string $text)
112
 * @method string underlineRed(string $text)
113
 * @method string underlineGreen(string $text)
114
 * @method string underlineYellow(string $text)
115
 * @method string underlineBlue(string $text)
116
 * @method string underlinePurple(string $text)
117
 * @method string underlineCyan(string $text)
118
 * @method string underlineWhite(string $text)
119
 * @method string underlineGray(string $text)
120
 * @method string underlineDarkgray(string $text)
121
 * @method string boldBgBlack(string $text)
122
 * @method string boldBgRed(string $text)
123
 * @method string boldBgGreen(string $text)
124
 * @method string boldBgYellow(string $text)
125
 * @method string boldBgBlue(string $text)
126
 * @method string boldBgPurple(string $text)
127
 * @method string boldBgCyan(string $text)
128
 * @method string boldBgWhite(string $text)
129
 * @method string boldBgGray(string $text)
130
 * @method string boldBgDarkgray(string $text)
131
 * @method string dimBgBlack(string $text)
132
 * @method string dimBgRed(string $text)
133
 * @method string dimBgGreen(string $text)
134
 * @method string dimBgYellow(string $text)
135
 * @method string dimBgBlue(string $text)
136
 * @method string dimBgPurple(string $text)
137
 * @method string dimBgCyan(string $text)
138
 * @method string dimBgWhite(string $text)
139
 * @method string dimBgGray(string $text)
140
 * @method string dimBgDarkgray(string $text)
141
 * @method string italicBgBlack(string $text)
142
 * @method string italicBgRed(string $text)
143
 * @method string italicBgGreen(string $text)
144
 * @method string italicBgYellow(string $text)
145
 * @method string italicBgBlue(string $text)
146
 * @method string italicBgPurple(string $text)
147
 * @method string italicBgCyan(string $text)
148
 * @method string italicBgWhite(string $text)
149
 * @method string italicBgGray(string $text)
150
 * @method string italicBgDarkgray(string $text)
151
 * @method string underlineBgBlack(string $text)
152
 * @method string underlineBgRed(string $text)
153
 * @method string underlineBgGreen(string $text)
154
 * @method string underlineBgYellow(string $text)
155
 * @method string underlineBgBlue(string $text)
156
 * @method string underlineBgPurple(string $text)
157
 * @method string underlineBgCyan(string $text)
158
 * @method string underlineBgWhite(string $text)
159
 * @method string underlineBgGray(string $text)
160
 * @method string underlineBgDarkgray(string $text)
161
 * @method string boldBlackBgRed(string $text)
162
 * @method string boldBlackBgGreen(string $text)
163
 * @method string boldBlackBgYellow(string $text)
164
 * @method string boldBlackBgBlue(string $text)
165
 * @method string boldBlackBgPurple(string $text)
166
 * @method string boldBlackBgCyan(string $text)
167
 * @method string boldBlackBgWhite(string $text)
168
 * @method string boldBlackBgGray(string $text)
169
 * @method string boldBlackBgDarkgray(string $text)
170
 * @method string boldRedBgBlack(string $text)
171
 * @method string boldRedBgGreen(string $text)
172
 * @method string boldRedBgYellow(string $text)
173
 * @method string boldRedBgBlue(string $text)
174
 * @method string boldRedBgPurple(string $text)
175
 * @method string boldRedBgCyan(string $text)
176
 * @method string boldRedBgWhite(string $text)
177
 * @method string boldRedBgGray(string $text)
178
 * @method string boldRedBgDarkgray(string $text)
179
 * @method string boldGreenBgBlack(string $text)
180
 * @method string boldGreenBgRed(string $text)
181
 * @method string boldGreenBgYellow(string $text)
182
 * @method string boldGreenBgBlue(string $text)
183
 * @method string boldGreenBgPurple(string $text)
184
 * @method string boldGreenBgCyan(string $text)
185
 * @method string boldGreenBgWhite(string $text)
186
 * @method string boldGreenBgGray(string $text)
187
 * @method string boldGreenBgDarkgray(string $text)
188
 * @method string boldYellowBgBlack(string $text)
189
 * @method string boldYellowBgRed(string $text)
190
 * @method string boldYellowBgGreen(string $text)
191
 * @method string boldYellowBgBlue(string $text)
192
 * @method string boldYellowBgPurple(string $text)
193
 * @method string boldYellowBgCyan(string $text)
194
 * @method string boldYellowBgWhite(string $text)
195
 * @method string boldYellowBgGray(string $text)
196
 * @method string boldYellowBgDarkgray(string $text)
197
 * @method string boldBlueBgBlack(string $text)
198
 * @method string boldBlueBgRed(string $text)
199
 * @method string boldBlueBgGreen(string $text)
200
 * @method string boldBlueBgYellow(string $text)
201
 * @method string boldBlueBgPurple(string $text)
202
 * @method string boldBlueBgCyan(string $text)
203
 * @method string boldBlueBgWhite(string $text)
204
 * @method string boldBlueBgGray(string $text)
205
 * @method string boldBlueBgDarkgray(string $text)
206
 * @method string boldPurpleBgBlack(string $text)
207
 * @method string boldPurpleBgRed(string $text)
208
 * @method string boldPurpleBgGreen(string $text)
209
 * @method string boldPurpleBgYellow(string $text)
210
 * @method string boldPurpleBgBlue(string $text)
211
 * @method string boldPurpleBgCyan(string $text)
212
 * @method string boldPurpleBgWhite(string $text)
213
 * @method string boldPurpleBgGray(string $text)
214
 * @method string boldPurpleBgDarkgray(string $text)
215
 * @method string boldCyanBgBlack(string $text)
216
 * @method string boldCyanBgRed(string $text)
217
 * @method string boldCyanBgGreen(string $text)
218
 * @method string boldCyanBgYellow(string $text)
219
 * @method string boldCyanBgBlue(string $text)
220
 * @method string boldCyanBgPurple(string $text)
221
 * @method string boldCyanBgWhite(string $text)
222
 * @method string boldCyanBgGray(string $text)
223
 * @method string boldCyanBgDarkgray(string $text)
224
 * @method string boldWhiteBgBlack(string $text)
225
 * @method string boldWhiteBgRed(string $text)
226
 * @method string boldWhiteBgGreen(string $text)
227
 * @method string boldWhiteBgYellow(string $text)
228
 * @method string boldWhiteBgBlue(string $text)
229
 * @method string boldWhiteBgPurple(string $text)
230
 * @method string boldWhiteBgCyan(string $text)
231
 * @method string boldWhiteBgGray(string $text)
232
 * @method string boldWhiteBgDarkgray(string $text)
233
 * @method string boldGrayBgBlack(string $text)
234
 * @method string boldGrayBgRed(string $text)
235
 * @method string boldGrayBgGreen(string $text)
236
 * @method string boldGrayBgYellow(string $text)
237
 * @method string boldGrayBgBlue(string $text)
238
 * @method string boldGrayBgPurple(string $text)
239
 * @method string boldGrayBgCyan(string $text)
240
 * @method string boldGrayBgWhite(string $text)
241
 * @method string boldGrayBgDarkgray(string $text)
242
 * @method string boldDarkgrayBgBlack(string $text)
243
 * @method string boldDarkgrayBgRed(string $text)
244
 * @method string boldDarkgrayBgGreen(string $text)
245
 * @method string boldDarkgrayBgYellow(string $text)
246
 * @method string boldDarkgrayBgBlue(string $text)
247
 * @method string boldDarkgrayBgPurple(string $text)
248
 * @method string boldDarkgrayBgCyan(string $text)
249
 * @method string boldDarkgrayBgWhite(string $text)
250
 * @method string boldDarkgrayBgGray(string $text)
251
 * @method string dimBlackBgRed(string $text)
252
 * @method string dimBlackBgGreen(string $text)
253
 * @method string dimBlackBgYellow(string $text)
254
 * @method string dimBlackBgBlue(string $text)
255
 * @method string dimBlackBgPurple(string $text)
256
 * @method string dimBlackBgCyan(string $text)
257
 * @method string dimBlackBgWhite(string $text)
258
 * @method string dimBlackBgGray(string $text)
259
 * @method string dimBlackBgDarkgray(string $text)
260
 * @method string dimRedBgBlack(string $text)
261
 * @method string dimRedBgGreen(string $text)
262
 * @method string dimRedBgYellow(string $text)
263
 * @method string dimRedBgBlue(string $text)
264
 * @method string dimRedBgPurple(string $text)
265
 * @method string dimRedBgCyan(string $text)
266
 * @method string dimRedBgWhite(string $text)
267
 * @method string dimRedBgGray(string $text)
268
 * @method string dimRedBgDarkgray(string $text)
269
 * @method string dimGreenBgBlack(string $text)
270
 * @method string dimGreenBgRed(string $text)
271
 * @method string dimGreenBgYellow(string $text)
272
 * @method string dimGreenBgBlue(string $text)
273
 * @method string dimGreenBgPurple(string $text)
274
 * @method string dimGreenBgCyan(string $text)
275
 * @method string dimGreenBgWhite(string $text)
276
 * @method string dimGreenBgGray(string $text)
277
 * @method string dimGreenBgDarkgray(string $text)
278
 * @method string dimYellowBgBlack(string $text)
279
 * @method string dimYellowBgRed(string $text)
280
 * @method string dimYellowBgGreen(string $text)
281
 * @method string dimYellowBgBlue(string $text)
282
 * @method string dimYellowBgPurple(string $text)
283
 * @method string dimYellowBgCyan(string $text)
284
 * @method string dimYellowBgWhite(string $text)
285
 * @method string dimYellowBgGray(string $text)
286
 * @method string dimYellowBgDarkgray(string $text)
287
 * @method string dimBlueBgBlack(string $text)
288
 * @method string dimBlueBgRed(string $text)
289
 * @method string dimBlueBgGreen(string $text)
290
 * @method string dimBlueBgYellow(string $text)
291
 * @method string dimBlueBgPurple(string $text)
292
 * @method string dimBlueBgCyan(string $text)
293
 * @method string dimBlueBgWhite(string $text)
294
 * @method string dimBlueBgGray(string $text)
295
 * @method string dimBlueBgDarkgray(string $text)
296
 * @method string dimPurpleBgBlack(string $text)
297
 * @method string dimPurpleBgRed(string $text)
298
 * @method string dimPurpleBgGreen(string $text)
299
 * @method string dimPurpleBgYellow(string $text)
300
 * @method string dimPurpleBgBlue(string $text)
301
 * @method string dimPurpleBgCyan(string $text)
302
 * @method string dimPurpleBgWhite(string $text)
303
 * @method string dimPurpleBgGray(string $text)
304
 * @method string dimPurpleBgDarkgray(string $text)
305
 * @method string dimCyanBgBlack(string $text)
306
 * @method string dimCyanBgRed(string $text)
307
 * @method string dimCyanBgGreen(string $text)
308
 * @method string dimCyanBgYellow(string $text)
309
 * @method string dimCyanBgBlue(string $text)
310
 * @method string dimCyanBgPurple(string $text)
311
 * @method string dimCyanBgWhite(string $text)
312
 * @method string dimCyanBgGray(string $text)
313
 * @method string dimCyanBgDarkgray(string $text)
314
 * @method string dimWhiteBgBlack(string $text)
315
 * @method string dimWhiteBgRed(string $text)
316
 * @method string dimWhiteBgGreen(string $text)
317
 * @method string dimWhiteBgYellow(string $text)
318
 * @method string dimWhiteBgBlue(string $text)
319
 * @method string dimWhiteBgPurple(string $text)
320
 * @method string dimWhiteBgCyan(string $text)
321
 * @method string dimWhiteBgGray(string $text)
322
 * @method string dimWhiteBgDarkgray(string $text)
323
 * @method string dimGrayBgBlack(string $text)
324
 * @method string dimGrayBgRed(string $text)
325
 * @method string dimGrayBgGreen(string $text)
326
 * @method string dimGrayBgYellow(string $text)
327
 * @method string dimGrayBgBlue(string $text)
328
 * @method string dimGrayBgPurple(string $text)
329
 * @method string dimGrayBgCyan(string $text)
330
 * @method string dimGrayBgWhite(string $text)
331
 * @method string dimGrayBgDarkgray(string $text)
332
 * @method string dimDarkgrayBgBlack(string $text)
333
 * @method string dimDarkgrayBgRed(string $text)
334
 * @method string dimDarkgrayBgGreen(string $text)
335
 * @method string dimDarkgrayBgYellow(string $text)
336
 * @method string dimDarkgrayBgBlue(string $text)
337
 * @method string dimDarkgrayBgPurple(string $text)
338
 * @method string dimDarkgrayBgCyan(string $text)
339
 * @method string dimDarkgrayBgWhite(string $text)
340
 * @method string dimDarkgrayBgGray(string $text)
341
 * @method string italicBlackBgRed(string $text)
342
 * @method string italicBlackBgGreen(string $text)
343
 * @method string italicBlackBgYellow(string $text)
344
 * @method string italicBlackBgBlue(string $text)
345
 * @method string italicBlackBgPurple(string $text)
346
 * @method string italicBlackBgCyan(string $text)
347
 * @method string italicBlackBgWhite(string $text)
348
 * @method string italicBlackBgGray(string $text)
349
 * @method string italicBlackBgDarkgray(string $text)
350
 * @method string italicRedBgBlack(string $text)
351
 * @method string italicRedBgGreen(string $text)
352
 * @method string italicRedBgYellow(string $text)
353
 * @method string italicRedBgBlue(string $text)
354
 * @method string italicRedBgPurple(string $text)
355
 * @method string italicRedBgCyan(string $text)
356
 * @method string italicRedBgWhite(string $text)
357
 * @method string italicRedBgGray(string $text)
358
 * @method string italicRedBgDarkgray(string $text)
359
 * @method string italicGreenBgBlack(string $text)
360
 * @method string italicGreenBgRed(string $text)
361
 * @method string italicGreenBgYellow(string $text)
362
 * @method string italicGreenBgBlue(string $text)
363
 * @method string italicGreenBgPurple(string $text)
364
 * @method string italicGreenBgCyan(string $text)
365
 * @method string italicGreenBgWhite(string $text)
366
 * @method string italicGreenBgGray(string $text)
367
 * @method string italicGreenBgDarkgray(string $text)
368
 * @method string italicYellowBgBlack(string $text)
369
 * @method string italicYellowBgRed(string $text)
370
 * @method string italicYellowBgGreen(string $text)
371
 * @method string italicYellowBgBlue(string $text)
372
 * @method string italicYellowBgPurple(string $text)
373
 * @method string italicYellowBgCyan(string $text)
374
 * @method string italicYellowBgWhite(string $text)
375
 * @method string italicYellowBgGray(string $text)
376
 * @method string italicYellowBgDarkgray(string $text)
377
 * @method string italicBlueBgBlack(string $text)
378
 * @method string italicBlueBgRed(string $text)
379
 * @method string italicBlueBgGreen(string $text)
380
 * @method string italicBlueBgYellow(string $text)
381
 * @method string italicBlueBgPurple(string $text)
382
 * @method string italicBlueBgCyan(string $text)
383
 * @method string italicBlueBgWhite(string $text)
384
 * @method string italicBlueBgGray(string $text)
385
 * @method string italicBlueBgDarkgray(string $text)
386
 * @method string italicPurpleBgBlack(string $text)
387
 * @method string italicPurpleBgRed(string $text)
388
 * @method string italicPurpleBgGreen(string $text)
389
 * @method string italicPurpleBgYellow(string $text)
390
 * @method string italicPurpleBgBlue(string $text)
391
 * @method string italicPurpleBgCyan(string $text)
392
 * @method string italicPurpleBgWhite(string $text)
393
 * @method string italicPurpleBgGray(string $text)
394
 * @method string italicPurpleBgDarkgray(string $text)
395
 * @method string italicCyanBgBlack(string $text)
396
 * @method string italicCyanBgRed(string $text)
397
 * @method string italicCyanBgGreen(string $text)
398
 * @method string italicCyanBgYellow(string $text)
399
 * @method string italicCyanBgBlue(string $text)
400
 * @method string italicCyanBgPurple(string $text)
401
 * @method string italicCyanBgWhite(string $text)
402
 * @method string italicCyanBgGray(string $text)
403
 * @method string italicCyanBgDarkgray(string $text)
404
 * @method string italicWhiteBgBlack(string $text)
405
 * @method string italicWhiteBgRed(string $text)
406
 * @method string italicWhiteBgGreen(string $text)
407
 * @method string italicWhiteBgYellow(string $text)
408
 * @method string italicWhiteBgBlue(string $text)
409
 * @method string italicWhiteBgPurple(string $text)
410
 * @method string italicWhiteBgCyan(string $text)
411
 * @method string italicWhiteBgGray(string $text)
412
 * @method string italicWhiteBgDarkgray(string $text)
413
 * @method string italicGrayBgBlack(string $text)
414
 * @method string italicGrayBgRed(string $text)
415
 * @method string italicGrayBgGreen(string $text)
416
 * @method string italicGrayBgYellow(string $text)
417
 * @method string italicGrayBgBlue(string $text)
418
 * @method string italicGrayBgPurple(string $text)
419
 * @method string italicGrayBgCyan(string $text)
420
 * @method string italicGrayBgWhite(string $text)
421
 * @method string italicGrayBgDarkgray(string $text)
422
 * @method string italicDarkgrayBgBlack(string $text)
423
 * @method string italicDarkgrayBgRed(string $text)
424
 * @method string italicDarkgrayBgGreen(string $text)
425
 * @method string italicDarkgrayBgYellow(string $text)
426
 * @method string italicDarkgrayBgBlue(string $text)
427
 * @method string italicDarkgrayBgPurple(string $text)
428
 * @method string italicDarkgrayBgCyan(string $text)
429
 * @method string italicDarkgrayBgWhite(string $text)
430
 * @method string italicDarkgrayBgGray(string $text)
431
 * @method string underlineBlackBgRed(string $text)
432
 * @method string underlineBlackBgGreen(string $text)
433
 * @method string underlineBlackBgYellow(string $text)
434
 * @method string underlineBlackBgBlue(string $text)
435
 * @method string underlineBlackBgPurple(string $text)
436
 * @method string underlineBlackBgCyan(string $text)
437
 * @method string underlineBlackBgWhite(string $text)
438
 * @method string underlineBlackBgGray(string $text)
439
 * @method string underlineBlackBgDarkgray(string $text)
440
 * @method string underlineRedBgBlack(string $text)
441
 * @method string underlineRedBgGreen(string $text)
442
 * @method string underlineRedBgYellow(string $text)
443
 * @method string underlineRedBgBlue(string $text)
444
 * @method string underlineRedBgPurple(string $text)
445
 * @method string underlineRedBgCyan(string $text)
446
 * @method string underlineRedBgWhite(string $text)
447
 * @method string underlineRedBgGray(string $text)
448
 * @method string underlineRedBgDarkgray(string $text)
449
 * @method string underlineGreenBgBlack(string $text)
450
 * @method string underlineGreenBgRed(string $text)
451
 * @method string underlineGreenBgYellow(string $text)
452
 * @method string underlineGreenBgBlue(string $text)
453
 * @method string underlineGreenBgPurple(string $text)
454
 * @method string underlineGreenBgCyan(string $text)
455
 * @method string underlineGreenBgWhite(string $text)
456
 * @method string underlineGreenBgGray(string $text)
457
 * @method string underlineGreenBgDarkgray(string $text)
458
 * @method string underlineYellowBgBlack(string $text)
459
 * @method string underlineYellowBgRed(string $text)
460
 * @method string underlineYellowBgGreen(string $text)
461
 * @method string underlineYellowBgBlue(string $text)
462
 * @method string underlineYellowBgPurple(string $text)
463
 * @method string underlineYellowBgCyan(string $text)
464
 * @method string underlineYellowBgWhite(string $text)
465
 * @method string underlineYellowBgGray(string $text)
466
 * @method string underlineYellowBgDarkgray(string $text)
467
 * @method string underlineBlueBgBlack(string $text)
468
 * @method string underlineBlueBgRed(string $text)
469
 * @method string underlineBlueBgGreen(string $text)
470
 * @method string underlineBlueBgYellow(string $text)
471
 * @method string underlineBlueBgPurple(string $text)
472
 * @method string underlineBlueBgCyan(string $text)
473
 * @method string underlineBlueBgWhite(string $text)
474
 * @method string underlineBlueBgGray(string $text)
475
 * @method string underlineBlueBgDarkgray(string $text)
476
 * @method string underlinePurpleBgBlack(string $text)
477
 * @method string underlinePurpleBgRed(string $text)
478
 * @method string underlinePurpleBgGreen(string $text)
479
 * @method string underlinePurpleBgYellow(string $text)
480
 * @method string underlinePurpleBgBlue(string $text)
481
 * @method string underlinePurpleBgCyan(string $text)
482
 * @method string underlinePurpleBgWhite(string $text)
483
 * @method string underlinePurpleBgGray(string $text)
484
 * @method string underlinePurpleBgDarkgray(string $text)
485
 * @method string underlineCyanBgBlack(string $text)
486
 * @method string underlineCyanBgRed(string $text)
487
 * @method string underlineCyanBgGreen(string $text)
488
 * @method string underlineCyanBgYellow(string $text)
489
 * @method string underlineCyanBgBlue(string $text)
490
 * @method string underlineCyanBgPurple(string $text)
491
 * @method string underlineCyanBgWhite(string $text)
492
 * @method string underlineCyanBgGray(string $text)
493
 * @method string underlineCyanBgDarkgray(string $text)
494
 * @method string underlineWhiteBgBlack(string $text)
495
 * @method string underlineWhiteBgRed(string $text)
496
 * @method string underlineWhiteBgGreen(string $text)
497
 * @method string underlineWhiteBgYellow(string $text)
498
 * @method string underlineWhiteBgBlue(string $text)
499
 * @method string underlineWhiteBgPurple(string $text)
500
 * @method string underlineWhiteBgCyan(string $text)
501
 * @method string underlineWhiteBgGray(string $text)
502
 * @method string underlineWhiteBgDarkgray(string $text)
503
 * @method string underlineGrayBgBlack(string $text)
504
 * @method string underlineGrayBgRed(string $text)
505
 * @method string underlineGrayBgGreen(string $text)
506
 * @method string underlineGrayBgYellow(string $text)
507
 * @method string underlineGrayBgBlue(string $text)
508
 * @method string underlineGrayBgPurple(string $text)
509
 * @method string underlineGrayBgCyan(string $text)
510
 * @method string underlineGrayBgWhite(string $text)
511
 * @method string underlineGrayBgDarkgray(string $text)
512
 * @method string underlineDarkgrayBgBlack(string $text)
513
 * @method string underlineDarkgrayBgRed(string $text)
514
 * @method string underlineDarkgrayBgGreen(string $text)
515
 * @method string underlineDarkgrayBgYellow(string $text)
516
 * @method string underlineDarkgrayBgBlue(string $text)
517
 * @method string underlineDarkgrayBgPurple(string $text)
518
 * @method string underlineDarkgrayBgCyan(string $text)
519
 * @method string underlineDarkgrayBgWhite(string $text)
520
 * @method string underlineDarkgrayBgGray(string $text)
521
 * @method string blackBgRed(string $text)
522
 * @method string blackBgGreen(string $text)
523
 * @method string blackBgYellow(string $text)
524
 * @method string blackBgBlue(string $text)
525
 * @method string blackBgPurple(string $text)
526
 * @method string blackBgCyan(string $text)
527
 * @method string blackBgWhite(string $text)
528
 * @method string blackBgGray(string $text)
529
 * @method string blackBgDarkgray(string $text)
530
 * @method string redBgBlack(string $text)
531
 * @method string redBgGreen(string $text)
532
 * @method string redBgYellow(string $text)
533
 * @method string redBgBlue(string $text)
534
 * @method string redBgPurple(string $text)
535
 * @method string redBgCyan(string $text)
536
 * @method string redBgWhite(string $text)
537
 * @method string redBgGray(string $text)
538
 * @method string redBgDarkgray(string $text)
539
 * @method string greenBgBlack(string $text)
540
 * @method string greenBgRed(string $text)
541
 * @method string greenBgYellow(string $text)
542
 * @method string greenBgBlue(string $text)
543
 * @method string greenBgPurple(string $text)
544
 * @method string greenBgCyan(string $text)
545
 * @method string greenBgWhite(string $text)
546
 * @method string greenBgGray(string $text)
547
 * @method string greenBgDarkgray(string $text)
548
 * @method string yellowBgBlack(string $text)
549
 * @method string yellowBgRed(string $text)
550
 * @method string yellowBgGreen(string $text)
551
 * @method string yellowBgBlue(string $text)
552
 * @method string yellowBgPurple(string $text)
553
 * @method string yellowBgCyan(string $text)
554
 * @method string yellowBgWhite(string $text)
555
 * @method string yellowBgGray(string $text)
556
 * @method string yellowBgDarkgray(string $text)
557
 * @method string blueBgBlack(string $text)
558
 * @method string blueBgRed(string $text)
559
 * @method string blueBgGreen(string $text)
560
 * @method string blueBgYellow(string $text)
561
 * @method string blueBgPurple(string $text)
562
 * @method string blueBgCyan(string $text)
563
 * @method string blueBgWhite(string $text)
564
 * @method string blueBgGray(string $text)
565
 * @method string blueBgDarkgray(string $text)
566
 * @method string purpleBgBlack(string $text)
567
 * @method string purpleBgRed(string $text)
568
 * @method string purpleBgGreen(string $text)
569
 * @method string purpleBgYellow(string $text)
570
 * @method string purpleBgBlue(string $text)
571
 * @method string purpleBgCyan(string $text)
572
 * @method string purpleBgWhite(string $text)
573
 * @method string purpleBgGray(string $text)
574
 * @method string purpleBgDarkgray(string $text)
575
 * @method string cyanBgBlack(string $text)
576
 * @method string cyanBgRed(string $text)
577
 * @method string cyanBgGreen(string $text)
578
 * @method string cyanBgYellow(string $text)
579
 * @method string cyanBgBlue(string $text)
580
 * @method string cyanBgPurple(string $text)
581
 * @method string cyanBgWhite(string $text)
582
 * @method string cyanBgGray(string $text)
583
 * @method string cyanBgDarkgray(string $text)
584
 * @method string whiteBgBlack(string $text)
585
 * @method string whiteBgRed(string $text)
586
 * @method string whiteBgGreen(string $text)
587
 * @method string whiteBgYellow(string $text)
588
 * @method string whiteBgBlue(string $text)
589
 * @method string whiteBgPurple(string $text)
590
 * @method string whiteBgCyan(string $text)
591
 * @method string whiteBgGray(string $text)
592
 * @method string whiteBgDarkgray(string $text)
593
 * @method string grayBgBlack(string $text)
594
 * @method string grayBgRed(string $text)
595
 * @method string grayBgGreen(string $text)
596
 * @method string grayBgYellow(string $text)
597
 * @method string grayBgBlue(string $text)
598
 * @method string grayBgPurple(string $text)
599
 * @method string grayBgCyan(string $text)
600
 * @method string grayBgWhite(string $text)
601
 * @method string grayBgDarkgray(string $text)
602
 * @method string darkgrayBgBlack(string $text)
603
 * @method string darkgrayBgRed(string $text)
604
 * @method string darkgrayBgGreen(string $text)
605
 * @method string darkgrayBgYellow(string $text)
606
 * @method string darkgrayBgBlue(string $text)
607
 * @method string darkgrayBgPurple(string $text)
608
 * @method string darkgrayBgCyan(string $text)
609
 * @method string darkgrayBgWhite(string $text)
610
 * @method string darkgrayBgGray(string $text)
611
*/
612
class Color
613
{
614
615
    /**
616
     * The color constants
617
     */
618
    public const BLACK    = 30;
619
    public const RED      = 31;
620
    public const GREEN    = 32;
621
    public const YELLOW   = 33;
622
    public const BLUE     = 34;
623
    public const PURPLE   = 35;
624
    public const CYAN     = 36;
625
    public const WHITE    = 37;
626
    public const GRAY     = 47;
627
    public const DARKGRAY = 100;
628
629
    /**
630
     * The style constants
631
     */
632
    public const BOLD = 1;
633
    public const DIM = 2;
634
    public const ITALIC = 3;
635
    public const UNDERLINE = 4;
636
637
    /**
638
     * The console color style format
639
     * @var string
640
     */
641
    protected string $format = "\033[:mod:;:fg:;:bg:m:txt:\033[0m";
642
643
    /**
644
     * Returns a line formatted as comment.
645
     * @param string $text
646
     * @return string
647
     */
648
    public function comment(string $text): string
649
    {
650
        return $this->line($text, null, null, self::DIM);
651
    }
652
653
    /**
654
     * Returns a line formatted as error.
655
     * @param string $text
656
     * @return string
657
     */
658
    public function error(string $text): string
659
    {
660
        return $this->red($text);
661
    }
662
663
    /**
664
     * Returns a line formatted ok error.
665
     * @param string $text
666
     * @return string
667
     */
668
    public function ok(string $text): string
669
    {
670
        return $this->green($text);
671
    }
672
673
    /**
674
     * Returns a line formatted as warning.
675
     * @param string $text
676
     * @return string
677
     */
678
    public function warn(string $text): string
679
    {
680
        return $this->yellow($text);
681
    }
682
683
    /**
684
     * Returns a line formatted as information.
685
     * @param string $text
686
     * @return string
687
     */
688
    public function info(string $text): string
689
    {
690
        return $this->blue($text);
691
    }
692
693
    /**
694
     * Returns a formatted/colored line.
695
     * @param string $text
696
     * @param int|null $fg
697
     * @param int|null $bg
698
     * @param int|null $mode
699
     * @return string
700
     */
701
    public function line(
702
        string $text,
703
        ?int $fg = self::WHITE,
704
        ?int $bg = null,
705
        ?int $mode = null
706
    ): string {
707
        $style = [
708
            'bg' => $bg,
709
            'fg' => $fg === null ? self::WHITE : $fg,
710
            'mod' => $mode,
711
        ];
712
713
        $format = $style['bg'] === null
714
                ? str_replace(';:bg:', '', $this->format)
715
                : $this->format;
716
717
        $line = strtr($format, [
718
            ':mod:' => (int) $style['mod'],
719
            ':fg:' => $style['fg'],
720
            ':bg:' => $style['bg'],
721
            ':txt:' => $text
722
        ]);
723
724
        return $line;
725
    }
726
727
    /**
728
     * Prepare a multi colored string with HTML like tags.
729
     * Example: "<errorBold>Text</end><eol/><bgGreenBold>Text</end><eol>"
730
     * @param string $text
731
     * @return string
732
     */
733
    public function colors(string $text): string
734
    {
735
        $rawText = str_replace(
736
            [
737
                '</eol>',
738
                "\r\n",
739
                "\n"
740
            ],
741
            '__PHP_EOL__',
742
            $text
743
        );
744
745
        $matches = [];
746
747
        if (!preg_match_all('/<(\w+)>(.*?)<\/end>/', $rawText, $matches)) {
748
            return str_replace('__PHP_EOL__', PHP_EOL, $rawText);
749
        }
750
751
        $end = "\033[0m";
752
        $styledText = str_replace(['</end>'], $end, $rawText);
753
754
        foreach ($matches[1] as $method) {
755
            $part = str_replace($end, '', $this->{$method}(''));
756
            $styledText = str_replace('<' . $method . '>', $part, $styledText);
757
        }
758
759
        return str_replace('__PHP_EOL__', PHP_EOL, $styledText);
760
    }
761
762
    /**
763
     * Magic call to handle dynamic color, style
764
     * @param string $method
765
     * @param array<int, mixed> $args
766
     * @return mixed
767
     * @throws Error
768
     */
769
    public function __call(string $method, array $args = [])
770
    {
771
        $colors = [
772
            'black' => self::BLACK,
773
            'red' => self::RED,
774
            'green' => self::GREEN,
775
            'yellow' => self::YELLOW,
776
            'blue' => self::BLUE,
777
            'purple' => self::PURPLE,
778
            'cyan' => self::CYAN,
779
            'white' => self::WHITE,
780
            'gray' => self::GRAY,
781
            'darkgray' => self::DARKGRAY
782
        ];
783
784
        $modes = [
785
            'bold' => self::BOLD,
786
            'dim' =>  self::DIM,
787
            'italic' => self::ITALIC,
788
            'underline' => self::UNDERLINE,
789
        ];
790
791
        $fg = null;
792
        $bg = null;
793
        $mode = null;
794
795
        $matches = [];
796
797
        preg_match_all('/((?:^|[A-Z])[a-z]+)/', $method, $matches);
798
799
        if (count($matches[1]) > 0 && count($args) > 0) {
800
            $values = $matches[1];
801
            $count = count($values);
802
803
            for ($i = 0; $i < $count; $i++) {
804
                $val = strtolower($values[$i]);
805
                //color
806
                if (array_key_exists($val, $colors)) {
807
                    $fg = $colors[$val];
808
                }
809
810
                //modes
811
                if (array_key_exists($val, $modes)) {
812
                    $mode = $modes[$val];
813
                }
814
815
                //background colors
816
                if (
817
                    $val === 'bg'
818
                    && isset($values[$i + 1])
819
                    && array_key_exists(strtolower($values[$i + 1]), $colors)
820
                ) {
821
                    $val = strtolower($values[$i + 1]);
822
                    $bg = $colors[$val] + 10;
823
                    $i += 2;
824
                }
825
            }
826
827
            return $this->line($args[0], $fg, $bg, $mode);
828
        }
829
830
        throw new Error(sprintf('No such method [%s]', $method));
831
    }
832
}
833