@flowscripter/dynamic-cli-framework 5.4.12 → 6.0.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/dist/src/service/printer/DefaultPrinterService.d.ts +2 -2
- package/dist/src/service/printer/DefaultPrinterService.d.ts.map +1 -1
- package/dist/src/service/printer/DefaultPrinterService.js +6 -4
- package/dist/src/service/printer/terminal/Progress.d.ts +1 -1
- package/dist/src/service/printer/terminal/Progress.d.ts.map +1 -1
- package/dist/src/service/printer/terminal/Progress.js +10 -33
- package/package.json +4 -4
- package/src/service/printer/DefaultPrinterService.ts +14 -11
- package/src/service/printer/terminal/Progress.ts +23 -45
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PrinterService } from "@flowscripter/dynamic-cli-framework-api";
|
|
2
|
-
import { type Icon, Level, type
|
|
2
|
+
import { type Icon, Level, type ProgressBarOptions, type SpinnerStyle } from "@flowscripter/dynamic-cli-framework-api";
|
|
3
3
|
import type Terminal from "../../terminal/Terminal.ts";
|
|
4
4
|
import { WritableStream } from "node:stream/web";
|
|
5
5
|
import type Styler from "../../terminal/Styler.ts";
|
|
@@ -64,7 +64,7 @@ export default class DefaultPrinterService implements PrinterService {
|
|
|
64
64
|
getLevel(): Level;
|
|
65
65
|
showSpinner(message?: string, style?: SpinnerStyle): Promise<void>;
|
|
66
66
|
hideSpinner(): Promise<void>;
|
|
67
|
-
showProgressBar(
|
|
67
|
+
showProgressBar(options?: ProgressBarOptions): Promise<number>;
|
|
68
68
|
hideProgressBar(handle: number): Promise<void>;
|
|
69
69
|
hideAllProgressBars(): Promise<void>;
|
|
70
70
|
updateProgressBar(handle: number, current: number, message?: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultPrinterService.d.ts","sourceRoot":"","sources":["../../../../src/service/printer/DefaultPrinterService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,KAAK,IAAI,EACT,KAAK,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"DefaultPrinterService.d.ts","sourceRoot":"","sources":["../../../../src/service/printer/DefaultPrinterService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,KAAK,IAAI,EACT,KAAK,EACL,KAAK,kBAAkB,EACvB,KAAK,YAAY,EAClB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,cAAc;;IAClE,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAgDxC,YACE,oBAAoB,EAAE,cAAc,EACpC,oBAAoB,EAAE,cAAc,EACpC,aAAa,EAAE,OAAO,EACtB,aAAa,EAAE,OAAO,EACtB,cAAc,EAAE,QAAQ,EACxB,cAAc,EAAE,QAAQ,EACxB,MAAM,EAAE,MAAM,EAcf;IAED,IAAI,YAAY,CAAC,OAAO,EAAE,OAAO,EAQhC;IAED,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,IAAI,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAErC;IAED,IAAI,iBAAiB,IAAI,OAAO,CAE/B;IAEM,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD;IAEM,aAAa,IAAI,MAAM,CAE7B;IAEM,aAAa,IAAI,MAAM,CAE7B;IAED,IAAI,QAAQ,CAAC,UAAU,EAAE,OAAO,EAa/B;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAEM,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,M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KAAK,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAY9E;IAEY,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAExC;IAEY,eAAe,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAsB9E;IAEY,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1D;IAEY,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEhD;IAEM,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAKhF;CACF"}
|
|
@@ -308,7 +308,7 @@ export default class DefaultPrinterService {
|
|
|
308
308
|
async hideSpinner() {
|
|
309
309
|
await this.#spinner.hide();
|
|
310
310
|
}
|
|
311
|
-
async showProgressBar(
|
|
311
|
+
async showProgressBar(options = {}) {
|
|
312
312
|
if (!this.#stderrTerminal.isTty()) {
|
|
313
313
|
return -1;
|
|
314
314
|
}
|
|
@@ -316,10 +316,12 @@ export default class DefaultPrinterService {
|
|
|
316
316
|
if (this.#threshold > Level.INFO) {
|
|
317
317
|
return -1;
|
|
318
318
|
}
|
|
319
|
-
if (style != null) {
|
|
320
|
-
this.#progress.progressStyle = style;
|
|
319
|
+
if (options.style != null) {
|
|
320
|
+
this.#progress.progressStyle = options.style;
|
|
321
321
|
}
|
|
322
|
-
|
|
322
|
+
const format = options.format ?? ((value) => String(value));
|
|
323
|
+
const formatRate = options.formatRate ?? ((rate) => `${format(rate)}/s`);
|
|
324
|
+
return this.#progress.add(options.message ?? "", options.total ?? 100, options.current ?? 0, format, formatRate);
|
|
323
325
|
}
|
|
324
326
|
async hideProgressBar(handle) {
|
|
325
327
|
await this.#progress.hide(handle);
|
|
@@ -5,7 +5,7 @@ import { ProgressStyle } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
5
5
|
export default class Progress {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(terminal: Terminal, styler: Styler);
|
|
8
|
-
add(
|
|
8
|
+
add(message: string, total: number, current: number, format: (value: number) => string, formatRate: (rate: number) => string): number;
|
|
9
9
|
update(handle: number, current: number, message?: string): void;
|
|
10
10
|
hide(handle: number): Promise<void>;
|
|
11
11
|
hideAll(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Progress.d.ts","sourceRoot":"","sources":["../../../../../src/service/printer/terminal/Progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAU1D,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"Progress.d.ts","sourceRoot":"","sources":["../../../../../src/service/printer/terminal/Progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AACtD,OAAO,KAAK,QAAQ,MAAM,+BAA+B,CAAC;AAU1D,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAmBxE,MAAM,CAAC,OAAO,OAAO,QAAQ;;IAe3B,YAAmB,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAGpD;IAEM,GAAG,CACR,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EACjC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GACnC,MAAM,CA6BR;IA4BM,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAyBrE;IAEY,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe/C;IAEY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAKpC;IAEY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAqBlC;IAEM,MAAM,IAAI,IAAI,CAapB;IAkID,IAAI,aAAa,CAAC,KAAK,EAAE,MAAM,EAE9B;IAED,IAAI,cAAc,CAAC,KAAK,EAAE,MAAM,EAE/B;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,EAE3B;IAED,IAAI,aAAa,CAAC,KAAK,EAAE,aAAa,EAErC;CAmDF"}
|
|
@@ -28,7 +28,7 @@ export default class Progress {
|
|
|
28
28
|
this.#terminal = terminal;
|
|
29
29
|
this.#styler = styler;
|
|
30
30
|
}
|
|
31
|
-
add(
|
|
31
|
+
add(message, total, current, format, formatRate) {
|
|
32
32
|
if (total < 0) {
|
|
33
33
|
total = 100;
|
|
34
34
|
}
|
|
@@ -42,7 +42,8 @@ export default class Progress {
|
|
|
42
42
|
name: message,
|
|
43
43
|
current,
|
|
44
44
|
total,
|
|
45
|
-
|
|
45
|
+
format,
|
|
46
|
+
formatRate,
|
|
46
47
|
startMillis: Date.now(),
|
|
47
48
|
});
|
|
48
49
|
// force render on next timeout
|
|
@@ -165,29 +166,16 @@ export default class Progress {
|
|
|
165
166
|
this.#bars.forEach((bar) => {
|
|
166
167
|
const name = `${this.#styler.colorText(bar.name, this.#valColor)}${this.#styler.colorText(":", this.#labColor)}`;
|
|
167
168
|
const prefix = `${this.#styler.colorText("[", this.#labColor)}`;
|
|
168
|
-
let visibleWidth = 1;
|
|
169
169
|
const percentString = ((bar.current / bar.total) * 100).toFixed(2);
|
|
170
170
|
const percent = this.#styler.colorText(percentString, this.#valColor) +
|
|
171
171
|
this.#styler.colorText("%,", this.#labColor);
|
|
172
|
-
|
|
173
|
-
const rateText = bar.rate === undefined ? "-" : bar.rate.toFixed(2) + "";
|
|
172
|
+
const rateText = bar.rate === undefined ? "-" : bar.formatRate(bar.rate);
|
|
174
173
|
const rate = `${this.#styler.colorText(rateText, this.#valColor)}`;
|
|
175
174
|
let suffix = `${this.#styler.colorText("]", this.#labColor)} ${percent} `;
|
|
176
|
-
visibleWidth += 3;
|
|
177
175
|
if (bar.current === bar.total) {
|
|
178
176
|
const taken = this.#formatTime(bar.endMillis - bar.startMillis);
|
|
179
|
-
const
|
|
180
|
-
suffix += `${this.#styler.colorText(
|
|
181
|
-
visibleWidth +=
|
|
182
|
-
totalString.length +
|
|
183
|
-
bar.units.length +
|
|
184
|
-
7 +
|
|
185
|
-
1 +
|
|
186
|
-
rateText.length +
|
|
187
|
-
bar.units.length +
|
|
188
|
-
15 +
|
|
189
|
-
1 +
|
|
190
|
-
Bun.stripANSI(taken).length;
|
|
177
|
+
const totalText = bar.format(bar.total);
|
|
178
|
+
suffix += `${this.#styler.colorText(totalText, this.#valColor)}${this.#styler.colorText(", rate:", this.#labColor)} ${rate}${this.#styler.colorText(", time taken:", this.#labColor)} ${taken}`;
|
|
191
179
|
}
|
|
192
180
|
else {
|
|
193
181
|
const remainingMillis = bar.rate === undefined || bar.rate === 0
|
|
@@ -198,22 +186,11 @@ export default class Progress {
|
|
|
198
186
|
remainingMillis > MAX_REMAINING_MILLIS
|
|
199
187
|
? "-"
|
|
200
188
|
: this.#formatTime(remainingMillis);
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
suffix += `${this.#styler.colorText(
|
|
204
|
-
visibleWidth +=
|
|
205
|
-
currentString.length +
|
|
206
|
-
1 +
|
|
207
|
-
totalString.length +
|
|
208
|
-
bar.units.length +
|
|
209
|
-
7 +
|
|
210
|
-
1 +
|
|
211
|
-
rateText.length +
|
|
212
|
-
bar.units.length +
|
|
213
|
-
19 +
|
|
214
|
-
1 +
|
|
215
|
-
Bun.stripANSI(remaining).length;
|
|
189
|
+
const currentText = bar.format(bar.current);
|
|
190
|
+
const totalText = bar.format(bar.total);
|
|
191
|
+
suffix += `${this.#styler.colorText(currentText, this.#valColor)}${this.#styler.colorText("/", this.#labColor)}${this.#styler.colorText(totalText, this.#valColor)}${this.#styler.colorText(", rate:", this.#labColor)} ${rate}${this.#styler.colorText(", time remaining:", this.#labColor)} ${remaining}`;
|
|
216
192
|
}
|
|
193
|
+
const visibleWidth = Bun.stripANSI(prefix + suffix).length;
|
|
217
194
|
let available = consoleWidth - visibleWidth;
|
|
218
195
|
if (available < 0) {
|
|
219
196
|
available = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/dynamic-cli-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "A framework for developing CLI applications which supports dynamic discovery and installation of new commands",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"build": "tsc -p tsconfig.build.json"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@flowscripter/dynamic-cli-framework-api": "^
|
|
52
|
-
"@flowscripter/dynamic-plugin-framework": "^2.2.
|
|
51
|
+
"@flowscripter/dynamic-cli-framework-api": "^3.0.0",
|
|
52
|
+
"@flowscripter/dynamic-plugin-framework": "^2.2.8",
|
|
53
53
|
"emphasize": "^7.0.0",
|
|
54
54
|
"fastest-levenshtein": "^1.0.16",
|
|
55
55
|
"figlet": "^1.11.4",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/bun": "^1.4.2",
|
|
64
|
-
"@types/node": "^26.
|
|
64
|
+
"@types/node": "^26.5.1",
|
|
65
65
|
"@types/semver": "^7.8.0",
|
|
66
66
|
"oxfmt": "0.67.0",
|
|
67
67
|
"oxlint": "1.82.0"
|
|
@@ -5,7 +5,7 @@ import type { PrinterService } from "@flowscripter/dynamic-cli-framework-api";
|
|
|
5
5
|
import {
|
|
6
6
|
type Icon,
|
|
7
7
|
Level,
|
|
8
|
-
type
|
|
8
|
+
type ProgressBarOptions,
|
|
9
9
|
type SpinnerStyle,
|
|
10
10
|
} from "@flowscripter/dynamic-cli-framework-api";
|
|
11
11
|
import type Terminal from "../../terminal/Terminal.ts";
|
|
@@ -385,13 +385,7 @@ export default class DefaultPrinterService implements PrinterService {
|
|
|
385
385
|
await this.#spinner.hide();
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
public async showProgressBar(
|
|
389
|
-
units: string,
|
|
390
|
-
message = "",
|
|
391
|
-
total = 100,
|
|
392
|
-
current = 0,
|
|
393
|
-
style?: ProgressStyle,
|
|
394
|
-
): Promise<number> {
|
|
388
|
+
public async showProgressBar(options: ProgressBarOptions = {}): Promise<number> {
|
|
395
389
|
if (!this.#stderrTerminal.isTty()) {
|
|
396
390
|
return -1;
|
|
397
391
|
}
|
|
@@ -399,11 +393,20 @@ export default class DefaultPrinterService implements PrinterService {
|
|
|
399
393
|
if (this.#threshold > Level.INFO) {
|
|
400
394
|
return -1;
|
|
401
395
|
}
|
|
402
|
-
if (style != null) {
|
|
403
|
-
this.#progress.progressStyle = style;
|
|
396
|
+
if (options.style != null) {
|
|
397
|
+
this.#progress.progressStyle = options.style;
|
|
404
398
|
}
|
|
405
399
|
|
|
406
|
-
|
|
400
|
+
const format = options.format ?? ((value: number) => String(value));
|
|
401
|
+
const formatRate = options.formatRate ?? ((rate: number) => `${format(rate)}/s`);
|
|
402
|
+
|
|
403
|
+
return this.#progress.add(
|
|
404
|
+
options.message ?? "",
|
|
405
|
+
options.total ?? 100,
|
|
406
|
+
options.current ?? 0,
|
|
407
|
+
format,
|
|
408
|
+
formatRate,
|
|
409
|
+
);
|
|
407
410
|
}
|
|
408
411
|
|
|
409
412
|
public async hideProgressBar(handle: number): Promise<void> {
|
|
@@ -21,7 +21,8 @@ interface Bar {
|
|
|
21
21
|
name: string;
|
|
22
22
|
current: number;
|
|
23
23
|
total: number;
|
|
24
|
-
|
|
24
|
+
format: (value: number) => string;
|
|
25
|
+
formatRate: (rate: number) => string;
|
|
25
26
|
lastMillis?: number;
|
|
26
27
|
startMillis?: number;
|
|
27
28
|
endMillis?: number;
|
|
@@ -48,7 +49,13 @@ export default class Progress {
|
|
|
48
49
|
this.#styler = styler;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
public add(
|
|
52
|
+
public add(
|
|
53
|
+
message: string,
|
|
54
|
+
total: number,
|
|
55
|
+
current: number,
|
|
56
|
+
format: (value: number) => string,
|
|
57
|
+
formatRate: (rate: number) => string,
|
|
58
|
+
): number {
|
|
52
59
|
if (total < 0) {
|
|
53
60
|
total = 100;
|
|
54
61
|
}
|
|
@@ -63,7 +70,8 @@ export default class Progress {
|
|
|
63
70
|
name: message,
|
|
64
71
|
current,
|
|
65
72
|
total,
|
|
66
|
-
|
|
73
|
+
format,
|
|
74
|
+
formatRate,
|
|
67
75
|
startMillis: Date.now(),
|
|
68
76
|
});
|
|
69
77
|
|
|
@@ -226,38 +234,22 @@ export default class Progress {
|
|
|
226
234
|
this.#labColor,
|
|
227
235
|
)}`;
|
|
228
236
|
const prefix = `${this.#styler.colorText("[", this.#labColor)}`;
|
|
229
|
-
let visibleWidth = 1;
|
|
230
237
|
const percentString = ((bar.current / bar.total) * 100).toFixed(2);
|
|
231
238
|
const percent =
|
|
232
239
|
this.#styler.colorText(percentString, this.#valColor) +
|
|
233
240
|
this.#styler.colorText("%,", this.#labColor);
|
|
234
|
-
visibleWidth += percentString.length + 1;
|
|
235
241
|
|
|
236
|
-
const rateText = bar.rate === undefined ? "-" : bar.rate
|
|
242
|
+
const rateText = bar.rate === undefined ? "-" : bar.formatRate(bar.rate);
|
|
237
243
|
const rate = `${this.#styler.colorText(rateText, this.#valColor)}`;
|
|
238
244
|
|
|
239
245
|
let suffix = `${this.#styler.colorText("]", this.#labColor)} ${percent} `;
|
|
240
|
-
visibleWidth += 3;
|
|
241
246
|
if (bar.current === bar.total) {
|
|
242
247
|
const taken = this.#formatTime(bar.endMillis! - bar.startMillis!);
|
|
243
|
-
const
|
|
244
|
-
suffix += `${this.#styler.colorText(
|
|
245
|
-
|
|
248
|
+
const totalText = bar.format(bar.total);
|
|
249
|
+
suffix += `${this.#styler.colorText(totalText, this.#valColor)}${this.#styler.colorText(
|
|
250
|
+
", rate:",
|
|
246
251
|
this.#labColor,
|
|
247
|
-
)} ${rate}${this.#styler.colorText(
|
|
248
|
-
bar.units + "/s, time taken:",
|
|
249
|
-
this.#labColor,
|
|
250
|
-
)} ${taken}`;
|
|
251
|
-
visibleWidth +=
|
|
252
|
-
totalString.length +
|
|
253
|
-
bar.units.length +
|
|
254
|
-
7 +
|
|
255
|
-
1 +
|
|
256
|
-
rateText.length +
|
|
257
|
-
bar.units.length +
|
|
258
|
-
15 +
|
|
259
|
-
1 +
|
|
260
|
-
Bun.stripANSI(taken).length;
|
|
252
|
+
)} ${rate}${this.#styler.colorText(", time taken:", this.#labColor)} ${taken}`;
|
|
261
253
|
} else {
|
|
262
254
|
const remainingMillis =
|
|
263
255
|
bar.rate === undefined || bar.rate === 0
|
|
@@ -269,31 +261,17 @@ export default class Progress {
|
|
|
269
261
|
remainingMillis > MAX_REMAINING_MILLIS
|
|
270
262
|
? "-"
|
|
271
263
|
: this.#formatTime(remainingMillis);
|
|
272
|
-
const
|
|
273
|
-
const
|
|
274
|
-
suffix += `${this.#styler.colorText(
|
|
264
|
+
const currentText = bar.format(bar.current);
|
|
265
|
+
const totalText = bar.format(bar.total);
|
|
266
|
+
suffix += `${this.#styler.colorText(currentText, this.#valColor)}${this.#styler.colorText(
|
|
275
267
|
"/",
|
|
276
268
|
this.#labColor,
|
|
277
|
-
)}${this.#styler.colorText(
|
|
278
|
-
|
|
279
|
-
this.#labColor,
|
|
280
|
-
)} ${rate}${this.#styler.colorText(
|
|
281
|
-
bar.units + "/s, time remaining:",
|
|
269
|
+
)}${this.#styler.colorText(totalText, this.#valColor)}${this.#styler.colorText(
|
|
270
|
+
", rate:",
|
|
282
271
|
this.#labColor,
|
|
283
|
-
)} ${remaining}`;
|
|
284
|
-
visibleWidth +=
|
|
285
|
-
currentString.length +
|
|
286
|
-
1 +
|
|
287
|
-
totalString.length +
|
|
288
|
-
bar.units.length +
|
|
289
|
-
7 +
|
|
290
|
-
1 +
|
|
291
|
-
rateText.length +
|
|
292
|
-
bar.units.length +
|
|
293
|
-
19 +
|
|
294
|
-
1 +
|
|
295
|
-
Bun.stripANSI(remaining).length;
|
|
272
|
+
)} ${rate}${this.#styler.colorText(", time remaining:", this.#labColor)} ${remaining}`;
|
|
296
273
|
}
|
|
274
|
+
const visibleWidth = Bun.stripANSI(prefix + suffix).length;
|
|
297
275
|
let available = consoleWidth - visibleWidth;
|
|
298
276
|
if (available < 0) {
|
|
299
277
|
available = 0;
|