UNPKG

@blitzjs/display

Version:

Display package for the Blitz CLI

189 lines (151 loc) 4.06 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var c = require('chalk'); var consoleTablePrinter = require('console-table-printer'); var ora = require('ora'); var readline = require('readline'); function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } var c__default = /*#__PURE__*/_interopDefault(c); var ora__default = /*#__PURE__*/_interopDefault(ora); var readline__default = /*#__PURE__*/_interopDefault(readline); var table = consoleTablePrinter.Table; var chalk = c__default['default']; // const blitzTrueBrandColor = '6700AB' var blitzBrightBrandColor = "8a3df0"; // Using bright brand color so it's better for dark terminals var brandColor = blitzBrightBrandColor; var withBrand = function withBrand(str) { return c__default['default'].hex(brandColor).bold(str); }; var withWarning = function withWarning(str) { return "\u26A0\uFE0F " + c__default['default'].yellow(str); }; var withCaret = function withCaret(str) { return c__default['default'].gray(">") + " " + str; }; var withCheck = function withCheck(str) { return c__default['default'].green("✔") + " " + str; }; var withX = function withX(str) { return c__default['default'].red.bold("✕") + " " + str; }; var withProgress = function withProgress(str) { return withCaret(str); }; var withError = function withError(str) { return withX(c__default['default'].red.bold(str)); }; /** * Logs a branded purple message to stdout. * * @param {string} msg */ var branded = function branded(msg) { console.log(c__default['default'].hex(brandColor).bold(msg)); }; /** * Clears the line and optionally log a message to stdout. * * @param {string} msg */ var clearLine = function clearLine(msg) { readline__default['default'].clearLine(process.stdout, 0); readline__default['default'].cursorTo(process.stdout, 0); msg && process.stdout.write(msg); }; var clearConsole = function clearConsole() { if (process.platform === "win32") { process.stdout.write("\x1B[2J\x1B[0f"); } else { process.stdout.write("\x1B[2J\x1B[3J\x1B[H"); } }; /** * Logs a red error message to stderr. * * @param {string} msg */ var warning = function warning(msg) { console.log(withCaret(withWarning(msg))); }; /** * Logs a red error message to stderr. * * @param {string} msg */ var error = function error(msg) { console.error(withX(c__default['default'].red.bold(msg))); }; /** * Logs a subtle gray message to stdout. * * @param {string} msg */ var meta = function meta(msg) { console.log(withCaret(c__default['default'].gray(msg))); }; /** * Logs a progress message to stdout. * * @param {string} msg */ var progress = function progress(msg) { console.log(withProgress(msg)); }; var info = function info(msg) { console.log(c__default['default'].bold(msg)); }; var spinner = function spinner(str) { return ora__default['default']({ text: str, color: "blue", spinner: { interval: 120, frames: ["◢", "◣", "◤", "◥"] } }); }; /** * Logs a green success message to stdout. * * @param {string} msg */ var success = function success(msg) { console.log(withCheck(c__default['default'].green(msg))); }; /** * Colorizes a variable for display. * * @param {string} val */ var variable = function variable(val) { return c__default['default'].cyan.bold("" + val); }; /** * If the DEBUG env var is set this will write to the console * @param str msg */ var debug = /*#__PURE__*/require("debug")("blitz"); var log = { withBrand: withBrand, withWarning: withWarning, withCaret: withCaret, withCheck: withCheck, withX: withX, withProgress: withProgress, withError: withError, branded: branded, clearLine: clearLine, clearConsole: clearConsole, error: error, warning: warning, meta: meta, progress: progress, spinner: spinner, success: success, variable: variable, info: info, debug: debug, Table: consoleTablePrinter.Table }; exports.chalk = chalk; exports.log = log; exports.table = table;