UNPKG

@plugjs/plug

Version:
101 lines (99 loc) 3.4 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // logging/spinner.ts var spinner_exports = {}; __export(spinner_exports, { disableWrap: () => disableWrap, enableWrap: () => enableWrap, setupSpinner: () => setupSpinner, zapSpinner: () => zapSpinner }); module.exports = __toCommonJS(spinner_exports); var import_async = require("../async.cjs"); var import_colors = require("./colors.cjs"); var import_options = require("./options.cjs"); var zapSpinner = "\x1B[0G\x1B[2K"; var disableWrap = "\x1B[?7l"; var enableWrap = "\x1B[?7h"; var _output = import_options.logOptions.output; var _colors = import_options.logOptions.colors; var _format = import_options.logOptions.format; var _spinner = import_options.logOptions.spinner; var _taskLength = import_options.logOptions.taskLength; import_options.logOptions.on("changed", ({ output, colors, format, spinner, taskLength }) => { _output = output; _colors = colors; _format = format; _spinner = spinner; _taskLength = taskLength; setupSpinner(); }); var _spins = [ (0, import_colors.$cyn)("\u2809"), // ⠉ - 14 (0, import_colors.$cyn)("\u2819"), // ⠙ - 145 (0, import_colors.$cyn)("\u2818"), // ⠘ - 45 (0, import_colors.$cyn)("\u2838"), // ⠸ - 456 (0, import_colors.$cyn)("\u2830"), // ⠰ - 56 (0, import_colors.$cyn)("\u2834"), // ⠴ - 356 (0, import_colors.$cyn)("\u2824"), // ⠤ - 36 (0, import_colors.$cyn)("\u2826"), // ⠦ - 236 (0, import_colors.$cyn)("\u2806"), // ⠆ - 23 (0, import_colors.$cyn)("\u2807"), // ⠇ - 123 (0, import_colors.$cyn)("\u2803"), // ⠃ - 12 (0, import_colors.$cyn)("\u280B") // ⠋ - 124 ]; var _nextSpin = 0; var _interval; function spin() { if (!_colors) return clearInterval(_interval); if (!_spinner) return clearInterval(_interval); const tasks = (0, import_async.runningTasks)(); if (!tasks.length) return; const pad = "".padStart(_taskLength, " "); const names = tasks.map((task2) => (0, import_colors.$t)(task2)).join((0, import_colors.$gry)(", ")); const task = (0, import_colors.$plur)(tasks.length, "task", "tasks"); _nextSpin = ++_nextSpin % _spins.length; _output.write(`${zapSpinner}${disableWrap}${pad} ${_spins[_nextSpin]} Running ${task}: ${(0, import_colors.$gry)(names)}${enableWrap}`); } function setupSpinner() { if (_interval) clearInterval(_interval); if (_colors && _spinner && _format === "fancy") { _interval = setInterval(spin, 150).unref(); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { disableWrap, enableWrap, setupSpinner, zapSpinner }); //# sourceMappingURL=spinner.cjs.map