Skip to content

Commit 873ddcc

Browse files
Add terminal-v2.0.html for terminal interface
1 parent 3a32b25 commit 873ddcc

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
3+
4+
<!-- headers
5+
cross-origin-isolate
6+
-->
7+
8+
9+
<html>
10+
11+
<head>
12+
13+
<link rel=stylesheet href='https://cdn.jsdelivr.net/npm/@xterm/xterm@5.5.0/css/xterm.css'>
14+
<style>
15+
16+
html
17+
{height:100%}
18+
body
19+
{margin:20px;height:calc(100% - 40px);}
20+
21+
#terminal
22+
{width:100%;height:100%}
23+
24+
</style>
25+
26+
</head>
27+
28+
29+
<body>
30+
31+
<div id=terminal></div>
32+
33+
</body>
34+
35+
36+
<script type=module>
37+
console.clear();
38+
import {Terminal} from 'https://cdn.jsdelivr.net/npm/@xterm/xterm/+esm';
39+
import {FitAddon} from 'https://cdn.jsdelivr.net/npm/@xterm/addon-fit/+esm'
40+
import {WebContainer} from 'https://cdn.jsdelivr.net/npm/@webcontainer/api/+esm'
41+
42+
var term = new Terminal();
43+
var fitAddon = new FitAddon();
44+
term.loadAddon(fitAddon);
45+
term.open(terminal);
46+
fitAddon.fit();
47+
term.write('booting container ...\r\n')
48+
var webcontainer = await WebContainer.boot();
49+
term.write('spawn jsh ...\r\n')
50+
var shell = await webcontainer.spawn('jsh');
51+
var output = new WritableStream({write(data){term.write(data)}});
52+
shell.output.pipeTo(output);
53+
54+
var input = shell.input.getWriter();
55+
term.onData(data=>input.write(data));
56+
57+
term.focus();
58+
59+
</script>
60+
61+
</html>
62+

0 commit comments

Comments
 (0)