import { createSignal, onMount, onCleanup, Show } from "solid-js"; import { BREAKPOINTS } from "~/config"; interface BtopProps { onClose: () => void; } export function Btop(props: BtopProps) { const [cpuUsage, setCpuUsage] = createSignal(64); const [memUsage, setMemUsage] = createSignal(80); const [netDown, setNetDown] = createSignal(404); const [netUp, setNetUp] = createSignal(0); const [processes, setProcesses] = createSignal([ { pid: 404, name: "error-handler", cpu: 32.0, mem: 15.2, status: "Running" }, { pid: 128, name: "glitch-generator", cpu: 18.4, mem: 8.7, status: "Running" }, { pid: 256, name: "terminal-shell", cpu: 8.2, mem: 4.1, status: "Running" }, { pid: 512, name: "random-process", cpu: 5.4, mem: 2.3, status: "Sleeping" }, { pid: 1024, name: "mystery-daemon", cpu: 0.0, mem: 0.0, status: "???" } ]); const [isMobile, setIsMobile] = createSignal(false); onMount(() => { if (typeof window !== "undefined") { setIsMobile(window.innerWidth < BREAKPOINTS.MOBILE); const handleResize = () => { setIsMobile(window.innerWidth < BREAKPOINTS.MOBILE); }; window.addEventListener("resize", handleResize); onCleanup(() => window.removeEventListener("resize", handleResize)); } const cpuInterval = setInterval(() => { setCpuUsage((prev) => { const change = (Math.random() - 0.5) * 10; const newVal = Math.max(30, Math.min(95, prev + change)); return Math.round(newVal); }); }, 1000); const memInterval = setInterval(() => { setMemUsage((prev) => { const change = (Math.random() - 0.5) * 5; const newVal = Math.max(60, Math.min(90, prev + change)); return Math.round(newVal); }); }, 1500); const netInterval = setInterval(() => { setNetDown(Math.floor(Math.random() * 1000)); setNetUp(Math.floor(Math.random() * 100)); }, 800); const procInterval = setInterval(() => { setProcesses((prev) => prev.map((proc) => ({ ...proc, cpu: proc.name === "mystery-daemon" ? 0.0 : Math.max(0, proc.cpu + (Math.random() - 0.5) * 5), mem: proc.name === "mystery-daemon" ? 0.0 : Math.max(0, proc.mem + (Math.random() - 0.5) * 2) })) ); }, 2000); const handleKeyPress = (e: KeyboardEvent) => { if (!isMobile() && e.key === "q" && e.shiftKey && e.key === ":") { props.onClose(); } if (!isMobile() && e.key === "q") { props.onClose(); } }; window.addEventListener("keydown", handleKeyPress); onCleanup(() => { clearInterval(cpuInterval); clearInterval(memInterval); clearInterval(netInterval); clearInterval(procInterval); window.removeEventListener("keydown", handleKeyPress); }); }); const createBar = (percentage: number, width: number = 30) => { const filled = Math.round((percentage / 100) * width); const empty = width - filled; return "█".repeat(filled) + "░".repeat(empty); }; return (
btop v1.404.0 - ErrorOS System Monitor Close } > Press 'q' to quit
System Resources
CPU [{createBar(cpuUsage())}] {cpuUsage()}% 2.4 GHz
MEM [{createBar(memUsage())}] {memUsage()}% {((memUsage() / 100) * 16).toFixed(1)}/16 GB
NET ↓ {netDown()} KB/s ↑ {netUp()} KB/s
Processes
{processes().map((proc) => ( ))}
PID Name CPU% MEM% Status
{proc.pid} {proc.name} {proc.cpu.toFixed(1)} {proc.mem.toFixed(1)} {proc.status}
Tap the Close button above to exit} > Type q to quit btop
); }