feat(SerialConsolePage): enhance input handling with line buffering and control character support
This commit is contained in:
parent
521fb8f613
commit
0fce95e9b8
|
|
@ -11,6 +11,7 @@ export default function SerialConsolePage({ onBack }: Props) {
|
|||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const termRef = useRef<Terminal | null>(null);
|
||||
const fitRef = useRef<FitAddon | null>(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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user