zcatalyst-cli
Version:
Command Line Tool for CATALYST
67 lines (66 loc) • 2.81 kB
JavaScript
;
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _a, _LogStreamFactory_logStream;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogStreamFactory = exports.TTYPassThrough = exports.CHAR = void 0;
const ansi_colors_1 = require("ansi-colors");
const env_js_1 = require("../env.js");
const readline_1 = require("readline");
const stream_1 = require("stream");
const option_1 = require("../option");
const isSupported = !env_js_1.isWindows || process.env.CI || process.env.TERM === 'xterm-256color';
exports.CHAR = {
success: isSupported ? ansi_colors_1.bold.green('✔') : ansi_colors_1.bold.green('√'),
warning: isSupported ? ansi_colors_1.bold.yellow('⚠') : ansi_colors_1.bold.yellow('‼'),
info: isSupported ? ansi_colors_1.bold.cyan('ℹ') : ansi_colors_1.bold.cyan('i'),
error: isSupported ? ansi_colors_1.bold.red('✖') : ansi_colors_1.bold.red('×')
};
class TTYPassThrough extends stream_1.PassThrough {
constructor() {
super(...arguments);
this.columns = process.stdout.columns;
this.rows = process.stdout.rows;
this.isTTY = true;
}
_write(chunk, encoding, callback) {
chunk = Buffer.from(JSON.stringify({
data: chunk.toString(),
command: (0, option_1.getCurrentCommand)()
}));
super._write(chunk, encoding, callback);
}
clearLine(dir, callback) {
return (0, readline_1.clearLine)(this, dir, callback);
}
clearScreenDown(callback) {
return (0, readline_1.clearScreenDown)(this, callback);
}
cursorTo(x, y, callback) {
return (0, readline_1.cursorTo)(this, x, y, callback);
}
moveCursor(dx, dy, callback) {
return (0, readline_1.moveCursor)(this, dx, dy, callback);
}
getColorDepth(env) {
return process.stdout.getColorDepth(env);
}
hasColors(count, env) {
return process.stdout.hasColors(count, env);
}
getWindowSize() {
return process.stdout.getWindowSize();
}
}
exports.TTYPassThrough = TTYPassThrough;
class LogStreamFactory {
static getStream() {
return __classPrivateFieldGet(LogStreamFactory, _a, "f", _LogStreamFactory_logStream);
}
}
exports.LogStreamFactory = LogStreamFactory;
_a = LogStreamFactory;
_LogStreamFactory_logStream = { value: new TTYPassThrough() };