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();
|
const term = new Terminal();
|
||||||
|
|
||||||
let command = "";
|
term.onKey(({ key }) => {
|
||||||
|
//@ts-ignore
|
||||||
term.onKey(({ key, domEvent }) => {
|
window.__WRITE_PTY(key);
|
||||||
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.open(document.getElementById("terminal")!);
|
term.open(document.getElementById("terminal")!);
|
||||||
|
3
main.go
3
main.go
@ -30,7 +30,7 @@ func main() {
|
|||||||
w.SetHtml(string(b))
|
w.SetHtml(string(b))
|
||||||
|
|
||||||
w.Bind("__WRITE_PTY", func(command string) {
|
w.Bind("__WRITE_PTY", func(command string) {
|
||||||
p.WriteString(command + "\n")
|
p.WriteString(command)
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -53,7 +53,6 @@ func main() {
|
|||||||
|
|
||||||
fn := fmt.Sprintf(`window.__WRITE_TERMINAL(%s);`, string(payload))
|
fn := fmt.Sprintf(`window.__WRITE_TERMINAL(%s);`, string(payload))
|
||||||
w.Eval(fn)
|
w.Eval(fn)
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user