@nomyx/assistant
Version:
A powerful assistant library and cli for your AI projects. works with Vertex AI (Claude and Gemini)
51 lines (50 loc) • 2.08 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Spinner = void 0;
const chalk_1 = __importDefault(require("chalk"));
class Spinner {
constructor() {
this.spinnerTypes = [
['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷', '⣜', '⣄'],
['🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘'],
['◐', '◓', '◑', '◒'],
['▖', '▘', '▝', '▗'],
['◢', '◣', '◤', '◥'],
['◰', '◳', '◲', '◱'],
['◴', '◷', '◶', '◵'],
['▰', '▱'],
['▉', '▊', '▋', '▌', '▍', '▎', '▏', '▎', '▍', '▌', '▋', '▊', '▉'],
['▁', '▃', '▄', '▅', '▆', '▇', '▆', '▅', '▄', '▃'],
];
this.currentCharIndex = 0;
this.currentTypeIndex = 0;
this.spinnerChars = this.spinnerTypes[this.currentTypeIndex];
this.interval = null;
}
start(message = 'Loading...') {
this.currentTypeIndex = Math.floor(Math.random() * this.spinnerTypes.length);
this.spinnerChars = this.spinnerTypes[this.currentTypeIndex];
process.stdout.write(`\r\n${message}`);
this.interval = setInterval(() => {
process.stdout.write(`\r${message} ${this.spinnerChars[this.currentCharIndex]}`);
this.currentCharIndex = (this.currentCharIndex + 1) % this.spinnerChars.length;
}, 100);
}
stop() {
this.interval && clearInterval(this.interval);
process.stdout.write('\r\n');
}
succeed(message = 'Done!') {
console.log(chalk_1.default.green(message));
this.stop();
}
fail(message = 'Failed!') {
console.log(chalk_1.default.red(message));
this.stop();
}
}
exports.Spinner = Spinner;