From cc5ef34fe3f4e251dda3d3f6f4a9a87d1d0c151d Mon Sep 17 00:00:00 2001 From: niku Date: Sun, 5 Mar 2023 13:41:05 +0100 Subject: [PATCH] Optimized code and fixed misunderstanding --- frontend/src/main.ts | 24 +++--------------------- main.go | 3 +-- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 1ddf2b5..2ac1562 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -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")!); diff --git a/main.go b/main.go index 9f8afd6..d8d16c3 100644 --- a/main.go +++ b/main.go @@ -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) } }()