scai
Version:
> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.
45 lines (44 loc) • 1.24 kB
JavaScript
export class Spinner {
constructor(message) {
this.frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
this.interval = null;
this.i = 0;
if (message) {
this.text = message;
}
}
start() {
process.stdout.write('\x1b[?25l'); // hide cursor
if (this.text) {
process.stdout.write(` ${this.text}`);
}
this.interval = setInterval(() => {
const text = this.text ?? '';
process.stdout.write('\r');
process.stdout.write(`${this.frames[this.i]} ${text}`);
this.i = (this.i + 1) % this.frames.length;
}, 80);
}
update(text) {
this.text = text;
}
succeed(msg) {
this.stop();
process.stdout.write('\r'); // go to start
if (msg) {
console.log(`✅ ${msg}`);
}
}
fail(msg) {
this.stop();
process.stdout.write('\r'); // go to start
console.log(`❌ ${msg}`);
}
stop() {
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
process.stdout.write('\x1b[?25h'); // show cursor
}
}