UNPKG

@trap_stevo/terminal-plus

Version:

Transform your CLI into a visually striking, feature-rich command layer. Blend animated gradients, stylish badges, dynamic progress bars, sleek tables, and precise formatting utilities — all turning terminal output into a powerful visual experience.

43 lines (42 loc) 1.59 kB
"use strict"; const GraphemeSplitter = require("grapheme-splitter"); class TerminalBadge { static get(label, options = {}, colorEngine) { const splitter = new GraphemeSplitter(); const { icon = null, padding = 1, backgroundColor = "#6c63ff", textColor = "#ffffff", gradient = null, type = "sleek", inline = true } = options; const chalk = colorEngine.chalk; let content = " ".repeat(padding) + (icon ? icon + " " : "") + label + " ".repeat(padding); let colored = ""; const graphemes = splitter.splitGraphemes(content); if (gradient && gradient.length >= 2) { const bgGradient = colorEngine.generateGradientColors(gradient, graphemes.length); for (let i = 0; i < graphemes.length; i++) { const [r, g, b] = bgGradient[i]; colored += chalk.bgRgb(r, g, b).hex(textColor)(graphemes[i]); } } else { colored = chalk.bgHex(backgroundColor).hex(textColor)(content); } let rightWrapper = ""; let leftWrapper = ""; if (type && type !== "none") { rightWrapper = type === "sci-fi" ? "::" : type === "sleek" ? "|" : type === "rounded" ? "⟧" : "]"; leftWrapper = type === "sci-fi" ? "::" : type === "sleek" ? "|" : type === "rounded" ? "⟦" : "["; } return inline ? `${leftWrapper}${colored}${rightWrapper}` : `\n${leftWrapper}${colored}${rightWrapper}\n`; } static print(label, options = {}, colorEngine) { const badge = TerminalBadge.get(label, options, colorEngine); console.log(badge); } } ; module.exports = TerminalBadge;