Skip to content

Commit

Permalink
fix: use stderr for loading (#69)
Browse files Browse the repository at this point in the history
Closes #53
  • Loading branch information
ps-kwang authored Apr 25, 2024
1 parent 0befc5d commit abe6efa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export async function loading<Promised extends Promise<any>>(
}

async function spin() {
await write(cursorHide());
await write(cursorHide(), Deno.stderr);

while (spinning) {
await writeLn(frames[i++ % frames.length] + " " + text);
await writeLn(frames[i++ % frames.length] + " " + text, Deno.stderr);
await new Promise<void>((resolve) =>
setTimeout(async () => {
await write(cursorUp(1) + eraseDown());
await write(cursorUp(1) + eraseDown(), Deno.stderr);
resolve();
}, 100)
);
Expand All @@ -47,13 +47,13 @@ export async function loading<Promised extends Promise<any>>(
spinning = false;
return value;
}).catch(async (error) => {
await write(cursorUp(1) + eraseDown() + cursorShow());
await write(cursorUp(1) + eraseDown() + cursorShow(), Deno.stderr);
throw error;
}),
spin(),
]);

await write(cursorShow());
await write(cursorShow(), Deno.stderr);
return value;
}

Expand Down

0 comments on commit abe6efa

Please sign in to comment.