scai
Version:
> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.
32 lines (31 loc) • 905 B
JavaScript
// lib/spinner.ts
export class Spinner {
constructor(message) {
this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
this.interval = null;
this.i = 0;
this.text = message;
}
start() {
process.stdout.write('\x1b[?25l'); // hide cursor
this.interval = setInterval(() => {
const frame = this.frames[this.i = ++this.i % this.frames.length];
process.stdout.write(`\r${frame} ${this.text} `);
}, 80);
}
succeed(msg) {
this.stop();
process.stdout.write(`\r✅ ${msg}\n`);
}
fail(msg) {
this.stop();
process.stdout.write(`\r❌ ${msg}\n`);
}
stop() {
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
process.stdout.write('\x1b[?25h'); // show cursor
}
}