forked from BeOnAuto/auto-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole-tools.ts.old
More file actions
75 lines (64 loc) · 2.61 KB
/
console-tools.ts.old
File metadata and controls
75 lines (64 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import kleur from 'kleur';
import readline from 'readline';
import process from 'process';
export const COLORS = [kleur.red, kleur.yellow, kleur.green, kleur.cyan, kleur.blue, kleur.magenta];
const repeat = (arr: string[], n: number) => Array(n).fill(arr).flat();
const SEQUENCES: Record<number, string[]> = {
0: ['⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏', '⠋', '⠙', '⠹'],
1: ['⠴', '⠲', '⠳', '⠓', '⠋', '⠙', '⠚', '⠞', '⠖', '⠦'],
2: ['▏', '▎', '▍', '▌', '▋', '▊', '▉', '█', '▉', '▊', '▋', '▌', '▍', '▎'],
3: ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█', '▇', '▆', '▅', '▄', '▃', '▂'],
4: ['🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘'],
5: ['⏳', '⏳', '⌛', '⌛', '⏳', '⏳', '⌛', '⌛'],
6: ['░', '░', '▒', '▒', '▓', '▓', '█', '█', '▓', '▓', '▒', '▒'],
};
export const THINKING = [
...repeat(SEQUENCES[0], 3),
...repeat(SEQUENCES[0], 3).reverse(),
...repeat(SEQUENCES[1], 3),
...repeat(SEQUENCES[1], 3).reverse(),
];
export const SCAFFOLDING = [...SEQUENCES[6], ...SEQUENCES[6], ...SEQUENCES[6].reverse(), ...SEQUENCES[6]];
export const BUILDING = [...SEQUENCES[2], ...SEQUENCES[3]];
export const WAITING = [...SEQUENCES[4], ...SEQUENCES[4], ...SEQUENCES[4].reverse(), ...SEQUENCES[4]];
export const HOURGLASS = [...SEQUENCES[5], ...SEQUENCES[5], ...SEQUENCES[5].reverse(), ...SEQUENCES[5]];
export class ConsoleTools {
animation: NodeJS.Timeout | undefined;
updateConsole(message: string): ConsoleTools {
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 0);
process.stdout.write(message);
return this;
}
animate(message: string, sequence: string[], delay = 100): ConsoleTools {
let index = 0;
let colorIndex = 0;
this.animation = setInterval(() => {
const colorFunction = COLORS[colorIndex];
this.updateConsole(`${colorFunction(sequence[index])} ${message}`);
index = (index + 1) % sequence.length;
colorIndex = (colorIndex + 1) % COLORS.length;
}, delay);
return this;
}
stopAnimation(): ConsoleTools {
if (this.animation) clearInterval(this.animation);
return this;
}
clear(): ConsoleTools {
// eslint-disable-next-line no-console
console.clear();
return this;
}
hide(): ConsoleTools {
// eslint-disable-next-line no-console
process.stdout.write('\x1B[?25l');
return this;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
log(...args: any[]): ConsoleTools {
// eslint-disable-next-line no-console
console.log(...args);
return this;
}
}