UNPKG

plazbot-cli

Version:
112 lines (111 loc) 4.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.theme = void 0; exports.createSpinner = createSpinner; exports.createTable = createTable; exports.box = box; exports.formatDate = formatDate; exports.statusBadge = statusBadge; exports.kvPair = kvPair; exports.section = section; exports.progressBar = progressBar; const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const cli_table3_1 = __importDefault(require("cli-table3")); // Colores del tema Plazbot exports.theme = { primary: chalk_1.default.hex('#4CAF50'), secondary: chalk_1.default.hex('#2196F3'), accent: chalk_1.default.hex('#FFA726'), success: chalk_1.default.hex('#66BB6A'), error: chalk_1.default.hex('#EF5350'), warning: chalk_1.default.hex('#FFA726'), muted: chalk_1.default.gray, bold: chalk_1.default.bold, dim: chalk_1.default.dim, }; // Spinner function createSpinner(text) { return (0, ora_1.default)({ text: exports.theme.muted(text), spinner: 'dots', color: 'green', }); } // Tabla formateada function createTable(headers, rows) { const table = new cli_table3_1.default({ head: headers.map(h => exports.theme.bold.hex('#4CAF50')(h)), style: { head: [], border: ['gray'], }, chars: { 'top': '─', 'top-mid': '┬', 'top-left': '┌', 'top-right': '┐', 'bottom': '─', 'bottom-mid': '┴', 'bottom-left': '└', 'bottom-right': '┘', 'left': '│', 'left-mid': '├', 'mid': '─', 'mid-mid': '┼', 'right': '│', 'right-mid': '┤', 'middle': '│' } }); rows.forEach(row => table.push(row)); return table.toString(); } // Box simple function box(content, title) { const lines = content.split('\n'); const maxLen = Math.max(...lines.map(l => stripAnsi(l).length), title ? stripAnsi(title).length + 4 : 0); const width = maxLen + 4; let result = ''; if (title) { result += exports.theme.muted(' ┌─ ') + exports.theme.primary(title) + exports.theme.muted(' ' + '─'.repeat(Math.max(0, width - stripAnsi(title).length - 5))) + exports.theme.muted('┐') + '\n'; } else { result += exports.theme.muted(' ┌' + '─'.repeat(width) + '┐') + '\n'; } for (const line of lines) { const pad = ' '.repeat(Math.max(0, maxLen - stripAnsi(line).length)); result += exports.theme.muted(' │') + ' ' + line + pad + ' ' + exports.theme.muted('│') + '\n'; } result += exports.theme.muted(' └' + '─'.repeat(width) + '┘'); return result; } // Strip ANSI codes para calcular longitud real function stripAnsi(str) { return str.replace(/\x1b\[[0-9;]*m/g, ''); } // Formato de fecha legible function formatDate(date) { const d = new Date(date); return d.toLocaleDateString('es-ES', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); } // Status badge function statusBadge(enabled) { return enabled ? exports.theme.success('● activo') : exports.theme.error('○ inactivo'); } // Key-value pair formateado function kvPair(key, value) { return ` ${exports.theme.muted(key + ':')} ${value}`; } // Sección con título function section(title) { return '\n' + exports.theme.bold.hex('#4CAF50')(` ${title}`) + '\n' + exports.theme.muted(' ' + '─'.repeat(40)); } // Progress bar simple function progressBar(current, total, width = 30) { const percent = Math.round((current / total) * 100); const filled = Math.round((current / total) * width); const empty = width - filled; const bar = exports.theme.success('█'.repeat(filled)) + exports.theme.muted('░'.repeat(empty)); return `${bar} ${exports.theme.bold(percent + '%')} (${current}/${total})`; }