Optimized code and fixed misunderstanding

This commit is contained in:
2023-03-05 13:41:05 +01:00
parent 130724f2f6
commit cc5ef34fe3
2 changed files with 4 additions and 23 deletions

View File

@ -2,27 +2,9 @@ import { Terminal } from "xterm";
const term = new Terminal();
let command = "";
term.onKey(({ key, domEvent }) => {
const isPrintable = !(
domEvent.altKey ||
domEvent.ctrlKey ||
domEvent.metaKey
);
if (domEvent.key === "Enter") {
//@ts-ignore
window.__WRITE_PTY(command);
term.writeln("");
command = "";
return;
}
if (isPrintable) {
term.write(key);
command += key;
}
term.onKey(({ key }) => {
//@ts-ignore
window.__WRITE_PTY(key);
});
term.open(document.getElementById("terminal")!);