@d-zero/dealer 1.0.2 → 1.2.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/deal.d.ts +5 -5
- package/dist/display.d.ts +1 -0
- package/dist/display.js +20 -6
- package/dist/get-corsor-pos.d.ts +1 -0
- package/dist/get-corsor-pos.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/lanes.d.ts +6 -5
- package/dist/lanes.js +17 -1
- package/dist/riffle.d.ts +1 -1
- package/dist/riffle.js +5 -1
- package/package.json +3 -2
package/dist/deal.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DealerOptions } from './dealer.js';
|
|
2
2
|
import type { LanesOptions } from './lanes.js';
|
|
3
|
-
type
|
|
4
|
-
header?:
|
|
5
|
-
debug?: boolean;
|
|
3
|
+
export type DealOptions = DealerOptions & LanesOptions & {
|
|
4
|
+
readonly header?: DealHeader;
|
|
5
|
+
readonly debug?: boolean;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
8
|
-
export
|
|
7
|
+
export type DealHeader = (progress: number, done: number, total: number, limit: number) => string;
|
|
8
|
+
export declare function deal<T extends WeakKey>(items: readonly T[], setup: (process: T, update: (log: string) => void, index: number) => Promise<() => void | Promise<void>> | (() => void | Promise<void>), options?: DealOptions): Promise<void>;
|
package/dist/display.d.ts
CHANGED
package/dist/display.js
CHANGED
|
@@ -19,7 +19,7 @@ export class Display {
|
|
|
19
19
|
#stack = null;
|
|
20
20
|
#startTime = Date.now();
|
|
21
21
|
#timer = null;
|
|
22
|
-
#verbose
|
|
22
|
+
#verbose;
|
|
23
23
|
constructor(options) {
|
|
24
24
|
this.#animations = {
|
|
25
25
|
...animationPresets,
|
|
@@ -27,6 +27,7 @@ export class Display {
|
|
|
27
27
|
};
|
|
28
28
|
const fps = options?.fps ?? 30;
|
|
29
29
|
this.#frameInterval = 1000 / fps;
|
|
30
|
+
this.#verbose = options?.verbose ?? false;
|
|
30
31
|
process.stdout.on('resize', () => this.#resize());
|
|
31
32
|
}
|
|
32
33
|
close() {
|
|
@@ -46,7 +47,9 @@ export class Display {
|
|
|
46
47
|
}
|
|
47
48
|
write(...logs) {
|
|
48
49
|
if (this.#verbose) {
|
|
49
|
-
|
|
50
|
+
for (const log of logs) {
|
|
51
|
+
process.stdout.write(this.#text(log, false) + '\n');
|
|
52
|
+
}
|
|
50
53
|
return;
|
|
51
54
|
}
|
|
52
55
|
this.#stack = [...this.#debugMessages, ...logs];
|
|
@@ -85,6 +88,9 @@ export class Display {
|
|
|
85
88
|
return text.replace(placeholder, `${displayTime}`);
|
|
86
89
|
}
|
|
87
90
|
#enterFrame() {
|
|
91
|
+
if (this.#verbose) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
88
94
|
this.#timer = setTimeout(() => this.#enterFrame(), this.#frameInterval);
|
|
89
95
|
this.#write();
|
|
90
96
|
}
|
|
@@ -94,17 +100,25 @@ export class Display {
|
|
|
94
100
|
}
|
|
95
101
|
this.#write();
|
|
96
102
|
}
|
|
103
|
+
#text(text, trim = true) {
|
|
104
|
+
text = riffle(text, Date.now() - this.#startTime, this.#animations, this.#verbose);
|
|
105
|
+
text = this.#countDown(text);
|
|
106
|
+
text = text.replaceAll(/\r?\n/g, ' ');
|
|
107
|
+
if (trim) {
|
|
108
|
+
text = text.slice(0, process.stdout.columns);
|
|
109
|
+
}
|
|
110
|
+
return `${RESET}${text}${RESET}`;
|
|
111
|
+
}
|
|
97
112
|
#write() {
|
|
98
113
|
if (!this.#stack) {
|
|
99
114
|
return;
|
|
100
115
|
}
|
|
101
116
|
this.#clear();
|
|
117
|
+
const outputBuffer = [];
|
|
102
118
|
for (const stack of this.#stack) {
|
|
103
|
-
|
|
104
|
-
text = this.#countDown(text);
|
|
105
|
-
const displayText = text.slice(0, process.stdout.columns);
|
|
106
|
-
process.stdout.write(`${RESET}${displayText}${RESET}\n`);
|
|
119
|
+
outputBuffer.push(this.#text(stack));
|
|
107
120
|
}
|
|
121
|
+
process.stdout.write(outputBuffer.join('\n') + '\n');
|
|
108
122
|
this.#lastWroteLineNum = this.#stack.length;
|
|
109
123
|
}
|
|
110
124
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCursorPos(): Promise<[x: number, y: number]>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function getCursorPos() {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
const termcodes = { cursorGetPosition: '\u001B[6n' };
|
|
4
|
+
process.stdin.setEncoding('utf8');
|
|
5
|
+
process.stdin.setRawMode(true);
|
|
6
|
+
const readFx = function () {
|
|
7
|
+
const buf = process.stdin.read();
|
|
8
|
+
const str = JSON.stringify(buf); // "\u001b[9;1R"
|
|
9
|
+
const xy = /\[.*/.exec(str)?.[0].replaceAll(/\[|R"/g, '').split(';');
|
|
10
|
+
process.stdin.setRawMode(false);
|
|
11
|
+
resolve([Number(xy?.[1] ?? 0), Number(xy?.[0] ?? 0)]);
|
|
12
|
+
};
|
|
13
|
+
process.stdin.once('readable', readFx);
|
|
14
|
+
process.stdout.write(termcodes.cursorGetPosition);
|
|
15
|
+
});
|
|
16
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/lanes.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Animations, FPS } from './types.js';
|
|
2
|
-
type Log = [id: number, message: string];
|
|
2
|
+
type Log = readonly [id: number, message: string];
|
|
3
3
|
type SortFunc = (a: Log, b: Log) => number;
|
|
4
4
|
export type LanesOptions = {
|
|
5
|
-
animations?: Animations;
|
|
6
|
-
fps?: FPS;
|
|
7
|
-
indent?: string;
|
|
8
|
-
sort?: SortFunc;
|
|
5
|
+
readonly animations?: Animations;
|
|
6
|
+
readonly fps?: FPS;
|
|
7
|
+
readonly indent?: string;
|
|
8
|
+
readonly sort?: SortFunc;
|
|
9
|
+
readonly verbose?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare class Lanes {
|
|
11
12
|
#private;
|
package/dist/lanes.js
CHANGED
|
@@ -4,36 +4,52 @@ export class Lanes {
|
|
|
4
4
|
#header;
|
|
5
5
|
#indent = '';
|
|
6
6
|
#logs = new Map();
|
|
7
|
+
#verbose;
|
|
7
8
|
#sort = ([a], [b]) => a - b;
|
|
8
9
|
constructor(options) {
|
|
9
10
|
this.#display = new Display({
|
|
10
11
|
animations: options?.animations,
|
|
11
12
|
fps: options?.fps,
|
|
13
|
+
verbose: options?.verbose,
|
|
12
14
|
});
|
|
13
15
|
this.#indent = options?.indent ?? this.#indent;
|
|
14
16
|
this.#sort = options?.sort ?? this.#sort;
|
|
17
|
+
this.#verbose = options?.verbose ?? false;
|
|
15
18
|
}
|
|
16
19
|
close() {
|
|
17
20
|
this.#display.close();
|
|
18
21
|
}
|
|
19
22
|
delete(id) {
|
|
23
|
+
if (this.#verbose) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
20
26
|
this.#logs.delete(id);
|
|
21
27
|
this.write();
|
|
22
28
|
}
|
|
23
29
|
header(text) {
|
|
24
30
|
this.#header = text;
|
|
31
|
+
if (this.#verbose) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
25
34
|
this.write();
|
|
26
35
|
}
|
|
27
36
|
update(id, log) {
|
|
37
|
+
if (this.#verbose) {
|
|
38
|
+
this.#display.write(this.#header + ' ' + log);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
28
41
|
this.#logs.set(id, log);
|
|
29
42
|
this.write();
|
|
30
43
|
}
|
|
31
44
|
write() {
|
|
45
|
+
if (this.#verbose) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
32
48
|
const logs = [...this.#logs.entries()];
|
|
33
49
|
logs.sort(this.#sort);
|
|
34
50
|
const messages = logs.map(([, message]) => `${this.#indent}${message}`);
|
|
35
51
|
if (this.#header) {
|
|
36
|
-
messages.unshift(this.#header);
|
|
52
|
+
messages.unshift(...this.#header.split('\n'));
|
|
37
53
|
}
|
|
38
54
|
this.#display.write(...messages);
|
|
39
55
|
}
|
package/dist/riffle.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Animations } from './types.js';
|
|
2
|
-
export declare function riffle(text: string, elapsed: number, animations: Animations): string;
|
|
2
|
+
export declare function riffle(text: string, elapsed: number, animations: Animations, hidden?: boolean): string;
|
package/dist/riffle.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export function riffle(text, elapsed, animations) {
|
|
1
|
+
export function riffle(text, elapsed, animations, hidden = false) {
|
|
2
2
|
for (const key of Object.keys(animations)) {
|
|
3
|
+
if (hidden) {
|
|
4
|
+
text = text.replaceAll(`%${key}%`, '');
|
|
5
|
+
continue;
|
|
6
|
+
}
|
|
3
7
|
const animation = animations[key];
|
|
4
8
|
if (!animation) {
|
|
5
9
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/dealer",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A tool that provides an API and CLI for parallel processing of collections and sequential logging to standard output",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc",
|
|
23
|
+
"watch": "tsc --watch",
|
|
23
24
|
"clean": "tsc --build --clean"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"ansi-colors": "4.1.3"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
|
|
29
30
|
}
|