feat(cli): add beautiful colored output and fix daemon exit bug
Major improvements:
- Created color theme system (ts/colors.ts) with ANSI colors
- Enhanced logger with colors, table formatting, and styled boxes
- Fixed daemon exit bug - now stays running when no UPS configured
- Added config hot-reload with file watcher for live updates
- Beautified CLI help output with color-coded commands
- Added showcase test demonstrating all output features
- Fixed ANSI code handling for perfect table/box alignment
Features:
- Color-coded messages (success=green, error=red, warning=yellow, info=cyan)
- Status symbols (●○◐◯ for running/stopped/starting/unknown)
- Battery level colors (green>60%, yellow 30-60%, red<30%)
- Table formatting with auto-sizing and column alignment
- Styled boxes (success, error, warning, info styles)
- Hot-reload: daemon watches config file and reloads automatically
- Idle mode: daemon stays alive when no devices, checks periodically
Daemon improvements:
- No longer exits when no UPS devices configured
- Enters idle monitoring loop waiting for config
- File watcher detects config changes in real-time
- Auto-reloads and starts monitoring when devices added
- Logs warnings instead of errors for missing devices
Technical fixes:
- Strip ANSI codes when calculating text width for alignment
- Use visible length for padding calculations in tables and boxes
- Properly handle colored text in table cells and box lines
Breaking changes: None (backward compatible)
2025-10-19 15:08:30 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* Color theme and styling utilities for NUPST CLI
|
|
|
|
|
|
* Uses Deno standard library colors module
|
|
|
|
|
|
*/
|
|
|
|
|
|
import * as colors from '@std/fmt/colors';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Color theme for consistent CLI styling
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const theme = {
|
|
|
|
|
|
// Message types
|
|
|
|
|
|
error: colors.red,
|
|
|
|
|
|
warning: colors.yellow,
|
|
|
|
|
|
success: colors.green,
|
|
|
|
|
|
info: colors.cyan,
|
|
|
|
|
|
dim: colors.dim,
|
|
|
|
|
|
highlight: colors.bold,
|
|
|
|
|
|
|
|
|
|
|
|
// Status indicators
|
|
|
|
|
|
statusActive: (text: string) => colors.green(colors.bold(text)),
|
|
|
|
|
|
statusInactive: (text: string) => colors.red(text),
|
|
|
|
|
|
statusWarning: (text: string) => colors.yellow(text),
|
|
|
|
|
|
statusUnknown: (text: string) => colors.dim(text),
|
|
|
|
|
|
|
|
|
|
|
|
// Battery level colors
|
|
|
|
|
|
batteryGood: colors.green, // > 60%
|
|
|
|
|
|
batteryMedium: colors.yellow, // 30-60%
|
|
|
|
|
|
batteryCritical: colors.red, // < 30%
|
|
|
|
|
|
|
|
|
|
|
|
// Box borders
|
|
|
|
|
|
borderSuccess: colors.green,
|
|
|
|
|
|
borderError: colors.red,
|
|
|
|
|
|
borderWarning: colors.yellow,
|
|
|
|
|
|
borderInfo: colors.cyan,
|
|
|
|
|
|
borderDefault: (text: string) => text, // No color
|
|
|
|
|
|
|
|
|
|
|
|
// Command/code highlighting
|
|
|
|
|
|
command: colors.cyan,
|
|
|
|
|
|
code: colors.dim,
|
|
|
|
|
|
path: colors.blue,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Status symbols with colors
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const symbols = {
|
|
|
|
|
|
success: colors.green('✓'),
|
|
|
|
|
|
error: colors.red('✗'),
|
|
|
|
|
|
warning: colors.yellow('⚠'),
|
|
|
|
|
|
info: colors.cyan('ℹ'),
|
|
|
|
|
|
running: colors.green('●'),
|
|
|
|
|
|
stopped: colors.red('○'),
|
|
|
|
|
|
starting: colors.yellow('◐'),
|
|
|
|
|
|
unknown: colors.dim('◯'),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Get color for battery level
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getBatteryColor(percentage: number): (text: string) => string {
|
|
|
|
|
|
if (percentage >= 60) return theme.batteryGood;
|
|
|
|
|
|
if (percentage >= 30) return theme.batteryMedium;
|
|
|
|
|
|
return theme.batteryCritical;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Get color for runtime remaining
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function getRuntimeColor(minutes: number): (text: string) => string {
|
|
|
|
|
|
if (minutes >= 20) return theme.batteryGood;
|
|
|
|
|
|
if (minutes >= 10) return theme.batteryMedium;
|
|
|
|
|
|
return theme.batteryCritical;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Format UPS power status with color
|
|
|
|
|
|
*/
|
2026-02-20 11:51:59 +00:00
|
|
|
|
export function formatPowerStatus(status: 'online' | 'onBattery' | 'unknown' | 'unreachable'): string {
|
feat(cli): add beautiful colored output and fix daemon exit bug
Major improvements:
- Created color theme system (ts/colors.ts) with ANSI colors
- Enhanced logger with colors, table formatting, and styled boxes
- Fixed daemon exit bug - now stays running when no UPS configured
- Added config hot-reload with file watcher for live updates
- Beautified CLI help output with color-coded commands
- Added showcase test demonstrating all output features
- Fixed ANSI code handling for perfect table/box alignment
Features:
- Color-coded messages (success=green, error=red, warning=yellow, info=cyan)
- Status symbols (●○◐◯ for running/stopped/starting/unknown)
- Battery level colors (green>60%, yellow 30-60%, red<30%)
- Table formatting with auto-sizing and column alignment
- Styled boxes (success, error, warning, info styles)
- Hot-reload: daemon watches config file and reloads automatically
- Idle mode: daemon stays alive when no devices, checks periodically
Daemon improvements:
- No longer exits when no UPS devices configured
- Enters idle monitoring loop waiting for config
- File watcher detects config changes in real-time
- Auto-reloads and starts monitoring when devices added
- Logs warnings instead of errors for missing devices
Technical fixes:
- Strip ANSI codes when calculating text width for alignment
- Use visible length for padding calculations in tables and boxes
- Properly handle colored text in table cells and box lines
Breaking changes: None (backward compatible)
2025-10-19 15:08:30 +00:00
|
|
|
|
switch (status) {
|
|
|
|
|
|
case 'online':
|
|
|
|
|
|
return theme.success('Online');
|
|
|
|
|
|
case 'onBattery':
|
|
|
|
|
|
return theme.warning('On Battery');
|
2026-02-20 11:51:59 +00:00
|
|
|
|
case 'unreachable':
|
|
|
|
|
|
return theme.error('Unreachable');
|
feat(cli): add beautiful colored output and fix daemon exit bug
Major improvements:
- Created color theme system (ts/colors.ts) with ANSI colors
- Enhanced logger with colors, table formatting, and styled boxes
- Fixed daemon exit bug - now stays running when no UPS configured
- Added config hot-reload with file watcher for live updates
- Beautified CLI help output with color-coded commands
- Added showcase test demonstrating all output features
- Fixed ANSI code handling for perfect table/box alignment
Features:
- Color-coded messages (success=green, error=red, warning=yellow, info=cyan)
- Status symbols (●○◐◯ for running/stopped/starting/unknown)
- Battery level colors (green>60%, yellow 30-60%, red<30%)
- Table formatting with auto-sizing and column alignment
- Styled boxes (success, error, warning, info styles)
- Hot-reload: daemon watches config file and reloads automatically
- Idle mode: daemon stays alive when no devices, checks periodically
Daemon improvements:
- No longer exits when no UPS devices configured
- Enters idle monitoring loop waiting for config
- File watcher detects config changes in real-time
- Auto-reloads and starts monitoring when devices added
- Logs warnings instead of errors for missing devices
Technical fixes:
- Strip ANSI codes when calculating text width for alignment
- Use visible length for padding calculations in tables and boxes
- Properly handle colored text in table cells and box lines
Breaking changes: None (backward compatible)
2025-10-19 15:08:30 +00:00
|
|
|
|
case 'unknown':
|
|
|
|
|
|
default:
|
|
|
|
|
|
return theme.dim('Unknown');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|