UNPKG

symfony-style-console

Version:

Use the style and utilities of the Symfony Console in Node.js

151 lines (150 loc) 4.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var env_1 = require("../env"); var ConsoleOutput_1 = require("../Output/ConsoleOutput"); var OutputInterface_1 = require("../Output/OutputInterface"); var ProgressBar_1 = require("../Helper/ProgressBar"); /** * Decorates output to add console style guide helpers. * * @author Kevin Bond <kevinbond@gmail.com> * * Original PHP class * * @author Florian Reuschel <florian@loilo.de> * * Port to TypeScript */ var OutputStyle = /** @class */ (function () { /** * Create an OutputStyle instance. * * @param output The output to style */ function OutputStyle(output) { if (output === void 0) { output = new ConsoleOutput_1.default(); } this.output = output; } /** * Add newline(s). * * @param number count The number of newlines */ OutputStyle.prototype.newLine = function (count) { if (count === void 0) { count = 1; } this.output.write(env_1.EOL.repeat(count)); }; /** * @param number max * * @return ProgressBar */ OutputStyle.prototype.createProgressBar = function (max) { if (max === void 0) { max = 0; } return new ProgressBar_1.default(this.output, max); }; /** * Writes a message to the output. * * @param messages The message as an array of lines or a single string * @param newline Whether to add a newline * @param type A bitmask of options (one of the OUTPUT or VERBOSITY constants), * 0 is considered the same as OUTPUT_NORMAL | VERBOSITY_NORMAL */ OutputStyle.prototype.write = function (messages, newline, type) { if (newline === void 0) { newline = false; } if (type === void 0) { type = OutputInterface_1.OUTPUT_NORMAL; } this.output.write(messages, newline, type); }; /** * Writes a message to the output and adds a newline at the end. * * @param messages The message as an array of lines of a single string * @param type A bitmask of options (one of the OUTPUT or VERBOSITY constants), * 0 is considered the same as OUTPUT_NORMAL | VERBOSITY_NORMAL */ OutputStyle.prototype.writeln = function (messages, type) { if (type === void 0) { type = OutputInterface_1.OUTPUT_NORMAL; } this.output.write(messages, true, type); }; /** * Sets the verbosity of the output. * * @param level The level of verbosity (one of the [[VERBOSITY_LEVEL]] constants) */ OutputStyle.prototype.setVerbosity = function (level) { this.output.setVerbosity(level); }; /** * Gets the current verbosity of the output. * * @return number The current level of verbosity (one of the [[VERBOSITY_LEVEL]] constants) */ OutputStyle.prototype.getVerbosity = function () { return this.output.getVerbosity(); }; /** * Sets the decorated flag. * * @param decorated Whether to decorate the messages */ OutputStyle.prototype.setDecorated = function (decorated) { this.output.setDecorated(decorated); }; /** * Gets the decorated flag. * * @return True if the output will decorate messages, false otherwise */ OutputStyle.prototype.isDecorated = function () { return this.output.isDecorated(); }; /** * Sets output formatter. * * @param The formatter to use */ OutputStyle.prototype.setFormatter = function (formatter) { this.output.setFormatter(formatter); }; /** * Returns current output formatter instance. */ OutputStyle.prototype.getFormatter = function () { return this.output.getFormatter(); }; /** * Returns whether verbosity is quiet (-q). * * @return True if verbosity is set to [[VERBOSITY_QUIET]], false otherwise */ OutputStyle.prototype.isQuiet = function () { return this.output.isQuiet(); }; /** * Returns whether verbosity is verbose (-v). * * @return True if verbosity is set to [[VERBOSITY_VERBOSE]], false otherwise */ OutputStyle.prototype.isVerbose = function () { return this.output.isVerbose(); }; /** * Returns whether verbosity is very verbose (-vv). * * @return True if verbosity is set to [[VERBOSITY_VERY_VERBOSE]], false otherwise */ OutputStyle.prototype.isVeryVerbose = function () { return this.output.isVeryVerbose(); }; /** * Returns whether verbosity is debug (-vvv). * * @return True if verbosity is set to [[VERBOSITY_DEBUG]], false otherwise */ OutputStyle.prototype.isDebug = function () { return this.output.isDebug(); }; return OutputStyle; }()); exports.default = OutputStyle;