Optimized code and fixed misunderstanding
This commit is contained in:
parent
130724f2f6
commit
cc5ef34fe3
@ -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")!);
|
||||
|
3
main.go
3
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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user