Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/web/cowasm.org/src/terminal.ts
1067 views
1
import "xterm/css/xterm.css";
2
import { Terminal } from "xterm";
3
import setTheme from "./theme";
4
import pythonWasm from "python-wasm";
5
import { WebLinksAddon } from "xterm-addon-web-links";
6
7
export default async function terminal(element: HTMLDivElement) {
8
const term = new Terminal({ convertEol: true });
9
term.options.allowProposedApi = true;
10
term.loadAddon(new WebLinksAddon());
11
term.open(element);
12
const python = await pythonWasm();
13
// @ts-ignore
14
element.children[0].style.padding = "15px";
15
term.resize(80, 40);
16
term.write(
17
"This is a demo of https://www.npmjs.com/package/python-wasm\nIt includes numpy, sympy and pandas. "
18
);
19
term.write(
20
"Try 'import pandas' below.\nControl+c to interrupt and time.sleep to pause are also supported.\n\n"
21
);
22
setTheme(term, "solarized-light");
23
term.onData((data) => {
24
python.kernel.writeToStdin(data);
25
});
26
python.kernel.on("stdout", (data) => {
27
term.write(data);
28
});
29
python.kernel.on("stderr", (data) => {
30
term.write(data);
31
});
32
await python.terminal();
33
python.kernel.terminate();
34
}
35
36