- Create abstract BaseMigration class with order, shouldRun(), migrate() - Add MigrationRunner to execute migrations in order - Add Migration v1→v2 (snmp → upsDevices) - Add Migration v3→v4 (upsList → upsDevices) - Update INupstConfig with version field - Update loadConfig() to run migrations automatically - Update saveConfig() to ensure version field and remove legacy fields - Update Docker test scripts to use real UPS data from .nogit/env.json - Remove colors.bright (not available in @std/fmt/colors) Config migrations allow users to jump versions (e.g., v1→v4) with all intermediate migrations running automatically. Version field tracks config format for future migrations.
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
/**
|
||
* 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
|
||
*/
|
||
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');
|
||
}
|
||
}
|