@sc-voice/tools 3.22.0 → 3.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/defines.mjs +1 -0
- package/src/text/color-console.mjs +87 -6
- package/src/text/unicode.mjs +22 -1
package/package.json
CHANGED
package/src/defines.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import util from 'node:util';
|
|
1
2
|
import { Unicode } from './unicode.mjs';
|
|
2
3
|
|
|
3
4
|
const {
|
|
@@ -31,6 +32,8 @@ export class ColorConsole {
|
|
|
31
32
|
fyiColor2 = BRIGHT_BLACK,
|
|
32
33
|
okColor1 = BRIGHT_GREEN,
|
|
33
34
|
okColor2 = GREEN,
|
|
35
|
+
tagColor1 = BRIGHT_MAGENTA,
|
|
36
|
+
tagColor2 = MAGENTA,
|
|
34
37
|
valueColor = CYAN,
|
|
35
38
|
dateFormat = new Intl.DateTimeFormat(undefined, {
|
|
36
39
|
dateStyle: 'short',
|
|
@@ -47,6 +50,8 @@ export class ColorConsole {
|
|
|
47
50
|
fyiColor2,
|
|
48
51
|
okColor1,
|
|
49
52
|
okColor2,
|
|
53
|
+
tagColor1,
|
|
54
|
+
tagColor2,
|
|
50
55
|
precision,
|
|
51
56
|
valueColor,
|
|
52
57
|
write,
|
|
@@ -58,6 +63,57 @@ export class ColorConsole {
|
|
|
58
63
|
return CC;
|
|
59
64
|
}
|
|
60
65
|
|
|
66
|
+
static utilColor(ansiColor) {
|
|
67
|
+
switch (ansiColor) {
|
|
68
|
+
case BLACK: return 'black';
|
|
69
|
+
case WHITE: return 'white';
|
|
70
|
+
case RED: return 'red';
|
|
71
|
+
case GREEN: return 'green';
|
|
72
|
+
case BLUE: return 'blue';
|
|
73
|
+
case CYAN: return 'cyan';
|
|
74
|
+
case MAGENTA: return 'magenta';
|
|
75
|
+
case YELLOW: return 'yellow';
|
|
76
|
+
case BRIGHT_BLACK: return 'blackBright';
|
|
77
|
+
case BRIGHT_WHITE: return 'whiteBright';
|
|
78
|
+
case BRIGHT_RED: return 'redBright';
|
|
79
|
+
case BRIGHT_GREEN: return 'greenBright';
|
|
80
|
+
case BRIGHT_BLUE: return 'blueBright';
|
|
81
|
+
case BRIGHT_CYAN: return 'cyanBright';
|
|
82
|
+
case BRIGHT_MAGENTA: return 'magentaBright';
|
|
83
|
+
case BRIGHT_YELLOW: return 'yellowBright';
|
|
84
|
+
case NO_COLOR: return 'noColor';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
writeColor(color, rest) {
|
|
89
|
+
let { styles, defaultOptions } = util?.inspect || {};
|
|
90
|
+
if (styles) {
|
|
91
|
+
let oldStyles = Object.assign({}, styles);
|
|
92
|
+
let oldColors = defaultOptions.colors;
|
|
93
|
+
defaultOptions.colors = true;
|
|
94
|
+
let valueColor = ColorConsole.utilColor(this.valueColor);
|
|
95
|
+
let textColor = ColorConsole.utilColor(color);
|
|
96
|
+
styles.bigint = valueColor;
|
|
97
|
+
styles.boolean = valueColor;
|
|
98
|
+
styles.date = valueColor;
|
|
99
|
+
//styles.name = textColor;
|
|
100
|
+
styles.module = 'underline';
|
|
101
|
+
styles.null = valueColor;
|
|
102
|
+
styles.number = valueColor;
|
|
103
|
+
styles.regexp = valueColor;
|
|
104
|
+
styles.special = valueColor;
|
|
105
|
+
styles.string = valueColor;
|
|
106
|
+
//styles.undefined = valueColor;
|
|
107
|
+
|
|
108
|
+
this.write(...this.color(color, ...rest));
|
|
109
|
+
|
|
110
|
+
Object.assign(util.inspect.styles, oldStyles);
|
|
111
|
+
defaultOptions.colors = oldColors;
|
|
112
|
+
} else {
|
|
113
|
+
this.write(...this.color(color, ...rest));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
61
117
|
valueOf(thing) {
|
|
62
118
|
const msg = 'c10e.valueOf';
|
|
63
119
|
let { precision } = this;
|
|
@@ -95,11 +151,24 @@ export class ColorConsole {
|
|
|
95
151
|
|
|
96
152
|
color(textColor, ...things) {
|
|
97
153
|
let { valueColor } = this;
|
|
154
|
+
let { styleText } = util;
|
|
98
155
|
let label = '';
|
|
99
156
|
let endColor = NO_COLOR;
|
|
157
|
+
let eol;
|
|
100
158
|
return things.reduce((a, thing) => {
|
|
101
159
|
let newLabel = '';
|
|
102
160
|
let v = this.valueOf(thing);
|
|
161
|
+
let aLast = a.at(-1);
|
|
162
|
+
if (typeof aLast === 'string' && aLast.endsWith('\n' + endColor)) {
|
|
163
|
+
if (aLast === textColor + '\n' + endColor) {
|
|
164
|
+
a.pop();
|
|
165
|
+
} else {
|
|
166
|
+
const iLast = aLast.lastIndexOf('\n');
|
|
167
|
+
a.pop();
|
|
168
|
+
a.push(aLast.substring(0, iLast) + aLast.substring(iLast + 1));
|
|
169
|
+
}
|
|
170
|
+
v = '\n' + v;
|
|
171
|
+
}
|
|
103
172
|
switch (typeof thing) {
|
|
104
173
|
case 'object': {
|
|
105
174
|
if (
|
|
@@ -138,11 +207,11 @@ export class ColorConsole {
|
|
|
138
207
|
}
|
|
139
208
|
|
|
140
209
|
fyi1(...rest) {
|
|
141
|
-
this.
|
|
210
|
+
this.writeColor(this.fyiColor1, rest);
|
|
142
211
|
}
|
|
143
212
|
|
|
144
213
|
fyi2(...rest) {
|
|
145
|
-
this.
|
|
214
|
+
this.writeColor(this.fyiColor2, rest);
|
|
146
215
|
}
|
|
147
216
|
|
|
148
217
|
ok(...rest) {
|
|
@@ -150,11 +219,11 @@ export class ColorConsole {
|
|
|
150
219
|
}
|
|
151
220
|
|
|
152
221
|
ok1(...rest) {
|
|
153
|
-
this.
|
|
222
|
+
this.writeColor(this.okColor1, rest);
|
|
154
223
|
}
|
|
155
224
|
|
|
156
225
|
ok2(...rest) {
|
|
157
|
-
this.
|
|
226
|
+
this.writeColor(this.okColor2, rest);
|
|
158
227
|
}
|
|
159
228
|
|
|
160
229
|
bad(...rest) {
|
|
@@ -162,10 +231,22 @@ export class ColorConsole {
|
|
|
162
231
|
}
|
|
163
232
|
|
|
164
233
|
bad1(...rest) {
|
|
165
|
-
this.
|
|
234
|
+
this.writeColor(this.badColor1, rest);
|
|
166
235
|
}
|
|
167
236
|
|
|
168
237
|
bad2(...rest) {
|
|
169
|
-
this.
|
|
238
|
+
this.writeColor(this.badColor2, rest);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
tag(...rest) {
|
|
242
|
+
return this.tag2(...rest);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
tag1(...rest) {
|
|
246
|
+
this.writeColor(this.tagColor1, rest);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
tag2(...rest) {
|
|
250
|
+
this.writeColor(this.tagColor2, rest);
|
|
170
251
|
}
|
|
171
252
|
}
|
package/src/text/unicode.mjs
CHANGED
|
@@ -281,10 +281,31 @@ export class Unicode {
|
|
|
281
281
|
BRIGHT_MAGENTA: '\u001b[95m',
|
|
282
282
|
BRIGHT_CYAN: '\u001b[96m',
|
|
283
283
|
BRIGHT_WHITE: '\u001b[97m',
|
|
284
|
-
NO_COLOR: '\u001b[
|
|
284
|
+
NO_COLOR: '\u001b[39m',
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
static get LINUX_STYLE() {
|
|
289
|
+
return {
|
|
290
|
+
BOLD: '\u001b[1m',
|
|
291
|
+
DIM: '\u001b[2m',
|
|
292
|
+
NO_BOLD: '\u001b[22m',
|
|
293
|
+
ITALIC: '\u001b[3m',
|
|
294
|
+
NO_ITALIC: '\u001b[23m',
|
|
295
|
+
UNDERLINE: '\u001b[4m',
|
|
296
|
+
NO_UNDERLINE: '\u001b[24m',
|
|
297
|
+
BLINK: '\u001b[5m',
|
|
298
|
+
NO_BLINK: '\u001b[25m',
|
|
299
|
+
INVERSE: '\u001b[7m',
|
|
300
|
+
NO_INVERSE: '\u001b[27m',
|
|
301
|
+
HIDE: '\u001b[8m',
|
|
302
|
+
NO_HIDE: '\u001b[28m',
|
|
303
|
+
STRIKETHROUGH: '\u001b[9m',
|
|
304
|
+
NO_STRIKETHROUGH: '\u001b[29m',
|
|
305
|
+
RESET: '\u001b[0m',
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
288
309
|
constructor(opts = {}) {
|
|
289
310
|
if (opts.romanizeMap == null) {
|
|
290
311
|
Object.defineProperty(this, 'romanizeMap', {
|