Compare commits

..

No commits in common. "648fb2778ca9002f86f017288c59d972bcf25441" and "521fb8f613a4641d3171d20063c0868a37efb8a9" have entirely different histories.

View File

@ -11,8 +11,6 @@ export default function SerialConsolePage({ onBack }: Props) {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const termRef = useRef<Terminal | null>(null); const termRef = useRef<Terminal | null>(null);
const fitRef = useRef<FitAddon | null>(null); const fitRef = useRef<FitAddon | null>(null);
const lineBuffer = useRef('');
const echoQueue = useRef<string[]>([]);
const { status, send, subscribe } = useWs(); const { status, send, subscribe } = useWs();
// Keep a stable ref to `send` so the xterm onData closure never goes stale // Keep a stable ref to `send` so the xterm onData closure never goes stale
@ -48,28 +46,7 @@ export default function SerialConsolePage({ onBack }: Props) {
term.writeln('\x1b[2m── Meatloaf Serial Console ──\x1b[0m'); term.writeln('\x1b[2m── Meatloaf Serial Console ──\x1b[0m');
term.writeln(''); term.writeln('');
term.onData((data) => { term.onData((data) => sendRef.current(data));
for (const char of data) {
if (char === '\r' || char === '\n') {
const line = lineBuffer.current + '\r';
lineBuffer.current = '';
term.write('\r\n');
echoQueue.current.push(line);
sendRef.current(line);
} 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(); const onResize = () => fitRef.current?.fit();
window.addEventListener('resize', onResize); window.addEventListener('resize', onResize);
@ -82,14 +59,9 @@ export default function SerialConsolePage({ onBack }: Props) {
}; };
}, []); }, []);
// Forward all incoming WS messages to the terminal, suppressing our own echoes // Forward all incoming WS messages to the terminal
useEffect(() => { useEffect(() => {
return subscribe((msg) => { return subscribe((msg) => {
const idx = echoQueue.current.indexOf(msg);
if (idx !== -1) {
echoQueue.current.splice(idx, 1);
return;
}
termRef.current?.write(msg); termRef.current?.write(msg);
}); });
}, [subscribe]); }, [subscribe]);
@ -137,16 +109,10 @@ export default function SerialConsolePage({ onBack }: Props) {
{/* Terminal */} {/* Terminal */}
<div <div
className="flex-1 min-h-0 relative overflow-hidden" ref={containerRef}
className="flex-1 min-h-0"
style={{ paddingBottom: 'env(safe-area-inset-bottom)' }} style={{ paddingBottom: 'env(safe-area-inset-bottom)' }}
>
<div ref={containerRef} className="absolute inset-0" />
<div
className="absolute inset-0 pointer-events-none z-10 opacity-15"
style={{ backgroundImage: 'url(assets/icon.svg)', backgroundRepeat: 'repeat', backgroundSize: '64px 64px' }}
aria-hidden="true"
/> />
</div> </div>
</div>
); );
} }