-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
254 lines (217 loc) · 7.03 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The HPI Language</title>
<style>
body {
font-family: 'Source Code Pro', monospace;
background-color: #ffffff;
color: #1e1e1e;
margin: 0;
padding: 0;
line-height: 1.6;
}
main {
text-align: center;
padding: 2rem;
}
h1 {
color: #007bff;
margin-bottom: 0.5rem;
}
h3 {
margin-top: 0;
color: #007bff;
}
#inputContainer {
display: flex;
width: 80%;
margin: 20px auto;
}
#sourceCodeContainer,
#outputContainer {
flex: 1;
margin-right: 20px;
}
#sourceCodeHeading,
#outputHeading {
text-align: left;
margin: 10px 0;
color: #007bff;
}
#myInput,
#output {
width: 100%;
height: 300px;
padding: 10px;
font-family: 'Source Code Pro', monospace;
font-size: 14px;
border: 1px solid #e0e0e0;
border-radius: 4px;
resize: none;
background-color: #ffffff;
color: #1e1e1e;
}
#output {
background-color: #1e1e1e;
color: #ffffff;
margin-top: 0;
}
#myInput:focus {
outline: none;
border-color: #007bff;
}
.buttonContainer {
margin-top: 20px;
display: flex;
justify-content: space-around;
}
.actionBtn {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 4px;
color: #ffffff;
}
#runBtn {
background-color: #007bff;
}
#runBtn:hover {
background-color: #0056b3;
}
#clearEditorBtn {
background-color: #dc3545;
}
#clearEditorBtn:hover {
background-color: #bd2130;
}
#clearOutputBtn {
background-color: #ffc107;
color: #1e1e1e;
}
#clearOutputBtn:hover {
background-color: #d39e00;
}
#copyCodeBtn {
background-color: #28a745;
}
#copyCodeBtn:hover {
background-color: #218838;
}
#openFileBtn {
background-color: #fd7e14;
}
#openFileBtn:hover {
background-color: #e66100;
}
#bottomControls {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
#bottomControls select {
width: 40%;
}
</style>
</head>
<body>
<main>
<h1>The HPI Language</h1>
<h3>A simple web interface to HPI language. Click 'Run program' to execute. Check the console for output</h3>
</main>
<div id="inputContainer" class="emscripten_border">
<div id="sourceCodeContainer">
<h4 id="sourceCodeHeading">Source Code:</h4>
<textarea id="myInput" rows="4" placeholder="Enter your program here"></textarea>
</div>
<div id="outputContainer">
<h4 id="outputHeading">Output:</h4>
<textarea id="output" rows="8"></textarea>
</div>
</div>
<div id="bottomControls" class="buttonContainer">
<select id="sampleCodeDropdown" onchange="loadSampleCode(this.value)">
<option value="" selected disabled>Select a sample program</option>
<option value="hello.hpi">Hello, World</option>
<option value="readEx.hpi">Simple Input</option>
<option value="fib.hpi">Fibonacci series</option>
<option value="bookPrgms/sp12.hpi">Factorial</option>
</select>
<button id="runBtn" class="actionBtn" onclick="handleClick()">Run program</button>
<button id="clearEditorBtn" class="actionBtn" onclick="clearEditor()">Clear editor</button>
<button id="clearOutputBtn" class="actionBtn" onclick="clearOutput()">Clear output</button>
<button id="copyCodeBtn" class="actionBtn" onclick="copyCode()">Copy code</button>
<button id="openFileBtn" class="actionBtn" onclick="openFile()">Open File</button>
</div>
<script>
var hpi_run;
var Module = {
print: (function() {
var element = document.getElementById('output');
if (element) element.value = '';
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight;
}
};
})(),
onRuntimeInitialized: () => {
hpi_run = Module.cwrap("runHPI", null, ["string"]);
}
};
function handleClick() {
document.getElementById("output").value = "";
var input = document.getElementById("myInput").value;
hpi_run(input);
}
function clearEditor() {
document.getElementById("myInput").value = "";
}
function clearOutput() {
document.getElementById("output").value = "";
}
function copyCode() {
var input = document.getElementById("myInput");
input.select();
document.execCommand("copy");
alert("Code copied to clipboard!");
}
function loadSampleCode(selectedSample) {
getSampleCode(selectedSample)
.then(sampleCode => {
document.getElementById("myInput").value = sampleCode;
})
.catch(error => {
console.error("Error loading sample code:", error);
});
}
function getSampleCode(sampleName) {
var githubBaseUrl = "https://raw.githubusercontent.com/harishtpj/HPI/master/examples/";
return fetch(githubBaseUrl + sampleName)
.then(response => response.text());
}
function openFile() {
var input = document.createElement('input');
input.type = 'file';
input.onchange = function (e) {
var file = e.target.files[0];
if (file) {
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById("myInput").value = e.target.result;
};
reader.readAsText(file);
}
};
input.click();
}
</script>
<script src="hpi.js"></script>
</body>
</html>