-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.html
More file actions
112 lines (107 loc) · 4.01 KB
/
template.html
File metadata and controls
112 lines (107 loc) · 4.01 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html>
<head>
<title>emForth Web Shell</title>
<style>
body {
font-family: monospace;
background-color: #1e1e1e;
color: #d4d4d4;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
#output {
width: 80%;
max-width: 800px;
height: 400px;
background-color: #000;
color: #0f0;
font-family: monospace;
white-space: pre;
border: 1px solid #333;
overflow-y: scroll;
padding: 10px;
box-sizing: border-box;
resize: vertical;
}
#input {
width: 80%;
max-width: 800px;
background-color: #333;
color: #fff;
border: 1px solid #555;
padding: 5px;
margin-top: 10px;
box-sizing: border-box;
}
</style>
</head>
<body>
<h1>emForth Web Shell</h1>
<textarea id="output" readonly></textarea>
<input type="text" id="input" autofocus />
<script type="text/javascript">
var inputBuffer = [];
var encoder = new TextEncoder();
var Module = {
print: function (text) {
if (arguments.length > 1) {
text = Array.prototype.slice.call(arguments).join(" ");
}
var element = document.getElementById("output");
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight;
}
},
printErr: function (text) {
if (arguments.length > 1) {
text = Array.prototype.slice.call(arguments).join(" ");
}
console.error(text);
var element = document.getElementById("output");
if (element) {
element.value += "ERR: " + text + "\n";
element.scrollTop = element.scrollHeight;
}
},
stdin: function () {
if (inputBuffer.length > 0) {
return inputBuffer.shift();
}
return undefined;
},
onRuntimeInitialized: function () {
document
.getElementById("input")
.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
var line = this.value + "\n";
var encoded = encoder.encode(line);
// Echo input to console
var output = document.getElementById("output");
if (output) {
output.value += this.value + "\n";
output.scrollTop = output.scrollHeight;
}
// Add to input buffer
for (var i = 0; i < encoded.length; i++) {
inputBuffer.push(encoded[i]);
}
this.value = "";
this.focus();
}
});
},
};
var script = document.createElement("script");
script.src = "./emforth.js";
script.onload = function () {
EmforthModule(Module);
};
document.body.appendChild(script);
</script>
</body>
</html>