import chalk from 'chalk'; import { sanitizeTerminalText } from './terminal'; /** * Render the OPML import preview shown by `import opml`. */ export function formatOpmlImportResult(result: { title?: string; feeds: Array<{ title: string; xmlUrl: string; category?: string }>; errors: Array<{ outline: string; error: string }>; totalOutlines: number; validFeeds: number; }): string { const lines: string[] = []; lines.push(''); if (result.title) { lines.push(chalk.bold.cyan(`OPML: ${sanitizeTerminalText(result.title)}`)); } else { lines.push(chalk.bold.cyan('OPML Import')); } lines.push(chalk.cyan('═'.repeat(40))); lines.push(` Total outlines: ${result.totalOutlines}`); lines.push(` Valid feeds: ${chalk.green(result.validFeeds.toString())}`); if (result.errors.length > 0) { lines.push(` Errors: ${chalk.red(result.errors.length.toString())}`); for (const e of result.errors.slice(0, 5)) { lines.push(chalk.red(` - ${sanitizeTerminalText(e.outline)}: ${sanitizeTerminalText(e.error)}`)); } if (result.errors.length > 5) { lines.push(chalk.red(` ... and ${result.errors.length - 5} more errors`)); } } if (result.feeds.length > 0) { lines.push(''); lines.push(chalk.bold('Feeds to import:')); for (const feed of result.feeds.slice(0, 10)) { const category = feed.category ? chalk.gray(` [${sanitizeTerminalText(feed.category)}]`) : ''; lines.push(` - ${sanitizeTerminalText(feed.title)}${category}`); } if (result.feeds.length > 10) { lines.push(chalk.gray(` ... and ${result.feeds.length - 10} more feeds`)); } } return lines.join('\n'); }