Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/web/terminal/src/terminal.ts
1070 views
1
import "xterm/css/xterm.css";
2
import { Terminal } from "xterm";
3
import setTheme from "./theme";
4
import pythonWasm from "python-wasm";
5
6
export default async function terminal(element: HTMLDivElement) {
7
console.log("creating pythonWasm");
8
const python = await pythonWasm();
9
(window as any).python = python;
10
const t = new Date();
11
console.log("python.init done; time = ", new Date().valueOf() - t.valueOf());
12
await python.exec("import readline");
13
console.log("readline = ", await python.repr("readline"));
14
const term = new Terminal({ convertEol: true });
15
term.open(element);
16
// @ts-ignore
17
element.children[0].style.padding = "15px";
18
term.resize(128, 40);
19
setTheme(term, "solarized-light");
20
term.onData((data) => {
21
python.kernel.writeToStdin(data);
22
});
23
python.kernel.on("stdout", (data) => {
24
term.write(data);
25
});
26
python.kernel.on("stderr", (data) => {
27
term.write(data);
28
});
29
console.log("starting terminal");
30
const r = await python.terminal();
31
console.log("terminal terminated", r);
32
python.kernel.terminate();
33
}
34
35