feat(cli): add beautiful colored output and fix daemon exit bug
Some checks failed
CI / Type Check & Lint (push) Failing after 6s
CI / Build Test (Current Platform) (push) Successful in 6s
Release / build-and-release (push) Successful in 44s
CI / Build All Platforms (push) Successful in 50s
CI / Type Check & Lint (pull_request) Failing after 5s
CI / Build Test (Current Platform) (pull_request) Successful in 5s
CI / Build All Platforms (pull_request) Successful in 49s
Some checks failed
CI / Type Check & Lint (push) Failing after 6s
CI / Build Test (Current Platform) (push) Successful in 6s
Release / build-and-release (push) Successful in 44s
CI / Build All Platforms (push) Successful in 50s
CI / Type Check & Lint (pull_request) Failing after 5s
CI / Build Test (Current Platform) (pull_request) Successful in 5s
CI / Build All Platforms (pull_request) Successful in 49s
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)
This commit is contained in:
89
ts/colors.ts
Normal file
89
ts/colors.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 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,
|
||||
bright: colors.bright,
|
||||
|
||||
// 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
|
||||
*/
|
||||
export function formatPowerStatus(status: 'online' | 'onBattery' | 'unknown'): string {
|
||||
switch (status) {
|
||||
case 'online':
|
||||
return theme.success('Online');
|
||||
case 'onBattery':
|
||||
return theme.warning('On Battery');
|
||||
case 'unknown':
|
||||
default:
|
||||
return theme.dim('Unknown');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user