-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
55 lines (55 loc) · 1.56 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!doctype html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>pyodide + xterm.js</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/css/xterm.min.css"
/>
</head>
<body>
<h1>pyodide + xterm.js</h1>
<script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
<script src=" https://cdn.jsdelivr.net/npm/[email protected]/lib/xterm.min.js "></script>
<div id="terminal"></div>
<script>
const term = new Terminal();
term.open(document.getElementById("terminal"));
let input = "";
let complete = false;
term.onData((recv) => {
if (recv.charCodeAt(0) == 13) {
term.write("\r\n");
complete = true;
} else {
term.write(recv);
input += recv;
}
});
async function main() {
let pyodide = await loadPyodide({
stdin: () => {
if (complete) {
s = input;
input = "";
complete = false;
return s;
}
return "";
},
stdout: (l) => {
term.write(l);
term.write("\r\n");
},
});
// Pyodide is now ready to use...
const rc = await axios.get("/run.py");
await pyodide.runPythonAsync(rc.data);
}
main();
</script>
</body>
</html>