158 lines
3.9 KiB
TypeScript
158 lines
3.9 KiB
TypeScript
|
|
/**
|
|||
|
|
* Color theme and styling utilities for ModelGrid 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),
|
|||
|
|
|
|||
|
|
// GPU status colors
|
|||
|
|
gpuHealthy: colors.green, // GPU healthy
|
|||
|
|
gpuWarning: colors.yellow, // GPU warning
|
|||
|
|
gpuError: colors.red, // GPU error
|
|||
|
|
|
|||
|
|
// VRAM usage colors
|
|||
|
|
vramGood: colors.green, // < 60% usage
|
|||
|
|
vramMedium: colors.yellow, // 60-85% usage
|
|||
|
|
vramCritical: colors.red, // > 85% usage
|
|||
|
|
|
|||
|
|
// Container status colors
|
|||
|
|
containerRunning: colors.green,
|
|||
|
|
containerStopped: colors.red,
|
|||
|
|
containerStarting: colors.yellow,
|
|||
|
|
|
|||
|
|
// 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,
|
|||
|
|
model: colors.magenta,
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 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('◯'),
|
|||
|
|
gpu: colors.cyan('◆'),
|
|||
|
|
container: colors.blue('▣'),
|
|||
|
|
model: colors.magenta('◈'),
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Get color for VRAM usage percentage
|
|||
|
|
*/
|
|||
|
|
export function getVramColor(percentage: number): (text: string) => string {
|
|||
|
|
if (percentage < 60) return theme.vramGood;
|
|||
|
|
if (percentage < 85) return theme.vramMedium;
|
|||
|
|
return theme.vramCritical;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Get color for GPU utilization
|
|||
|
|
*/
|
|||
|
|
export function getGpuUtilColor(percentage: number): (text: string) => string {
|
|||
|
|
if (percentage < 60) return theme.gpuHealthy;
|
|||
|
|
if (percentage < 85) return theme.gpuWarning;
|
|||
|
|
return theme.gpuError;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Format GPU vendor with color
|
|||
|
|
*/
|
|||
|
|
export function formatGpuVendor(vendor: 'nvidia' | 'amd' | 'intel' | 'unknown'): string {
|
|||
|
|
switch (vendor) {
|
|||
|
|
case 'nvidia':
|
|||
|
|
return colors.green('NVIDIA');
|
|||
|
|
case 'amd':
|
|||
|
|
return colors.red('AMD');
|
|||
|
|
case 'intel':
|
|||
|
|
return colors.blue('Intel');
|
|||
|
|
case 'unknown':
|
|||
|
|
default:
|
|||
|
|
return colors.dim('Unknown');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Format container status with color
|
|||
|
|
*/
|
|||
|
|
export function formatContainerStatus(
|
|||
|
|
status: 'running' | 'stopped' | 'starting' | 'error' | 'unknown',
|
|||
|
|
): string {
|
|||
|
|
switch (status) {
|
|||
|
|
case 'running':
|
|||
|
|
return theme.containerRunning('Running');
|
|||
|
|
case 'stopped':
|
|||
|
|
return theme.containerStopped('Stopped');
|
|||
|
|
case 'starting':
|
|||
|
|
return theme.containerStarting('Starting');
|
|||
|
|
case 'error':
|
|||
|
|
return theme.error('Error');
|
|||
|
|
case 'unknown':
|
|||
|
|
default:
|
|||
|
|
return theme.dim('Unknown');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Format container type with color
|
|||
|
|
*/
|
|||
|
|
export function formatContainerType(type: 'ollama' | 'vllm' | 'tgi' | 'custom'): string {
|
|||
|
|
switch (type) {
|
|||
|
|
case 'ollama':
|
|||
|
|
return colors.green('Ollama');
|
|||
|
|
case 'vllm':
|
|||
|
|
return colors.cyan('vLLM');
|
|||
|
|
case 'tgi':
|
|||
|
|
return colors.magenta('TGI');
|
|||
|
|
case 'custom':
|
|||
|
|
return colors.yellow('Custom');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Format model status with color
|
|||
|
|
*/
|
|||
|
|
export function formatModelStatus(status: 'loaded' | 'loading' | 'unloaded' | 'error'): string {
|
|||
|
|
switch (status) {
|
|||
|
|
case 'loaded':
|
|||
|
|
return theme.success('Loaded');
|
|||
|
|
case 'loading':
|
|||
|
|
return theme.warning('Loading');
|
|||
|
|
case 'unloaded':
|
|||
|
|
return theme.dim('Unloaded');
|
|||
|
|
case 'error':
|
|||
|
|
return theme.error('Error');
|
|||
|
|
}
|
|||
|
|
}
|