cloggi 1.0.9 → 1.0.11
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/index.d.ts +2 -2
- package/dist/index.js +14 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare class ClogBuilder {
|
|
|
3
3
|
private _modifiers;
|
|
4
4
|
private _timed;
|
|
5
5
|
private _overwrite;
|
|
6
|
-
private
|
|
6
|
+
private _lastOverwriteLines;
|
|
7
7
|
private _print;
|
|
8
8
|
get red(): this;
|
|
9
9
|
get green(): this;
|
|
@@ -27,7 +27,7 @@ declare class ClogBuilder {
|
|
|
27
27
|
success(text: number | string | object): this;
|
|
28
28
|
warning(text: number | string | object): this;
|
|
29
29
|
sep(a?: number | string, b?: number | string): this;
|
|
30
|
-
progress(
|
|
30
|
+
progress(message: number | string | object, total: number, current: number): this;
|
|
31
31
|
}
|
|
32
32
|
type Cloggi = ClogBuilder & ((text: number | string | object) => void);
|
|
33
33
|
export declare const cloggi: Cloggi;
|
package/dist/index.js
CHANGED
|
@@ -6,9 +6,10 @@ class ClogBuilder {
|
|
|
6
6
|
this._modifiers = [];
|
|
7
7
|
this._timed = false;
|
|
8
8
|
this._overwrite = false;
|
|
9
|
-
this.
|
|
9
|
+
this._lastOverwriteLines = 0;
|
|
10
10
|
}
|
|
11
11
|
_print(text) {
|
|
12
|
+
var _a, _b;
|
|
12
13
|
const str = typeof text === 'object'
|
|
13
14
|
? prettyjson.render(text)
|
|
14
15
|
: typeof text === 'number'
|
|
@@ -17,16 +18,17 @@ class ClogBuilder {
|
|
|
17
18
|
const output = `${this._timed ? `[${new Date().toTimeString().slice(0, 8)}]${typeof text === 'object' ? '\n' : ' - '}` : ''}${str}`;
|
|
18
19
|
const formats = [this._color, ...this._modifiers];
|
|
19
20
|
const styled = st(formats, output, { validateStream: false });
|
|
20
|
-
if (this.
|
|
21
|
-
|
|
21
|
+
if (this._lastOverwriteLines > 0) {
|
|
22
|
+
const up = '\x1B[1A\x1B[2K'.repeat(this._lastOverwriteLines - 1);
|
|
23
|
+
process.stdout.write(up + '\r\x1B[2K');
|
|
22
24
|
}
|
|
23
25
|
if (this._overwrite) {
|
|
24
26
|
process.stdout.write(styled);
|
|
25
|
-
this.
|
|
27
|
+
this._lastOverwriteLines = ((_b = (_a = output.match(/\n/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) + 1;
|
|
26
28
|
}
|
|
27
29
|
else {
|
|
28
30
|
console.log(styled);
|
|
29
|
-
this.
|
|
31
|
+
this._lastOverwriteLines = 0;
|
|
30
32
|
}
|
|
31
33
|
this._color = 'white';
|
|
32
34
|
this._modifiers = [];
|
|
@@ -126,11 +128,16 @@ class ClogBuilder {
|
|
|
126
128
|
const char = typeof a === 'string' ? a : typeof b === 'string' ? b : '-';
|
|
127
129
|
return this._print(char.repeat(length));
|
|
128
130
|
}
|
|
129
|
-
progress(
|
|
131
|
+
progress(message, total, current) {
|
|
130
132
|
this._overwrite = true;
|
|
131
133
|
this._timed = true;
|
|
132
134
|
this._color = 'cyan';
|
|
133
|
-
|
|
135
|
+
const percentage = ((current / total) * 100).toFixed(2);
|
|
136
|
+
const progressBarLength = 50;
|
|
137
|
+
const filledLength = Math.round((current / total) * progressBarLength);
|
|
138
|
+
const bar = '█'.repeat(filledLength) + '-'.repeat(progressBarLength - filledLength);
|
|
139
|
+
const fullMessage = `${message}\n|${bar}| ${percentage}%\n${current} of ${total}`;
|
|
140
|
+
return this._print(fullMessage);
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
const wrapInstance = (instance) => {
|