import { X, AlertTriangle } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
export function UsageCell({ percent = 0, variant = 'cpu' }) {
const clamped = Math.min(Number(percent) || 0, 100);
return (
);
}
export function ProcessTable({
processes = [],
selectedPid = null,
onSelect,
onKill,
onForceKill,
formatMemory = defaultFormatMemory,
getStatusVariant = defaultGetStatusVariant,
}) {
return (
| PID |
Name |
User |
CPU % |
Memory % |
Memory |
Status |
Actions |
{processes.map(p => (
onSelect?.(p)}
>
| {p.pid} |
{p.name} |
{p.user} |
|
|
{formatMemory(p.memory_info?.rss)} |
{p.status}
|
{onKill && (
)}
{onForceKill && (
)}
|
))}
);
}
export function ProcessDetailsPanel({ process, onClose, formatMemory = defaultFormatMemory }) {
if (!process) return null;
return (
Process Details
{process.command && (
Command
{process.command}
)}
);
}
export function DetailItem({ label, value, mono = false, children }) {
const valueClass = ['detail-value', mono && 'mono'].filter(Boolean).join(' ');
return (
{label}
{children ?? {value}}
);
}
function defaultFormatMemory(bytes) {
if (!bytes) return '-';
const units = ['B', 'KB', 'MB', 'GB'];
let i = 0;
while (bytes >= 1024 && i < units.length - 1) {
bytes /= 1024;
i++;
}
return `${bytes.toFixed(1)} ${units[i]}`;
}
function defaultGetStatusVariant(status) {
switch (status?.toLowerCase()) {
case 'running':
case 'sleeping':
return 'success';
case 'stopped':
case 'zombie':
return 'destructive';
case 'idle':
case 'disk-sleep':
return 'warning';
default:
return 'secondary';
}
}
export default ProcessTable;