-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinnerUtil.js
More file actions
56 lines (47 loc) · 1.88 KB
/
spinnerUtil.js
File metadata and controls
56 lines (47 loc) · 1.88 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
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
/**
* Creates a loading spinner with message
* @param {string} message - The message to display
* @returns {Object} - Object containing interval and update functions
*/
function createSpinner(message) {
let frameIndex = 0;
process.stdout.write(`\r${spinnerFrames[0]} ${message}`);
const interval = setInterval(() => {
frameIndex = (frameIndex + 1) % spinnerFrames.length;
process.stdout.write(`\r${spinnerFrames[frameIndex]} ${message}`);
}, 80);
return {
interval,
succeed: (id, details = {}) => {
clearInterval(interval);
let message = `✅ Installed ${id}`;
if (details.symbolName) {
message += ` (${details.symbolName})`;
}
const counts = [];
if (details.footprintCount > 0) {
counts.push(`${details.footprintCount} footprint${details.footprintCount > 1 ? 's' : ''}`);
}
if (details.modelCount > 0) {
counts.push(`${details.modelCount} 3D model${details.modelCount > 1 ? 's' : ''}`);
}
if (counts.length > 0) {
message += ` with ${counts.join(', ')}`;
}
process.stdout.write(`\r${message}\n`);
},
update: (newMessage) => {
process.stdout.write(`\r${spinnerFrames[frameIndex]} ${newMessage}`);
},
clear: () => {
clearInterval(interval);
process.stdout.write('\r' + ' '.repeat(process.stdout.columns - 1) + '\r');
},
fail: (id, error) => {
clearInterval(interval);
process.stdout.write(`\r❌ Failed to install ${id} - ${error}\n`);
}
};
}
module.exports = { createSpinner };