UNPKG

@rawcmd/typewriters

Version:

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

44 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("@rawcmd/utils"); const text_1 = require("@rawcmd/text"); function textTypewriter(options) { options = Object.assign({}, options); return (value) => { try { value = utils_1.toString(value) || ''; value = applyStyle(value, options); return value; } catch (e) { return ''; } }; } exports.textTypewriter = textTypewriter; function applyStyle(value, options) { const styles = []; if (options.reset) { styles.push(text_1.ANSI_CODES[text_1.TextStyle.RESET]); } if (options.bold) { styles.push(text_1.ANSI_CODES[text_1.TextStyle.BOLD]); } if (options.dim) { styles.push(text_1.ANSI_CODES[text_1.TextStyle.DIM]); } if (options.underline) { styles.push(text_1.ANSI_CODES[text_1.TextStyle.UNDERLINE]); } if (options.inverse) { styles.push(text_1.ANSI_CODES[text_1.TextStyle.INVERSE]); } if (options.color) { styles.push(text_1.ANSI_CODES[options.color]); } if (options.background) { styles.push(text_1.ANSI_CODES[options.background]); } return text_1.repairAnsi(`${styles.filter((s) => !!s).map((s) => s[0]).join('')}${value}`).join(''); } //# sourceMappingURL=text.js.map