Optimized code and fixed misunderstanding
This commit is contained in:
@ -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")!);
|
||||
|
Reference in New Issue
Block a user