UNPKG

@kya-os/cli

Version:

CLI for KYA-OS MCP-I setup and management

146 lines 4.72 kB
/** * Message Components * Reusable components for displaying various types of messages */ import chalk from "chalk"; import { createBox } from "./box.js"; /** * Create a success message */ export function createSuccessMessage(message, options = {}) { const { title = "Success", icon = "✅", color = "00ff00", boxStyle = "round", width = 60, } = options; return createBox(`${icon} ${message}`, { title, style: boxStyle, borderColor: color, width, padding: 1, align: "center", }); } /** * Create an error message */ export function createErrorMessage(message, options = {}) { const { title = "Error", icon = "❌", color = "ff0000", boxStyle = "double", width = 60, } = options; return createBox(chalk.red(`${icon} ${message}`), { title: chalk.red(title), style: boxStyle, borderColor: color, width, padding: 1, }); } /** * Create a warning message */ export function createWarningMessage(message, options = {}) { const { title = "Warning", icon = "⚠️", color = "ffff00", boxStyle = "single", width = 60, } = options; return createBox(chalk.yellow(`${icon} ${message}`), { title: chalk.yellow(title), style: boxStyle, borderColor: color, width, padding: 1, }); } /** * Create an info message */ export function createInfoMessage(message, options = {}) { const { title = "Info", icon = "ℹ️", color = "00ffff", boxStyle = "single", width = 60, } = options; return createBox(chalk.cyan(`${icon} ${message}`), { title: chalk.cyan(title), style: boxStyle, borderColor: color, width, padding: 1, }); } /** * Create a step indicator */ export function createStepIndicator(currentStep, totalSteps, stepName, status = "active") { const icons = { pending: "○", active: "◉", completed: "✓", failed: "✗", }; const colors = { pending: chalk.gray, active: chalk.cyan, completed: chalk.green, failed: chalk.red, }; const icon = icons[status]; const colorFn = colors[status]; const progress = `[${currentStep}/${totalSteps}]`; return colorFn(`${icon} ${progress} ${stepName}`); } /** * Create a progress bar */ export function createProgressBar(current, total, width = 30, options = {}) { const { showPercentage = true, showNumbers = true } = options; const percentage = Math.round((current / total) * 100); const filled = Math.round((current / total) * width); const empty = width - filled; const bar = chalk.green("█".repeat(filled)) + chalk.gray("░".repeat(empty)); let result = `[${bar}]`; if (showPercentage) { result += ` ${percentage}%`; } if (showNumbers) { result += ` (${current}/${total})`; } return result; } /** * Create a list of items with bullets */ export function createBulletList(items, options = {}) { const { bullet = "•", indent = 2, color } = options; const colorFn = color ? chalk.hex(color) : (s) => s; const indentStr = " ".repeat(indent); return items .map((item) => `${indentStr}${colorFn(bullet)} ${item}`) .join("\n"); } /** * Create a numbered list */ export function createNumberedList(items, options = {}) { const { startNumber = 1, indent = 2, color } = options; const colorFn = color ? chalk.hex(color) : (s) => s; const indentStr = " ".repeat(indent); return items .map((item, index) => `${indentStr}${colorFn(`${startNumber + index}.`)} ${item}`) .join("\n"); } /** * Create a key-value display */ export function createKeyValueDisplay(data, options = {}) { const { separator = ": ", keyColor = "00ff00", valueColor = "ffffff", maxKeyLength, } = options; const keyColorFn = chalk.hex(keyColor); const valueColorFn = chalk.hex(valueColor); // Calculate max key length if not provided const actualMaxKeyLength = maxKeyLength || Math.max(...Object.keys(data).map((k) => k.length)); return Object.entries(data) .filter(([_, value]) => value !== undefined) .map(([key, value]) => { const paddedKey = key.padEnd(actualMaxKeyLength); return `${keyColorFn(paddedKey)}${separator}${valueColorFn(value)}`; }) .join("\n"); } /** * Create a spinner with text (static version for display) */ export function createSpinner(text, frame = 0) { const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; const spinner = chalk.cyan(frames[frame % frames.length]); return `${spinner} ${text}`; } //# sourceMappingURL=messages.js.map