Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/desktop/electron/src/python-terminal.ts
1067 views
1
import "xterm/css/xterm.css";
2
import { Terminal } from "xterm";
3
import setTheme from "./xterm-theme";
4
import { WebLinksAddon } from "xterm-addon-web-links";
5
6
export default async function terminal(element: HTMLDivElement) {
7
const term = new Terminal({ convertEol: true });
8
term.options.allowProposedApi = true;
9
term.loadAddon(new WebLinksAddon());
10
term.open(element);
11
(element.children[0] as any).style.padding = "15px";
12
term.resize(80, 40);
13
term.write(
14
"This is a demo of https://www.npmjs.com/package/python-wasm\nIt includes numpy, sympy and pandas. "
15
);
16
term.write(
17
"Try 'import pandas' below.\nControl+c to interrupt and time.sleep to pause are also supported.\n\n"
18
);
19
setTheme(term, "solarized-light");
20
21
// Start the terminal:
22
window.electronAPI.pythonTerminal();
23
24
// process output from the terminal
25
window.electronAPI.onPythonStdout((data) => {
26
term.write(data);
27
});
28
window.electronAPI.onPythonStderr((data) => {
29
term.write(data);
30
});
31
32
term.onData((data) => {
33
window.electronAPI.pythonStdin(data);
34
});
35
/*
36
const python = await pythonWasm();
37
// @ts-ignore
38
element.children[0].style.padding = "15px";
39
term.resize(80, 40);
40
term.write(
41
"This is a demo of https://www.npmjs.com/package/python-wasm\nIt includes numpy and sympy. "
42
);
43
term.write(
44
"Try 'import numpy' and 'import sympy' below.\nControl+c to interrupt and time.sleep to pause are also supported.\n\n"
45
);
46
setTheme(term, "solarized-light");
47
term.onData((data) => {
48
python.kernel.writeToStdin(data);
49
});
50
python.kernel.on("stdout", (data) => {
51
term.write(data);
52
});
53
python.kernel.on("stderr", (data) => {
54
term.write(data);
55
});
56
await python.terminal();
57
python.kernel.terminate();
58
*/
59
}
60
61