-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpython.html
72 lines (57 loc) · 1.91 KB
/
python.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<html>
<head>
<title>python</title>
<link rel="stylesheet" href="https://esm.sh/@xterm/xterm/css/xterm.css" />
<script type="importmap">
{
"imports": {
"easywasi": "./easywasi.js",
"@zenfs/core": "https://esm.sh/@zenfs/core",
"@zenfs/dom": "https://esm.sh/@zenfs/dom",
"@zenfs/zip": "https://esm.sh/@zenfs/zip",
"@xterm/xterm": "https://esm.sh/@xterm/xterm",
"@xterm/addon-webgl": "https://esm.sh/@xterm/addon-webgl",
"@xterm/addon-clipboard": "https://esm.sh/@xterm/addon-clipboard"
}
}
</script
</head>
<body>
<div id="terminal"></div>
<script type="module">
import { WasiPreview1 } from 'easywasi'
import { configure, InMemory, fs } from '@zenfs/core'
import { IndexedDB } from '@zenfs/dom'
import { Zip } from '@zenfs/zip'
import { Terminal } from '@xterm/xterm'
import { WebglAddon } from '@xterm/addon-webgl'
import { ClipboardAddon } from '@xterm/addon-clipboard'
const xterm = new Terminal({
cursorBlink: true
})
xterm.loadAddon(new WebglAddon())
xterm.loadAddon(new ClipboardAddon())
xterm.open(document.getElementById('terminal'))
xterm.onData(data => console.log(data))
await configure({
mounts: {
'/zip': {
backend: Zip,
data: await fetch('rustpython.zip').then((r) => r.arrayBuffer())
},
'/tmp': InMemory, // goes away on refresh
'/home': IndexedDB // lives between page-loads
}
})
const wasi_snapshot_preview1 = new WasiPreview1({ fs, args: [], env: {PYTHONPATH: ''}})
wasi_snapshot_preview1.fd_filestat_get = () => {}
wasi_snapshot_preview1.stdout = b => xterm.write(b)
wasi_snapshot_preview1.stderr = b => xterm.write(b)
wasi_snapshot_preview1.stdin = () => {}
const bytes = await fs.promises.readFile('/zip/rustpython.wasm')
const { instance } = await WebAssembly.instantiate(bytes, {
wasi_snapshot_preview1
})
const exitCode = wasi_snapshot_preview1.start(instance.exports)
</script>
</html>