/** * Showcase test for NUPST CLI outputs * Demonstrates all the beautiful colored output features * * Run with: deno run --allow-all test/showcase.ts */ import { logger, type ITableColumn } from '../ts/logger.ts'; import { theme, symbols, getBatteryColor, formatPowerStatus } from '../ts/colors.ts'; console.log(''); console.log('═'.repeat(80)); logger.highlight('NUPST CLI OUTPUT SHOWCASE'); logger.dim('Demonstrating beautiful, colored terminal output'); console.log('═'.repeat(80)); console.log(''); // === 1. Basic Logging Methods === logger.logBoxTitle('Basic Logging Methods', 60, 'info'); logger.logBoxLine(''); logger.log('Normal log message (default color)'); logger.success('Success message with ✓ symbol'); logger.error('Error message with ✗ symbol'); logger.warn('Warning message with ⚠ symbol'); logger.info('Info message with ℹ symbol'); logger.dim('Dim/secondary text for less important info'); logger.highlight('Highlighted/bold text for emphasis'); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 2. Colored Boxes === logger.logBoxTitle('Colored Box Styles', 60); logger.logBoxLine(''); logger.logBoxLine('Boxes can be styled with different colors:'); logger.logBoxEnd(); console.log(''); logger.logBox('Success Box (Green)', [ 'Used for successful operations', 'Installation complete, service started, etc.', ], 60, 'success'); console.log(''); logger.logBox('Error Box (Red)', [ 'Used for critical errors and failures', 'Configuration errors, connection failures, etc.', ], 60, 'error'); console.log(''); logger.logBox('Warning Box (Yellow)', [ 'Used for warnings and deprecations', 'Old command format, missing config, etc.', ], 60, 'warning'); console.log(''); logger.logBox('Info Box (Cyan)', [ 'Used for informational messages', 'Version info, update available, etc.', ], 60, 'info'); console.log(''); // === 3. Status Symbols === logger.logBoxTitle('Status Symbols', 60, 'info'); logger.logBoxLine(''); logger.logBoxLine(`${symbols.running} Service Running`); logger.logBoxLine(`${symbols.stopped} Service Stopped`); logger.logBoxLine(`${symbols.starting} Service Starting`); logger.logBoxLine(`${symbols.unknown} Status Unknown`); logger.logBoxLine(''); logger.logBoxLine(`${symbols.success} Operation Successful`); logger.logBoxLine(`${symbols.error} Operation Failed`); logger.logBoxLine(`${symbols.warning} Warning Condition`); logger.logBoxLine(`${symbols.info} Information`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 4. Battery Level Colors === logger.logBoxTitle('Battery Level Color Coding', 60, 'info'); logger.logBoxLine(''); logger.logBoxLine('Battery levels are color-coded:'); logger.logBoxLine(''); logger.logBoxLine(` ${getBatteryColor(85)('85%')} - Good (green, ≥60%)`); logger.logBoxLine(` ${getBatteryColor(45)('45%')} - Medium (yellow, 30-60%)`); logger.logBoxLine(` ${getBatteryColor(15)('15%')} - Critical (red, <30%)`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 5. Power Status Formatting === logger.logBoxTitle('Power Status Formatting', 60, 'info'); logger.logBoxLine(''); logger.logBoxLine(`Status: ${formatPowerStatus('online')}`); logger.logBoxLine(`Status: ${formatPowerStatus('onBattery')}`); logger.logBoxLine(`Status: ${formatPowerStatus('unknown')}`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 6. Table Formatting === const upsColumns: ITableColumn[] = [ { header: 'ID', key: 'id' }, { header: 'Name', key: 'name' }, { header: 'Host', key: 'host' }, { header: 'Status', key: 'status', color: (v) => { if (v.includes('Online')) return theme.success(v); if (v.includes('Battery')) return theme.warning(v); return theme.dim(v); }}, { header: 'Battery', key: 'battery', align: 'right', color: (v) => { const pct = parseInt(v); return getBatteryColor(pct)(v); }}, { header: 'Runtime', key: 'runtime', align: 'right' }, ]; const upsData = [ { id: 'ups-1', name: 'Main UPS', host: '192.168.1.10', status: 'Online', battery: '95%', runtime: '45 min', }, { id: 'ups-2', name: 'Backup UPS', host: '192.168.1.11', status: 'On Battery', battery: '42%', runtime: '12 min', }, { id: 'ups-3', name: 'Critical UPS', host: '192.168.1.12', status: 'On Battery', battery: '18%', runtime: '5 min', }, ]; logger.logTable(upsColumns, upsData, 'UPS Devices'); console.log(''); // === 7. Group Table === const groupColumns: ITableColumn[] = [ { header: 'ID', key: 'id' }, { header: 'Name', key: 'name' }, { header: 'Mode', key: 'mode' }, { header: 'UPS Count', key: 'count', align: 'right' }, ]; const groupData = [ { id: 'dc-1', name: 'Data Center 1', mode: 'redundant', count: '3' }, { id: 'office', name: 'Office Servers', mode: 'nonRedundant', count: '2' }, ]; logger.logTable(groupColumns, groupData, 'UPS Groups'); console.log(''); // === 8. Service Status Example === logger.logBoxTitle('Service Status', 70, 'success'); logger.logBoxLine(''); logger.logBoxLine(`Status: ${symbols.running} ${theme.statusActive('Active (Running)')}`); logger.logBoxLine(`Enabled: ${symbols.success} ${theme.success('Yes')}`); logger.logBoxLine(`Uptime: 2 days, 5 hours, 23 minutes`); logger.logBoxLine(`PID: ${theme.dim('12345')}`); logger.logBoxLine(`Memory: ${theme.dim('45.2 MB')}`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 9. Configuration Example === logger.logBoxTitle('Configuration', 70); logger.logBoxLine(''); logger.logBoxLine(`UPS Devices: ${theme.highlight('3')}`); logger.logBoxLine(`Groups: ${theme.highlight('2')}`); logger.logBoxLine(`Check Interval: ${theme.dim('30 seconds')}`); logger.logBoxLine(`Config File: ${theme.path('/etc/nupst/config.json')}`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 10. Update Available Example === logger.logBoxTitle('Update Available', 70, 'warning'); logger.logBoxLine(''); logger.logBoxLine(`Current Version: ${theme.dim('4.0.1')}`); logger.logBoxLine(`Latest Version: ${theme.highlight('4.0.2')}`); logger.logBoxLine(''); logger.logBoxLine(`Run ${theme.command('sudo nupst update')} to update`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === 11. Error Example === logger.logBoxTitle('Error Example', 70, 'error'); logger.logBoxLine(''); logger.logBoxLine(`${symbols.error} Failed to connect to UPS at 192.168.1.10`); logger.logBoxLine(''); logger.logBoxLine('Possible causes:'); logger.logBoxLine(` ${theme.dim('• UPS is offline or unreachable')}`); logger.logBoxLine(` ${theme.dim('• Incorrect SNMP community string')}`); logger.logBoxLine(` ${theme.dim('• Firewall blocking port 161')}`); logger.logBoxLine(''); logger.logBoxLine(`Try: ${theme.command('nupst ups test --debug')}`); logger.logBoxLine(''); logger.logBoxEnd(); console.log(''); // === Final Summary === console.log('═'.repeat(80)); logger.success('CLI Output Showcase Complete!'); logger.dim('All color and formatting features demonstrated'); console.log('═'.repeat(80)); console.log('');