first commit
This commit is contained in:
34
node_modules/@oclif/core/lib/ux/action/base.d.ts
generated
vendored
Normal file
34
node_modules/@oclif/core/lib/ux/action/base.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Options } from './types';
|
||||
type Task = {
|
||||
action: string;
|
||||
active: boolean;
|
||||
status: string | undefined;
|
||||
};
|
||||
export type ActionType = 'debug' | 'simple' | 'spinner';
|
||||
export declare class ActionBase {
|
||||
std: 'stderr' | 'stdout';
|
||||
protected stdmocks?: ['stderr' | 'stdout', string[]][];
|
||||
type: ActionType;
|
||||
private stdmockOrigs;
|
||||
private get globals();
|
||||
protected get output(): string | undefined;
|
||||
protected set output(output: string | undefined);
|
||||
get running(): boolean;
|
||||
get status(): string | undefined;
|
||||
set status(status: string | undefined);
|
||||
get task(): Task | undefined;
|
||||
set task(task: Task | undefined);
|
||||
protected _flushStdout(): void;
|
||||
protected _pause(_?: string): void;
|
||||
protected _resume(): void;
|
||||
protected _start(_opts: Options): void;
|
||||
protected _stdout(toggle: boolean): void;
|
||||
protected _stop(_: string): void;
|
||||
protected _updateStatus(_: string | undefined, __?: string): void;
|
||||
protected _write(std: 'stderr' | 'stdout', s: string | string[]): void;
|
||||
pause(fn: () => any, icon?: string): Promise<any>;
|
||||
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
||||
start(action: string, status?: string, opts?: Options): void;
|
||||
stop(msg?: string): void;
|
||||
}
|
||||
export {};
|
||||
183
node_modules/@oclif/core/lib/ux/action/base.js
generated
vendored
Normal file
183
node_modules/@oclif/core/lib/ux/action/base.js
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ActionBase = void 0;
|
||||
const node_util_1 = require("node:util");
|
||||
const util_1 = require("../../util/util");
|
||||
class ActionBase {
|
||||
std = 'stderr';
|
||||
stdmocks;
|
||||
type;
|
||||
stdmockOrigs = {
|
||||
stderr: process.stderr.write,
|
||||
stdout: process.stdout.write,
|
||||
};
|
||||
get globals() {
|
||||
;
|
||||
globalThis.ux = globalThis.ux || {};
|
||||
const globals = globalThis.ux;
|
||||
globals.action = globals.action || {};
|
||||
return globals;
|
||||
}
|
||||
get output() {
|
||||
return this.globals.output;
|
||||
}
|
||||
set output(output) {
|
||||
this.globals.output = output;
|
||||
}
|
||||
get running() {
|
||||
return Boolean(this.task);
|
||||
}
|
||||
get status() {
|
||||
return this.task ? this.task.status : undefined;
|
||||
}
|
||||
set status(status) {
|
||||
const { task } = this;
|
||||
if (!task) {
|
||||
return;
|
||||
}
|
||||
if (task.status === status) {
|
||||
return;
|
||||
}
|
||||
this._updateStatus(status, task.status);
|
||||
task.status = status;
|
||||
}
|
||||
get task() {
|
||||
return this.globals.action.task;
|
||||
}
|
||||
set task(task) {
|
||||
this.globals.action.task = task;
|
||||
}
|
||||
// flush mocked stdout/stderr
|
||||
_flushStdout() {
|
||||
try {
|
||||
let output = '';
|
||||
let std;
|
||||
while (this.stdmocks && this.stdmocks.length > 0) {
|
||||
const cur = this.stdmocks.shift();
|
||||
std = cur[0];
|
||||
this._write(std, cur[1]);
|
||||
output += cur[1][0].toString('utf8');
|
||||
}
|
||||
// add newline if there isn't one already
|
||||
// otherwise we'll just overwrite it when we render
|
||||
if (output && std && output.at(-1) !== '\n') {
|
||||
this._write(std, '\n');
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this._write('stderr', (0, node_util_1.inspect)(error));
|
||||
}
|
||||
}
|
||||
_pause(_) {
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
_resume() {
|
||||
if (this.task)
|
||||
this.start(this.task.action, this.task.status);
|
||||
}
|
||||
_start(_opts) {
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
// mock out stdout/stderr so it doesn't screw up the rendering
|
||||
_stdout(toggle) {
|
||||
try {
|
||||
if (toggle) {
|
||||
if (this.stdmocks)
|
||||
return;
|
||||
this.stdmockOrigs = {
|
||||
stderr: process.stderr.write,
|
||||
stdout: process.stdout.write,
|
||||
};
|
||||
this.stdmocks = [];
|
||||
process.stdout.write = (...args) => {
|
||||
this.stdmocks.push(['stdout', args]);
|
||||
return true;
|
||||
};
|
||||
process.stderr.write = (...args) => {
|
||||
this.stdmocks.push(['stderr', args]);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
else {
|
||||
if (!this.stdmocks)
|
||||
return;
|
||||
// this._write('stderr', '\nresetstdmock\n\n\n')
|
||||
delete this.stdmocks;
|
||||
process.stdout.write = this.stdmockOrigs.stdout;
|
||||
process.stderr.write = this.stdmockOrigs.stderr;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
this._write('stderr', (0, node_util_1.inspect)(error));
|
||||
}
|
||||
}
|
||||
_stop(_) {
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
_updateStatus(_, __) {
|
||||
// Not implemented
|
||||
}
|
||||
// write to the real stdout/stderr
|
||||
_write(std, s) {
|
||||
switch (std) {
|
||||
case 'stderr': {
|
||||
this.stdmockOrigs.stderr.apply(process.stderr, (0, util_1.castArray)(s));
|
||||
break;
|
||||
}
|
||||
case 'stdout': {
|
||||
this.stdmockOrigs.stdout.apply(process.stdout, (0, util_1.castArray)(s));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error(`invalid std: ${std}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
pause(fn, icon) {
|
||||
const { task } = this;
|
||||
const active = task && task.active;
|
||||
if (task && active) {
|
||||
this._pause(icon);
|
||||
this._stdout(false);
|
||||
task.active = false;
|
||||
}
|
||||
const ret = fn();
|
||||
if (task && active) {
|
||||
this._resume();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
async pauseAsync(fn, icon) {
|
||||
const { task } = this;
|
||||
const active = task && task.active;
|
||||
if (task && active) {
|
||||
this._pause(icon);
|
||||
this._stdout(false);
|
||||
task.active = false;
|
||||
}
|
||||
const ret = await fn();
|
||||
if (task && active) {
|
||||
this._resume();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
start(action, status, opts = {}) {
|
||||
this.std = opts.stdout ? 'stdout' : 'stderr';
|
||||
const task = { action, active: Boolean(this.task && this.task.active), status };
|
||||
this.task = task;
|
||||
this._start(opts);
|
||||
task.active = true;
|
||||
this._stdout(true);
|
||||
}
|
||||
stop(msg = 'done') {
|
||||
const { task } = this;
|
||||
if (!task) {
|
||||
return;
|
||||
}
|
||||
this._stop(msg);
|
||||
task.active = false;
|
||||
this.task = undefined;
|
||||
this._stdout(false);
|
||||
}
|
||||
}
|
||||
exports.ActionBase = ActionBase;
|
||||
11
node_modules/@oclif/core/lib/ux/action/simple.d.ts
generated
vendored
Normal file
11
node_modules/@oclif/core/lib/ux/action/simple.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ActionBase, ActionType } from './base';
|
||||
export default class SimpleAction extends ActionBase {
|
||||
type: ActionType;
|
||||
protected _pause(icon?: string): void;
|
||||
protected _resume(): void;
|
||||
protected _start(): void;
|
||||
protected _stop(status: string): void;
|
||||
protected _updateStatus(status: string, prevStatus?: string, newline?: boolean): void;
|
||||
private _flush;
|
||||
private _render;
|
||||
}
|
||||
47
node_modules/@oclif/core/lib/ux/action/simple.js
generated
vendored
Normal file
47
node_modules/@oclif/core/lib/ux/action/simple.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const base_1 = require("./base");
|
||||
class SimpleAction extends base_1.ActionBase {
|
||||
type = 'simple';
|
||||
_pause(icon) {
|
||||
if (icon)
|
||||
this._updateStatus(icon);
|
||||
else
|
||||
this._flush();
|
||||
}
|
||||
_resume() {
|
||||
// Not implemented
|
||||
}
|
||||
_start() {
|
||||
if (!this.task)
|
||||
return;
|
||||
this._render(this.task.action, this.task.status);
|
||||
}
|
||||
_stop(status) {
|
||||
if (!this.task)
|
||||
return;
|
||||
this._updateStatus(status, this.task.status, true);
|
||||
}
|
||||
_updateStatus(status, prevStatus, newline = false) {
|
||||
if (!this.task)
|
||||
return;
|
||||
if (this.task.active && !prevStatus)
|
||||
this._write(this.std, ` ${status}`);
|
||||
else
|
||||
this._write(this.std, `${this.task.action}... ${status}`);
|
||||
if (newline || !prevStatus)
|
||||
this._flush();
|
||||
}
|
||||
_flush() {
|
||||
this._write(this.std, '\n');
|
||||
this._flushStdout();
|
||||
}
|
||||
_render(action, status) {
|
||||
if (!this.task)
|
||||
return;
|
||||
if (this.task.active)
|
||||
this._flush();
|
||||
this._write(this.std, status ? `${action}... ${status}` : `${action}...`);
|
||||
}
|
||||
}
|
||||
exports.default = SimpleAction;
|
||||
19
node_modules/@oclif/core/lib/ux/action/spinner.d.ts
generated
vendored
Normal file
19
node_modules/@oclif/core/lib/ux/action/spinner.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ActionBase, ActionType } from './base';
|
||||
import { Options } from './types';
|
||||
export default class SpinnerAction extends ActionBase {
|
||||
type: ActionType;
|
||||
private color;
|
||||
private frameIndex;
|
||||
private frames;
|
||||
private spinner?;
|
||||
constructor();
|
||||
protected _frame(): string;
|
||||
protected _pause(icon?: string): void;
|
||||
protected _start(opts: Options): void;
|
||||
protected _stop(status: string): void;
|
||||
protected colorize(s: string): string;
|
||||
private _lines;
|
||||
private _render;
|
||||
private _reset;
|
||||
private getFrames;
|
||||
}
|
||||
88
node_modules/@oclif/core/lib/ux/action/spinner.js
generated
vendored
Normal file
88
node_modules/@oclif/core/lib/ux/action/spinner.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ansiEscapes = require('ansi-escapes');
|
||||
const ansis_1 = __importDefault(require("ansis"));
|
||||
const cli_spinners_1 = __importDefault(require("cli-spinners"));
|
||||
const cache_1 = __importDefault(require("../../cache"));
|
||||
const screen_1 = require("../../screen");
|
||||
const theme_1 = require("../theme");
|
||||
const base_1 = require("./base");
|
||||
class SpinnerAction extends base_1.ActionBase {
|
||||
type = 'spinner';
|
||||
color = 'magenta';
|
||||
frameIndex;
|
||||
frames;
|
||||
spinner;
|
||||
constructor() {
|
||||
super();
|
||||
this.frames = this.getFrames();
|
||||
this.frameIndex = 0;
|
||||
}
|
||||
_frame() {
|
||||
const frame = this.frames[this.frameIndex];
|
||||
this.frameIndex = ++this.frameIndex % this.frames.length;
|
||||
return this.colorize(frame);
|
||||
}
|
||||
_pause(icon) {
|
||||
if (this.spinner)
|
||||
clearInterval(this.spinner);
|
||||
this._reset();
|
||||
if (icon)
|
||||
this._render(` ${icon}`);
|
||||
this.output = undefined;
|
||||
}
|
||||
_start(opts) {
|
||||
this.color = cache_1.default.getInstance().get('config')?.theme?.spinner ?? this.color;
|
||||
if (opts.style)
|
||||
this.frames = this.getFrames(opts);
|
||||
this._reset();
|
||||
if (this.spinner)
|
||||
clearInterval(this.spinner);
|
||||
this._render();
|
||||
this.spinner = setInterval((icon) => this._render.bind(this)(icon), process.platform === 'win32' ? 500 : 100, 'spinner');
|
||||
const interval = this.spinner;
|
||||
interval.unref();
|
||||
}
|
||||
_stop(status) {
|
||||
if (this.task)
|
||||
this.task.status = status;
|
||||
if (this.spinner)
|
||||
clearInterval(this.spinner);
|
||||
this._render();
|
||||
this.output = undefined;
|
||||
}
|
||||
colorize(s) {
|
||||
return (0, theme_1.colorize)(this.color, s);
|
||||
}
|
||||
_lines(s) {
|
||||
return ansis_1.default.strip(s).split('\n')
|
||||
.map((l) => Math.ceil(l.length / screen_1.errtermwidth))
|
||||
.reduce((c, i) => c + i, 0);
|
||||
}
|
||||
_render(icon) {
|
||||
if (!this.task)
|
||||
return;
|
||||
this._reset();
|
||||
this._flushStdout();
|
||||
const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || '';
|
||||
const status = this.task.status ? ` ${this.task.status}` : '';
|
||||
this.output = `${this.task.action}...${frame}${status}\n`;
|
||||
this._write(this.std, this.output);
|
||||
}
|
||||
_reset() {
|
||||
if (!this.output)
|
||||
return;
|
||||
const lines = this._lines(this.output);
|
||||
this._write(this.std, ansiEscapes.cursorLeft + ansiEscapes.cursorUp(lines) + ansiEscapes.eraseDown);
|
||||
this.output = undefined;
|
||||
}
|
||||
getFrames(opts) {
|
||||
if (opts?.style)
|
||||
return cli_spinners_1.default[opts.style].frames;
|
||||
return cli_spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
|
||||
}
|
||||
}
|
||||
exports.default = SpinnerAction;
|
||||
5
node_modules/@oclif/core/lib/ux/action/types.d.ts
generated
vendored
Normal file
5
node_modules/@oclif/core/lib/ux/action/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as spinners from 'cli-spinners';
|
||||
export type Options = {
|
||||
stdout?: boolean;
|
||||
style?: spinners.SpinnerName | 'random';
|
||||
};
|
||||
2
node_modules/@oclif/core/lib/ux/action/types.js
generated
vendored
Normal file
2
node_modules/@oclif/core/lib/ux/action/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
29
node_modules/@oclif/core/lib/ux/colorize-json.d.ts
generated
vendored
Normal file
29
node_modules/@oclif/core/lib/ux/colorize-json.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
type Options = {
|
||||
pretty?: boolean | undefined;
|
||||
theme?: Record<string, string> | undefined;
|
||||
};
|
||||
export declare function stringifyInput(json?: unknown, options?: Options): string;
|
||||
export declare function tokenize(json?: unknown, options?: Options): {
|
||||
type: string;
|
||||
value: string;
|
||||
}[];
|
||||
/**
|
||||
* Add color to JSON.
|
||||
*
|
||||
* options
|
||||
* pretty: set to true to pretty print the JSON (defaults to true)
|
||||
* theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
|
||||
*
|
||||
* Available theme keys:
|
||||
* - brace
|
||||
* - bracket
|
||||
* - colon
|
||||
* - comma
|
||||
* - key
|
||||
* - string
|
||||
* - number
|
||||
* - boolean
|
||||
* - null
|
||||
*/
|
||||
export default function colorizeJson(json: unknown, options?: Options): string;
|
||||
export {};
|
||||
100
node_modules/@oclif/core/lib/ux/colorize-json.js
generated
vendored
Normal file
100
node_modules/@oclif/core/lib/ux/colorize-json.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.stringifyInput = stringifyInput;
|
||||
exports.tokenize = tokenize;
|
||||
exports.default = colorizeJson;
|
||||
const theme_1 = require("./theme");
|
||||
const tokenTypes = [
|
||||
{ regex: /^\s+/, tokenType: 'whitespace' },
|
||||
{ regex: /^[{}]/, tokenType: 'brace' },
|
||||
{ regex: /^[[\]]/, tokenType: 'bracket' },
|
||||
{ regex: /^:/, tokenType: 'colon' },
|
||||
{ regex: /^,/, tokenType: 'comma' },
|
||||
{ regex: /^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/i, tokenType: 'number' },
|
||||
{ regex: /^"(?:\\.|[^"\\])*"(?=\s*:)/, tokenType: 'key' },
|
||||
{ regex: /^"(?:\\.|[^"\\])*"/, tokenType: 'string' },
|
||||
{ regex: /^true|^false/, tokenType: 'boolean' },
|
||||
{ regex: /^null/, tokenType: 'null' },
|
||||
];
|
||||
function stringify(value, replacer, spaces) {
|
||||
return JSON.stringify(value, serializer(replacer, replacer), spaces);
|
||||
}
|
||||
// Inspired by https://github.com/moll/json-stringify-safe
|
||||
function serializer(replacer, cycleReplacer) {
|
||||
const stack = [];
|
||||
const keys = [];
|
||||
if (!cycleReplacer)
|
||||
cycleReplacer = function (key, value) {
|
||||
if (stack[0] === value)
|
||||
return '[Circular ~]';
|
||||
return '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']';
|
||||
};
|
||||
return function (key, value) {
|
||||
if (stack.length > 0) {
|
||||
// @ts-expect-error because `this` is not typed
|
||||
const thisPos = stack.indexOf(this);
|
||||
// @ts-expect-error because `this` is not typed
|
||||
// eslint-disable-next-line no-bitwise, @typescript-eslint/no-unused-expressions
|
||||
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
||||
// eslint-disable-next-line no-bitwise, @typescript-eslint/no-unused-expressions
|
||||
~thisPos ? keys.splice(thisPos, Number.POSITIVE_INFINITY, key) : keys.push(key);
|
||||
// @ts-expect-error because `this` is not typed
|
||||
if (stack.includes(value))
|
||||
value = cycleReplacer.call(this, key, value);
|
||||
}
|
||||
else
|
||||
stack.push(value);
|
||||
// @ts-expect-error because `this` is not typed
|
||||
return replacer ? replacer.call(this, key, value) : value;
|
||||
};
|
||||
}
|
||||
function stringifyInput(json, options) {
|
||||
const str = options?.pretty
|
||||
? stringify(typeof json === 'string' ? JSON.parse(json) : json, undefined, 2)
|
||||
: typeof json === 'string'
|
||||
? json
|
||||
: stringify(json);
|
||||
return str;
|
||||
}
|
||||
function tokenize(json, options) {
|
||||
let input = stringifyInput(json, options);
|
||||
const tokens = [];
|
||||
let foundToken = false;
|
||||
do {
|
||||
for (const tokenType of tokenTypes) {
|
||||
const match = tokenType.regex.exec(input);
|
||||
if (match) {
|
||||
tokens.push({ type: tokenType.tokenType, value: match[0] });
|
||||
input = input.slice(match[0].length);
|
||||
foundToken = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (hasRemainingTokens(input, foundToken));
|
||||
return tokens;
|
||||
}
|
||||
function hasRemainingTokens(input, foundToken) {
|
||||
return (input?.length ?? 0) > 0 && foundToken;
|
||||
}
|
||||
/**
|
||||
* Add color to JSON.
|
||||
*
|
||||
* options
|
||||
* pretty: set to true to pretty print the JSON (defaults to true)
|
||||
* theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
|
||||
*
|
||||
* Available theme keys:
|
||||
* - brace
|
||||
* - bracket
|
||||
* - colon
|
||||
* - comma
|
||||
* - key
|
||||
* - string
|
||||
* - number
|
||||
* - boolean
|
||||
* - null
|
||||
*/
|
||||
function colorizeJson(json, options) {
|
||||
const opts = { ...options, pretty: options?.pretty ?? true };
|
||||
return tokenize(json, opts).reduce((acc, token) => acc + (0, theme_1.colorize)(options?.theme?.[token.type], token.value), '');
|
||||
}
|
||||
70
node_modules/@oclif/core/lib/ux/index.d.ts
generated
vendored
Normal file
70
node_modules/@oclif/core/lib/ux/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import { error } from '../errors/error';
|
||||
import { exit } from '../errors/exit';
|
||||
import { warn } from '../errors/warn';
|
||||
import Simple from './action/simple';
|
||||
import Spinner from './action/spinner';
|
||||
import colorizeJson from './colorize-json';
|
||||
import { colorize } from './theme';
|
||||
export { error } from '../errors/error';
|
||||
export { exit } from '../errors/exit';
|
||||
export { warn } from '../errors/warn';
|
||||
export { default as colorizeJson } from './colorize-json';
|
||||
export { colorize } from './theme';
|
||||
export { stderr, stdout } from './write';
|
||||
export declare const action: Simple | Spinner;
|
||||
export declare const ux: {
|
||||
action: Simple | Spinner;
|
||||
/**
|
||||
* Add color to text.
|
||||
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
|
||||
* @param text string to colorize
|
||||
* @returns colorized string
|
||||
*/
|
||||
colorize: typeof colorize;
|
||||
/**
|
||||
* Add color to JSON.
|
||||
*
|
||||
* options
|
||||
* pretty: set to true to pretty print the JSON (defaults to true)
|
||||
* theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
|
||||
*
|
||||
* Available theme keys:
|
||||
* - brace
|
||||
* - bracket
|
||||
* - colon
|
||||
* - comma
|
||||
* - key
|
||||
* - string
|
||||
* - number
|
||||
* - boolean
|
||||
* - null
|
||||
*/
|
||||
colorizeJson: typeof colorizeJson;
|
||||
/**
|
||||
* Throw an error.
|
||||
*
|
||||
* If `exit` option is `false`, the error will be logged to stderr but not exit the process.
|
||||
* If `exit` is set to a number, the process will exit with that code.
|
||||
*/
|
||||
error: typeof error;
|
||||
/**
|
||||
* Exit the process with provided exit code (defaults to 0).
|
||||
*/
|
||||
exit: typeof exit;
|
||||
/**
|
||||
* Log a formatted string to stderr.
|
||||
*
|
||||
* See node's util.format() for formatting options.
|
||||
*/
|
||||
stderr: (str?: string | string[] | undefined, ...args: string[]) => void;
|
||||
/**
|
||||
* Log a formatted string to stdout.
|
||||
*
|
||||
* See node's util.format() for formatting options.
|
||||
*/
|
||||
stdout: (str?: string | string[] | undefined, ...args: string[]) => void;
|
||||
/**
|
||||
* Prints a pretty warning message to stderr.
|
||||
*/
|
||||
warn: typeof warn;
|
||||
};
|
||||
89
node_modules/@oclif/core/lib/ux/index.js
generated
vendored
Normal file
89
node_modules/@oclif/core/lib/ux/index.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ux = exports.action = exports.stdout = exports.stderr = exports.colorize = exports.colorizeJson = exports.warn = exports.exit = exports.error = void 0;
|
||||
const error_1 = require("../errors/error");
|
||||
const exit_1 = require("../errors/exit");
|
||||
const warn_1 = require("../errors/warn");
|
||||
const simple_1 = __importDefault(require("./action/simple"));
|
||||
const spinner_1 = __importDefault(require("./action/spinner"));
|
||||
const colorize_json_1 = __importDefault(require("./colorize-json"));
|
||||
const theme_1 = require("./theme");
|
||||
const write_1 = require("./write");
|
||||
var error_2 = require("../errors/error");
|
||||
Object.defineProperty(exports, "error", { enumerable: true, get: function () { return error_2.error; } });
|
||||
var exit_2 = require("../errors/exit");
|
||||
Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_2.exit; } });
|
||||
var warn_2 = require("../errors/warn");
|
||||
Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return warn_2.warn; } });
|
||||
var colorize_json_2 = require("./colorize-json");
|
||||
Object.defineProperty(exports, "colorizeJson", { enumerable: true, get: function () { return __importDefault(colorize_json_2).default; } });
|
||||
var theme_2 = require("./theme");
|
||||
Object.defineProperty(exports, "colorize", { enumerable: true, get: function () { return theme_2.colorize; } });
|
||||
var write_2 = require("./write");
|
||||
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return write_2.stderr; } });
|
||||
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return write_2.stdout; } });
|
||||
const ACTION_TYPE = (Boolean(process.stderr.isTTY) &&
|
||||
!process.env.CI &&
|
||||
!['dumb', 'emacs-color'].includes(process.env.TERM) &&
|
||||
'spinner') ||
|
||||
'simple';
|
||||
exports.action = ACTION_TYPE === 'spinner' ? new spinner_1.default() : new simple_1.default();
|
||||
exports.ux = {
|
||||
action: exports.action,
|
||||
/**
|
||||
* Add color to text.
|
||||
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
|
||||
* @param text string to colorize
|
||||
* @returns colorized string
|
||||
*/
|
||||
colorize: theme_1.colorize,
|
||||
/**
|
||||
* Add color to JSON.
|
||||
*
|
||||
* options
|
||||
* pretty: set to true to pretty print the JSON (defaults to true)
|
||||
* theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
|
||||
*
|
||||
* Available theme keys:
|
||||
* - brace
|
||||
* - bracket
|
||||
* - colon
|
||||
* - comma
|
||||
* - key
|
||||
* - string
|
||||
* - number
|
||||
* - boolean
|
||||
* - null
|
||||
*/
|
||||
colorizeJson: colorize_json_1.default,
|
||||
/**
|
||||
* Throw an error.
|
||||
*
|
||||
* If `exit` option is `false`, the error will be logged to stderr but not exit the process.
|
||||
* If `exit` is set to a number, the process will exit with that code.
|
||||
*/
|
||||
error: error_1.error,
|
||||
/**
|
||||
* Exit the process with provided exit code (defaults to 0).
|
||||
*/
|
||||
exit: exit_1.exit,
|
||||
/**
|
||||
* Log a formatted string to stderr.
|
||||
*
|
||||
* See node's util.format() for formatting options.
|
||||
*/
|
||||
stderr: write_1.stderr,
|
||||
/**
|
||||
* Log a formatted string to stdout.
|
||||
*
|
||||
* See node's util.format() for formatting options.
|
||||
*/
|
||||
stdout: write_1.stdout,
|
||||
/**
|
||||
* Prints a pretty warning message to stderr.
|
||||
*/
|
||||
warn: warn_1.warn,
|
||||
};
|
||||
3
node_modules/@oclif/core/lib/ux/list.d.ts
generated
vendored
Normal file
3
node_modules/@oclif/core/lib/ux/list.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export type IListItem = [string, string | undefined];
|
||||
export type IList = IListItem[];
|
||||
export default function renderList(items: IListItem[]): string;
|
||||
28
node_modules/@oclif/core/lib/ux/list.js
generated
vendored
Normal file
28
node_modules/@oclif/core/lib/ux/list.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = renderList;
|
||||
const wordwrap = require('wordwrap');
|
||||
const screen_1 = require("../screen");
|
||||
const util_1 = require("../util/util");
|
||||
function linewrap(length, s) {
|
||||
return wordwrap(length, screen_1.stdtermwidth, {
|
||||
skipScheme: 'ansi-color',
|
||||
})(s).trim();
|
||||
}
|
||||
function renderList(items) {
|
||||
if (items.length === 0) {
|
||||
return '';
|
||||
}
|
||||
const maxLength = (0, util_1.maxBy)(items, (item) => item[0].length)?.[0].length ?? 0;
|
||||
const lines = items.map((i) => {
|
||||
let left = i[0];
|
||||
let right = i[1];
|
||||
if (!right) {
|
||||
return left;
|
||||
}
|
||||
left = left.padEnd(maxLength);
|
||||
right = linewrap(maxLength + 2, right);
|
||||
return `${left} ${right}`;
|
||||
});
|
||||
return lines.join('\n');
|
||||
}
|
||||
1
node_modules/@oclif/core/lib/ux/supports-color.d.ts
generated
vendored
Normal file
1
node_modules/@oclif/core/lib/ux/supports-color.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function supportsColor(): boolean;
|
||||
7
node_modules/@oclif/core/lib/ux/supports-color.js
generated
vendored
Normal file
7
node_modules/@oclif/core/lib/ux/supports-color.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.supportsColor = supportsColor;
|
||||
const supports_color_1 = require("supports-color");
|
||||
function supportsColor() {
|
||||
return Boolean(supports_color_1.stdout) && Boolean(supports_color_1.stderr);
|
||||
}
|
||||
9
node_modules/@oclif/core/lib/ux/theme.d.ts
generated
vendored
Normal file
9
node_modules/@oclif/core/lib/ux/theme.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { StandardAnsi, Theme } from '../interfaces/theme';
|
||||
/**
|
||||
* Add color to text.
|
||||
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
|
||||
* @param text string to colorize
|
||||
* @returns colorized string
|
||||
*/
|
||||
export declare function colorize(color: string | StandardAnsi | undefined, text: string): string;
|
||||
export declare function parseTheme(theme: Record<string, string | Record<string, string>>): Theme;
|
||||
45
node_modules/@oclif/core/lib/ux/theme.js
generated
vendored
Normal file
45
node_modules/@oclif/core/lib/ux/theme.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.colorize = colorize;
|
||||
exports.parseTheme = parseTheme;
|
||||
const ansis_1 = __importDefault(require("ansis"));
|
||||
const theme_1 = require("../interfaces/theme");
|
||||
const supports_color_1 = require("./supports-color");
|
||||
function isStandardAnsi(color) {
|
||||
return theme_1.STANDARD_ANSI.includes(color);
|
||||
}
|
||||
/**
|
||||
* Add color to text.
|
||||
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
|
||||
* @param text string to colorize
|
||||
* @returns colorized string
|
||||
*/
|
||||
function colorize(color, text) {
|
||||
if (!color)
|
||||
return text;
|
||||
if (!(0, supports_color_1.supportsColor)())
|
||||
return text;
|
||||
if (isStandardAnsi(color))
|
||||
return ansis_1.default[color](text);
|
||||
if (color.startsWith('#'))
|
||||
return ansis_1.default.hex(color)(text);
|
||||
if (color.startsWith('rgb')) {
|
||||
const [red, green, blue] = color
|
||||
.slice(4, -1)
|
||||
.split(',')
|
||||
.map((c) => Number.parseInt(c.trim(), 10));
|
||||
return ansis_1.default.rgb(red, green, blue)(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
function parseTheme(theme) {
|
||||
return Object.fromEntries(Object.entries(theme)
|
||||
.map(([key, value]) => [key, typeof value === 'string' ? isValid(value) : parseTheme(value)])
|
||||
.filter(([_, value]) => value));
|
||||
}
|
||||
function isValid(color) {
|
||||
return color.startsWith('#') || color.startsWith('rgb') || isStandardAnsi(color) ? color : undefined;
|
||||
}
|
||||
2
node_modules/@oclif/core/lib/ux/write.d.ts
generated
vendored
Normal file
2
node_modules/@oclif/core/lib/ux/write.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare const stdout: (str?: string | string[] | undefined, ...args: string[]) => void;
|
||||
export declare const stderr: (str?: string | string[] | undefined, ...args: string[]) => void;
|
||||
34
node_modules/@oclif/core/lib/ux/write.js
generated
vendored
Normal file
34
node_modules/@oclif/core/lib/ux/write.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.stderr = exports.stdout = void 0;
|
||||
const node_util_1 = require("node:util");
|
||||
const stdout = (str, ...args) => {
|
||||
if (!str && args) {
|
||||
console.log((0, node_util_1.format)(...args));
|
||||
}
|
||||
else if (!str) {
|
||||
console.log();
|
||||
}
|
||||
else if (typeof str === 'string') {
|
||||
console.log((0, node_util_1.format)(str, ...args));
|
||||
}
|
||||
else {
|
||||
console.log((0, node_util_1.format)(...str, ...args));
|
||||
}
|
||||
};
|
||||
exports.stdout = stdout;
|
||||
const stderr = (str, ...args) => {
|
||||
if (!str && args) {
|
||||
console.error((0, node_util_1.format)(...args));
|
||||
}
|
||||
else if (!str) {
|
||||
console.error();
|
||||
}
|
||||
else if (typeof str === 'string') {
|
||||
console.error((0, node_util_1.format)(str, ...args));
|
||||
}
|
||||
else {
|
||||
console.error((0, node_util_1.format)(...str, ...args));
|
||||
}
|
||||
};
|
||||
exports.stderr = stderr;
|
||||
Reference in New Issue
Block a user