UNPKG

leetcode-fetcher-cli

Version:

A CLi Application for local fetching of leetcode problems

41 lines (40 loc) 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = __importDefault(require("../constants")); const chalk_1 = __importDefault(require("chalk")); class Spinner { interval_id; counter; message; constructor(message) { this.counter = 0; this.message = message; } start() { if (this.interval_id !== undefined) { return; } const interval = constants_1.default.SPINNER.DOTS.INTERVAL; const frames = constants_1.default.SPINNER.DOTS.FRAMES; this.interval_id = setInterval(() => { process.stdout.write(chalk_1.default.cyanBright(`${frames[this.counter]}`) + chalk_1.default.bold(chalk_1.default.gray(` ${this.message}`)) + '\r'); this.counter = (this.counter + 1) % frames.length; }, interval); } stop() { clearInterval(this.interval_id); this.interval_id = undefined; this.counter = 0; process.stdout.clearLine(0); process.stdout.cursorTo(0); } changeMessage(msg) { this.message = msg; } } ; exports.default = Spinner;