1 | class Color {
|
2 | constructor() {
|
3 | const TERMINAL = {
|
4 | Blink: '\x1b[5m',
|
5 | Bright: '\x1b[1m',
|
6 | Dim: '\x1b[2m',
|
7 | Hidden: '\x1b[8m',
|
8 | Reset: '\x1b[0m',
|
9 | Reverse: '\x1b[7m',
|
10 | Underline: '\x1b[4m',
|
11 | Black: '\x1b[30m',
|
12 | Red: '\x1b[31m',
|
13 | Green: '\x1b[32m',
|
14 | Yellow: '\x1b[33m',
|
15 | Blue: '\x1b[34m',
|
16 | Magenta: '\x1b[35m',
|
17 | Cyan: '\x1b[36m',
|
18 | White: '\x1b[37m',
|
19 | Crimson: '\x1b[38m',
|
20 | BlackBG: '\x1b[40m',
|
21 | RedBG: '\x1b[41m',
|
22 | GreenBG: '\x1b[42m',
|
23 | YellowBG: '\x1b[43m',
|
24 | BlueBG: '\x1b[44m',
|
25 | MagentaBG: '\x1b[45m',
|
26 | CyanBG: '\x1b[46m',
|
27 | WhiteBG: '\x1b[47m',
|
28 | CrimsonBG: '\x1b[48m',
|
29 | }
|
30 | this.decorator = ''
|
31 | Object.entries(TERMINAL).forEach(([key, val]) => {
|
32 | Object.defineProperty(this, key, {
|
33 | get: () => { this.decorator += val; return this }
|
34 | })
|
35 | })
|
36 | }
|
37 |
|
38 | color(str) {
|
39 | this.decorator += str
|
40 | return this
|
41 | }
|
42 |
|
43 | get end() {
|
44 | const result = this.decorator
|
45 | this.decorator = ''
|
46 | return result
|
47 | }
|
48 |
|
49 | }
|
50 |
|
51 | module.exports = new Color()
|