UNPKG

@rawcmd/typewriters

Version:

Collection of typewriters for styling command-line messages for Rawcmd.

41 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@rawcmd/core"); const title_1 = require("./title"); const row_1 = require("./row"); function usageTypewriter(options) { options = Object.assign({ title: 'Usage', totalWidth: 80 }, options); const writeTitle = title_1.titleTypewriter(options); const writeBody = row_1.rowTypewriter([ { index: 0, width: options.totalWidth, }, ]); return (command) => { if (!command) { return ''; } const lines = [ [ '$', ...command.getAncestors().map((a) => a.name), command.name, '<COMMAND>', ].filter((v) => !!v).join(' '), [ '$', ...command.getAncestors().map((a) => a.name), command.name, '<OPTION>', ].filter((v) => !!v).join(' '), ]; const titleOutput = writeTitle(options.title); const bodyOutput = lines.map((line) => { return writeBody([line]); }).join(core_1.EOL); return [titleOutput, bodyOutput].filter((o) => !!o).join(core_1.EOL); }; } exports.usageTypewriter = usageTypewriter; //# sourceMappingURL=usage.js.map