-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.html
60 lines (55 loc) · 2.06 KB
/
repl.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<link rel="stylesheet" href="xterm.css" />
<script type="text/javascript" src="xterm.js"></script>
<script src="micropython.mjs" type="module"></script>
<script type="text/javascript" src="enable-threads.js"></script>
<script type="text/javascript" src="amy.js"></script>
<script type="text/javascript" src="amyrepl.js"></script>
</head>
<body>
<script type="module">
// Tulip settings
term = new Terminal({rows:40, cols:100, fontSize:12, theme: { background: '#004955' }});
term.writeln("Tap in the terminal window here to start...");
term.open(document.getElementById('terminal'));
const stdoutWriter = (line) => {
// While it's called line, it's always one char, line[0].
// Writing a 10 to xterm does LF but not CR, so we use its writeln to LFCR
if(line[0]==10) {
term.writeln([0]);
} else {
term.write(line);
}
};
// Tulip settings
mp = await loadMicroPython({
stdout:stdoutWriter,
linebuffer: false,
pystack: 8 * 1024,
heapsize: 2 * 1024 * 1024
});
term.onKey(e => {
var code = e.key.charCodeAt(0);
mp.replProcessCharWithAsyncify(code).then((response) => {
});
});
</script>
<div class="container-fluid px-5 my-5">
<h1>Web <A HREF="https://github.com/shorepine/amy">AMY</A> REPL</h1>
<div id="terminal"></div>
<script language="javascript">
function start_repl() {
start_python_and_audio();
start_term_and_repl();
}
// On click anywhere, start audio and the REPL, after audio is started (otherwise python gets confused about AMY)
document.body.addEventListener('click', start_repl, true);
</script>
</div>
</body>
</html>