@sc-voice/tools 3.21.0 → 3.23.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/text/color-console.mjs +28 -0
- package/src/text/list.mjs +19 -9
package/package.json
CHANGED
|
@@ -31,6 +31,8 @@ export class ColorConsole {
|
|
|
31
31
|
fyiColor2 = BRIGHT_BLACK,
|
|
32
32
|
okColor1 = BRIGHT_GREEN,
|
|
33
33
|
okColor2 = GREEN,
|
|
34
|
+
tagColor1 = BRIGHT_MAGENTA,
|
|
35
|
+
tagColor2 = MAGENTA,
|
|
34
36
|
valueColor = CYAN,
|
|
35
37
|
dateFormat = new Intl.DateTimeFormat(undefined, {
|
|
36
38
|
dateStyle: 'short',
|
|
@@ -47,6 +49,8 @@ export class ColorConsole {
|
|
|
47
49
|
fyiColor2,
|
|
48
50
|
okColor1,
|
|
49
51
|
okColor2,
|
|
52
|
+
tagColor1,
|
|
53
|
+
tagColor2,
|
|
50
54
|
precision,
|
|
51
55
|
valueColor,
|
|
52
56
|
write,
|
|
@@ -97,9 +101,21 @@ export class ColorConsole {
|
|
|
97
101
|
let { valueColor } = this;
|
|
98
102
|
let label = '';
|
|
99
103
|
let endColor = NO_COLOR;
|
|
104
|
+
let eol;
|
|
100
105
|
return things.reduce((a, thing) => {
|
|
101
106
|
let newLabel = '';
|
|
102
107
|
let v = this.valueOf(thing);
|
|
108
|
+
let aLast = a.at(-1);
|
|
109
|
+
if (typeof aLast === 'string' && aLast.endsWith('\n' + endColor)) {
|
|
110
|
+
if (aLast === textColor + '\n' + endColor) {
|
|
111
|
+
a.pop();
|
|
112
|
+
} else {
|
|
113
|
+
const iLast = aLast.lastIndexOf('\n');
|
|
114
|
+
a.pop();
|
|
115
|
+
a.push(aLast.substring(0, iLast) + aLast.substring(iLast + 1));
|
|
116
|
+
}
|
|
117
|
+
v = '\n' + v;
|
|
118
|
+
}
|
|
103
119
|
switch (typeof thing) {
|
|
104
120
|
case 'object': {
|
|
105
121
|
if (
|
|
@@ -168,4 +184,16 @@ export class ColorConsole {
|
|
|
168
184
|
bad2(...rest) {
|
|
169
185
|
this.write(...this.color(this.badColor2, ...rest));
|
|
170
186
|
}
|
|
187
|
+
|
|
188
|
+
tag(...rest) {
|
|
189
|
+
return this.tag2(...rest);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
tag1(...rest) {
|
|
193
|
+
this.write(...this.color(this.tagColor1, ...rest));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
tag2(...rest) {
|
|
197
|
+
this.write(...this.color(this.tagColor2, ...rest));
|
|
198
|
+
}
|
|
171
199
|
}
|
package/src/text/list.mjs
CHANGED
|
@@ -11,11 +11,19 @@ export class ListFactory {
|
|
|
11
11
|
nColumns = 0,
|
|
12
12
|
nRows = 0,
|
|
13
13
|
nLists = 0,
|
|
14
|
+
rowSeparator = '\n',
|
|
15
|
+
colSeparator = ' ',
|
|
16
|
+
order = 'column-major',
|
|
17
|
+
precision = 3,
|
|
14
18
|
} = opts;
|
|
15
19
|
Object.assign(this, {
|
|
16
20
|
nColumns,
|
|
17
21
|
nRows,
|
|
18
22
|
nLists,
|
|
23
|
+
order,
|
|
24
|
+
precision,
|
|
25
|
+
rowSeparator,
|
|
26
|
+
colSeparator,
|
|
19
27
|
});
|
|
20
28
|
}
|
|
21
29
|
|
|
@@ -32,7 +40,7 @@ export class ListFactory {
|
|
|
32
40
|
values=[],
|
|
33
41
|
separator = ',', // join() separator
|
|
34
42
|
widths, // element string widths
|
|
35
|
-
precision =
|
|
43
|
+
precision = this.precision, // numeric precision
|
|
36
44
|
} = opts;
|
|
37
45
|
|
|
38
46
|
let list = [...values];
|
|
@@ -118,7 +126,7 @@ export class ListFactory {
|
|
|
118
126
|
name,
|
|
119
127
|
values=[],
|
|
120
128
|
separator = '\n',
|
|
121
|
-
precision,
|
|
129
|
+
precision = this.precision,
|
|
122
130
|
} = opts;
|
|
123
131
|
|
|
124
132
|
this.nColumns++;
|
|
@@ -139,7 +147,7 @@ export class ListFactory {
|
|
|
139
147
|
values=[],
|
|
140
148
|
separator = '\t',
|
|
141
149
|
widths,
|
|
142
|
-
precision,
|
|
150
|
+
precision = this.precision,
|
|
143
151
|
} = opts;
|
|
144
152
|
|
|
145
153
|
this.nRows++;
|
|
@@ -156,22 +164,24 @@ export class ListFactory {
|
|
|
156
164
|
}
|
|
157
165
|
|
|
158
166
|
wrapList(list, opts = {}) {
|
|
159
|
-
const msg = '
|
|
167
|
+
const msg = 'l9y.wrapList';
|
|
160
168
|
const dbg = 0;
|
|
161
169
|
let {
|
|
162
170
|
name,
|
|
163
171
|
maxValues = 2,
|
|
164
172
|
namePrefix = 'column',
|
|
165
|
-
order =
|
|
166
|
-
rowSeparator =
|
|
167
|
-
colSeparator =
|
|
173
|
+
order = this.order,
|
|
174
|
+
rowSeparator = this.rowSeparator,
|
|
175
|
+
colSeparator = this.colSeparator,
|
|
176
|
+
precision = this.precision,
|
|
168
177
|
} = opts;
|
|
169
178
|
|
|
170
|
-
let singleList =
|
|
179
|
+
let singleList = this.createColumn({
|
|
171
180
|
name,
|
|
172
181
|
separator:rowSeparator,
|
|
182
|
+
precision,
|
|
173
183
|
});
|
|
174
|
-
let newRow = (separator) =>
|
|
184
|
+
let newRow = (separator) => this.createRow({ separator, precision });
|
|
175
185
|
name = name || singleList.name;
|
|
176
186
|
switch (order) {
|
|
177
187
|
case 'col-major':
|