@sc-voice/tools 3.23.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sc-voice/tools",
3
- "version": "3.23.0",
3
+ "version": "3.24.0",
4
4
  "description": "Utilities for SC-Voice",
5
5
  "main": "index.mjs",
6
6
  "files": [
package/src/defines.mjs CHANGED
@@ -3,6 +3,7 @@ export const DBG = {
3
3
  ALIGN_LINE: 0,
4
4
  L2T_TO_STRING: 0,
5
5
  COLOR_CONSOLE: 0,
6
+ C10E_INSPECT: 0,
6
7
  I6L_CONTAINS: 0,
7
8
  I6L_OVERLAPS: 0,
8
9
  ML_DOC_VECTORS: 0, // 'mn8:3.4',
@@ -1,3 +1,4 @@
1
+ import util from 'node:util';
1
2
  import { Unicode } from './unicode.mjs';
2
3
 
3
4
  const {
@@ -62,6 +63,57 @@ export class ColorConsole {
62
63
  return CC;
63
64
  }
64
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
+
65
117
  valueOf(thing) {
66
118
  const msg = 'c10e.valueOf';
67
119
  let { precision } = this;
@@ -99,6 +151,7 @@ export class ColorConsole {
99
151
 
100
152
  color(textColor, ...things) {
101
153
  let { valueColor } = this;
154
+ let { styleText } = util;
102
155
  let label = '';
103
156
  let endColor = NO_COLOR;
104
157
  let eol;
@@ -154,11 +207,11 @@ export class ColorConsole {
154
207
  }
155
208
 
156
209
  fyi1(...rest) {
157
- this.write(...this.color(this.fyiColor1, ...rest));
210
+ this.writeColor(this.fyiColor1, rest);
158
211
  }
159
212
 
160
213
  fyi2(...rest) {
161
- this.write(...this.color(this.fyiColor2, ...rest));
214
+ this.writeColor(this.fyiColor2, rest);
162
215
  }
163
216
 
164
217
  ok(...rest) {
@@ -166,11 +219,11 @@ export class ColorConsole {
166
219
  }
167
220
 
168
221
  ok1(...rest) {
169
- this.write(...this.color(this.okColor1, ...rest));
222
+ this.writeColor(this.okColor1, rest);
170
223
  }
171
224
 
172
225
  ok2(...rest) {
173
- this.write(...this.color(this.okColor2, ...rest));
226
+ this.writeColor(this.okColor2, rest);
174
227
  }
175
228
 
176
229
  bad(...rest) {
@@ -178,11 +231,11 @@ export class ColorConsole {
178
231
  }
179
232
 
180
233
  bad1(...rest) {
181
- this.write(...this.color(this.badColor1, ...rest));
234
+ this.writeColor(this.badColor1, rest);
182
235
  }
183
236
 
184
237
  bad2(...rest) {
185
- this.write(...this.color(this.badColor2, ...rest));
238
+ this.writeColor(this.badColor2, rest);
186
239
  }
187
240
 
188
241
  tag(...rest) {
@@ -190,10 +243,10 @@ export class ColorConsole {
190
243
  }
191
244
 
192
245
  tag1(...rest) {
193
- this.write(...this.color(this.tagColor1, ...rest));
246
+ this.writeColor(this.tagColor1, rest);
194
247
  }
195
248
 
196
249
  tag2(...rest) {
197
- this.write(...this.color(this.tagColor2, ...rest));
250
+ this.writeColor(this.tagColor2, rest);
198
251
  }
199
252
  }
@@ -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[0m',
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', {