UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API g

43 lines (42 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Spinner = void 0; const process = require("process"); const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; class Spinner { constructor() { this.frames = SPINNER_FRAMES; this.currentFrame = 0; this.intervalId = null; this.message = ''; } showFrame() { process.stdout.write('\r' + this.frames[this.currentFrame] + ' ' + this.message); this.currentFrame = (this.currentFrame + 1) % this.frames.length; } start(message) { if (this.message === message) { return; } this.message = message; // If we're not in a TTY, don't display the spinner. if (!process.stdout.isTTY) { process.stdout.write(`${message}...\n`); return; } if (this.intervalId === null) { this.intervalId = setInterval(() => { this.showFrame(); }, 100); } } stop() { if (this.intervalId !== null) { clearInterval(this.intervalId); this.intervalId = null; process.stdout.write('\r'); } this.message = ''; } } exports.Spinner = Spinner;