From 0fce95e9b836c172d24125eb9129b266e57e8654 Mon Sep 17 00:00:00 2001 From: Jaime Idolpx Date: Thu, 11 Jun 2026 00:13:59 -0400 Subject: [PATCH] feat(SerialConsolePage): enhance input handling with line buffering and control character support --- src/app/components/SerialConsolePage.tsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/app/components/SerialConsolePage.tsx b/src/app/components/SerialConsolePage.tsx index 3d58d81..01bdee1 100644 --- a/src/app/components/SerialConsolePage.tsx +++ b/src/app/components/SerialConsolePage.tsx @@ -11,6 +11,7 @@ export default function SerialConsolePage({ onBack }: Props) { const containerRef = useRef(null); const termRef = useRef(null); const fitRef = useRef(null); + const lineBuffer = useRef(''); const { status, send, subscribe } = useWs(); // Keep a stable ref to `send` so the xterm onData closure never goes stale @@ -46,7 +47,26 @@ export default function SerialConsolePage({ onBack }: Props) { term.writeln('\x1b[2m── Meatloaf Serial Console ──\x1b[0m'); term.writeln(''); - term.onData((data) => sendRef.current(data)); + term.onData((data) => { + for (const char of data) { + if (char === '\r' || char === '\n') { + term.write('\r\n'); + sendRef.current(lineBuffer.current + '\r'); + lineBuffer.current = ''; + } else if (char === '\x7f' || char === '\b') { + if (lineBuffer.current.length > 0) { + lineBuffer.current = lineBuffer.current.slice(0, -1); + term.write('\b \b'); + } + } else if (char === '\x03') { + lineBuffer.current = ''; + term.write('^C\r\n'); + } else if (char >= ' ') { + lineBuffer.current += char; + term.write(char); + } + } + }); const onResize = () => fitRef.current?.fit(); window.addEventListener('resize', onResize);