Wired up a pty

This commit is contained in:
2023-03-05 08:44:21 +01:00
parent 39d2dc6efb
commit f86d0e662b
4 changed files with 62 additions and 6 deletions

View File

@@ -1,10 +1,31 @@
import { Terminal } from "xterm";
const term = new Terminal();
const term = new Terminal({
fontFamily:
'"Fira Code", courier-new, courier, monospace, "Powerline Extra Symbols"',
});
let line = "";
term.onKey(({ key, domEvent }) => {
const printable = !(domEvent.altKey || domEvent.ctrlKey || domEvent.metaKey);
if (domEvent.key === "Enter") {
//@ts-ignore
window.__WRITE_PTY(line);
term.writeln("");
line = "";
return;
}
if (printable) {
term.write(key);
line += key;
}
});
term.open(document.getElementById("terminal")!);
//@ts-ignore
window.__WRITE_TERMINAL = (data: string) => {
term.write(data);
window.__WRITE_TERMINAL = (data: { result: string }) => {
term.write(data.result);
};