@blitzjs/display
Version:
Display package for the Blitz CLI
177 lines (143 loc) • 3.32 kB
JavaScript
import c from 'chalk';
import { Table } from 'console-table-printer';
import ora from 'ora';
import readline from 'readline';
var table = Table;
var chalk = c; // 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.hex(brandColor).bold(str);
};
var withWarning = function withWarning(str) {
return "\u26A0\uFE0F " + c.yellow(str);
};
var withCaret = function withCaret(str) {
return c.gray(">") + " " + str;
};
var withCheck = function withCheck(str) {
return c.green("✔") + " " + str;
};
var withX = function withX(str) {
return c.red.bold("✕") + " " + str;
};
var withProgress = function withProgress(str) {
return withCaret(str);
};
var withError = function withError(str) {
return withX(c.red.bold(str));
};
/**
* Logs a branded purple message to stdout.
*
* @param {string} msg
*/
var branded = function branded(msg) {
console.log(c.hex(brandColor).bold(msg));
};
/**
* Clears the line and optionally log a message to stdout.
*
* @param {string} msg
*/
var clearLine = function clearLine(msg) {
readline.clearLine(process.stdout, 0);
readline.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.red.bold(msg)));
};
/**
* Logs a subtle gray message to stdout.
*
* @param {string} msg
*/
var meta = function meta(msg) {
console.log(withCaret(c.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.bold(msg));
};
var spinner = function spinner(str) {
return ora({
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.green(msg)));
};
/**
* Colorizes a variable for display.
*
* @param {string} val
*/
var variable = function variable(val) {
return c.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: Table
};
export { chalk, log, table };