Skip to content

Commit a4dbfb2

Browse files
committed
Add spinner indicator
1 parent ecf9782 commit a4dbfb2

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

lib/handler.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export async function handleRender(source, options) {
4242

4343
try {
4444
const start = Date.now();
45+
let spinner = showSpinner();
4546
const output = await render(content, options);
47+
spinner.stop();
4648
const time = (Date.now() - start) / 1000;
4749
if (output) {
4850
console.log(`Saved to ${output}. (${time}s)`);
@@ -212,3 +214,18 @@ function readTime(number, options = {}) {
212214
}
213215
return Math.min(result, options.max ?? Infinity);
214216
}
217+
218+
function showSpinner() {
219+
let i = 0;
220+
let spinner = ['|', '/', '-', '\\'];
221+
let timer = setInterval(() => {
222+
process.stdout.write(`\r${spinner[i++]}`);
223+
i &= 3;
224+
}, 100);
225+
return {
226+
stop: () => {
227+
clearInterval(timer);
228+
process.stdout.write('\r');
229+
}
230+
}
231+
}

0 commit comments

Comments
 (0)