export class VisualFormatter { /** * Create a box header with title and emoji */ static createBoxHeader(title: string, emoji: string = '', width: number = 41): string { const fullTitle = emoji ? `${emoji} ${title}` : title; const padding = Math.max(0, width - fullTitle.length - 2); const topLine = '┌' + '─'.repeat(width) + '┐'; const titleLine = `│ ${fullTitle}${' '.repeat(padding)}│`; const bottomLine = '└' + '─'.repeat(width) + '┘'; return `${topLine}\n${titleLine}\n${bottomLine}`; } /** * Create a tree structure for hierarchical data */ static createTree(items: Array<{ id: string; title: string; description?: string; status?: string; children?: Array; }>): string { let result = ''; items.forEach((item, index) => { const isLastItem = index === items.length - 1; const prefix = isLastItem ? '└─ ' : '├─ '; const checkbox = item.status === 'completed' ? '[x]' : '[ ]'; const statusEmoji = this.getStatusEmoji(item.status); // Main item line result += `${prefix}${checkbox} ${item.id} ${item.title} ${statusEmoji}\n`; // Add description if exists if (item.description) { const descPrefix = isLastItem ? ' ' : '│ '; result += `${descPrefix} ${item.description}\n`; } // Add children recursively if (item.children && item.children.length > 0) { const childPrefix = isLastItem ? ' ' : '│ '; result += this.createTreeWithPrefix(item.children, childPrefix); } // Add spacing between main items if (!isLastItem) { result += '│\n'; } }); return result; } /** * Create a tree structure with custom prefix */ private static createTreeWithPrefix(items: Array, prefix: string): string { let result = ''; items.forEach((item, index) => { const isLastItem = index === items.length - 1; const treePrefix = isLastItem ? '└─ ' : '├─ '; const checkbox = item.status === 'completed' ? '[x]' : '[ ]'; const statusEmoji = this.getStatusEmoji(item.status); result += `${prefix}${treePrefix}${checkbox} ${item.id} ${item.title} ${statusEmoji}\n`; if (item.description) { result += `${prefix} ${item.description}\n`; } if (item.children && item.children.length > 0) { const childPrefix = isLastItem ? `${prefix} ` : `${prefix}│ `; result += this.createTreeWithPrefix(item.children, childPrefix); } }); return result; } /** * Create a hierarchical list with tree structure */ static createHierarchicalList(items: Array<{ title: string; items?: Array; children?: Array; }>): string { let result = ''; items.forEach((item, index) => { const isLast = index === items.length - 1; const prefix = isLast ? '└─ ' : '├─ '; result += `${prefix}${item.title}\n`; // Add sub-items if (item.items && item.items.length > 0) { item.items.forEach((subItem, subIndex) => { const isLastSub = subIndex === item.items!.length - 1; const subPrefix = isLast ? ' ' : '│ '; const subTreePrefix = isLastSub ? '└─ ' : '├─ '; result += `${subPrefix}${subTreePrefix}${subItem}\n`; }); } // Add children recursively if (item.children && item.children.length > 0) { const childPrefix = isLast ? ' ' : '│ '; result += this.createHierarchicalListWithPrefix(item.children, childPrefix); } // Add spacing between main items if (!isLast) { result += '│\n'; } }); return result; } /** * Create hierarchical list with custom prefix */ private static createHierarchicalListWithPrefix(items: Array, prefix: string): string { let result = ''; items.forEach((item, index) => { const isLast = index === items.length - 1; const treePrefix = isLast ? '└─ ' : '├─ '; result += `${prefix}${treePrefix}${item.title}\n`; if (item.items && item.items.length > 0) { item.items.forEach((subItem: string, subIndex: number) => { const isLastSub = subIndex === item.items!.length - 1; const subPrefix = isLast ? `${prefix} ` : `${prefix}│ `; const subTreePrefix = isLastSub ? '└─ ' : '├─ '; result += `${subPrefix}${subTreePrefix}${subItem}\n`; }); } if (item.children && item.children.length > 0) { const childPrefix = isLast ? `${prefix} ` : `${prefix}│ `; result += this.createHierarchicalListWithPrefix(item.children, childPrefix); } }); return result; } /** * Create a data model structure */ static createDataModel(name: string, fields: Array<{name: string, type: string}>): string { let result = `${name} {\n`; fields.forEach((field, index) => { const isLast = index === fields.length - 1; const prefix = isLast ? '└─ ' : '├─ '; result += ` ${prefix}${field.name}: ${field.type}\n`; }); result += '}'; return result; } /** * Create API endpoints structure */ static createAPIEndpoints(endpoints: Array<{method: string, path: string, description: string}>): string { let result = ''; endpoints.forEach((endpoint, index) => { const isLast = index === endpoints.length - 1; const prefix = isLast ? '└─ ' : '├─ '; result += `${prefix}${endpoint.method} ${endpoint.path}\n`; result += ` └─ ${endpoint.description}\n`; }); return result; } /** * Create technology stack visualization */ static createTechStack(frontend: string[], backend: string[], database: string[]): string { const maxLength = Math.max(frontend.length, backend.length, database.length); let result = ''; // Headers result += 'Frontend Backend Database\n'; for (let i = 0; i < maxLength; i++) { const frontendItem = frontend[i] || ''; const backendItem = backend[i] || ''; const databaseItem = database[i] || ''; const isLast = i === maxLength - 1; const prefix = isLast ? '└─ ' : '├─ '; result += `${prefix}${frontendItem.padEnd(15)} ${prefix}${backendItem.padEnd(15)} ${prefix}${databaseItem}\n`; } return result; } /** * Create status indicators */ static createStatusIndicators(items: Array<{name: string, status: boolean}>): string { let result = ''; items.forEach((item, index) => { const isLast = index === items.length - 1; const prefix = isLast ? '└─ ' : '├─ '; const statusIcon = item.status ? '[✅]' : '[⏳]'; const statusText = item.status ? 'Complete' : 'Pending'; result += `${prefix}${item.name.padEnd(15)} ${statusIcon} ${statusText}\n`; }); return result; } /** * Create timeline visualization */ static createTimeline(created: string, updated: string): string { const arrow = '──────────►'; return `Created: ${created} ${arrow} Updated: ${updated}`; } /** * Create EARS suggestions in compact format */ static createEARSSuggestions(suggestions: Array<{ original: string; earsFormat: string; confidence: number; type: string; }>): string { let result = ''; suggestions.forEach((suggestion, index) => { const isLast = index === suggestions.length - 1; const prefix = isLast ? '└─ ' : '├─ '; const confidenceEmoji = this.getConfidenceEmoji(suggestion.confidence); result += `${prefix}${suggestion.original}\n`; result += ` → ${suggestion.earsFormat}\n`; result += ` ${confidenceEmoji} ${Math.round(suggestion.confidence * 100)}% (${suggestion.type})\n`; if (!isLast) { result += '\n'; } }); return result; } /** * Get status emoji based on status */ private static getStatusEmoji(status?: string): string { switch (status) { case 'completed': return '✅'; case 'in-progress': return '🔄'; case 'pending': return '⏳'; default: return '📋'; } } /** * Get confidence emoji based on confidence level */ private static getConfidenceEmoji(confidence: number): string { if (confidence >= 0.8) return '🟢'; if (confidence >= 0.6) return '🟡'; return '🔴'; } /** * Create a simple box around content */ static createSimpleBox(content: string, width: number = 41): string { const lines = content.split('\n'); const maxWidth = Math.max(...lines.map(line => line.length), width); const topLine = '┌' + '─'.repeat(maxWidth) + '┐'; const bottomLine = '└' + '─'.repeat(maxWidth) + '┘'; let result = topLine + '\n'; lines.forEach(line => { const paddedLine = line.padEnd(maxWidth); result += `│${paddedLine}│\n`; }); result += bottomLine; return result; } /** * Create a section separator */ static createSectionSeparator(): string { return '\n' + '─'.repeat(50) + '\n'; } }