UNPKG

@rawcmd/typewriters

Version:

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

38 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@rawcmd/core"); const utils_1 = require("@rawcmd/utils"); const text_1 = require("./text"); const row_1 = require("./row"); function contentsTypewriter(options) { options = Object.assign({ paddingWidth: 5, totalWidth: 80 }, options); const writeDot = text_1.textTypewriter({ dim: true, }); return (lines) => { if (!utils_1.isArray(lines) || lines.length <= 0) { return ''; } const nameSize = Math.max(...lines.map((line) => line[0].length)); const bodyTypewriter = row_1.rowTypewriter([ { index: 0, width: nameSize + options.paddingWidth + 1, }, { index: 1, width: options.totalWidth - nameSize - options.paddingWidth - 1, }, ]); const dotOutput = writeDot('.'); const bodyOutput = lines.map((line) => { return bodyTypewriter([ `${line[0]} ${dotOutput.repeat(nameSize - line[0].length + options.paddingWidth)}`, line[1], ]); }).join(core_1.EOL); return bodyOutput; }; } exports.contentsTypewriter = contentsTypewriter; //# sourceMappingURL=contents.js.map