Optimized code and fixed misunderstanding

This commit is contained in:
niku 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")!);

View File

@ -30,7 +30,7 @@ func main() {
w.SetHtml(string(b))
w.Bind("__WRITE_PTY", func(command string) {
p.WriteString(command + "\n")
p.WriteString(command)
})
go func() {
@ -53,7 +53,6 @@ func main() {
fn := fmt.Sprintf(`window.__WRITE_TERMINAL(%s);`, string(payload))
w.Eval(fn)
time.Sleep(200 * time.Millisecond)
}
}()