-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·360 lines (321 loc) · 10.9 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html lang="en">
<head>
<title>CircuitPython IDE</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="description" content="CircuitPython IDE, with REPL that runs in Chrome browser">
<meta name="keywords" content="CircuitPython, IDE, REPL, Chrome browser">
<meta name="author" content="Mr. Coxall">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
<title>CircuitPython IDE</title>
<script>
// Redirect to HTTPS if HTTP is requested.
if (window.location.protocol === 'http:') {
window.location.href = 'https:' + window.location.href.substring(5);
}
</script>
<link rel="stylesheet" href="./style.css">
<script src="./script.js" defer></script>
<script type="text/javascript" src="./split.min.js"></script>
<style>
html,
body {
padding: 2px;
height: 100%;
background-color: #AAAAAA;
box-sizing: border-box;
}
.ace_editor {
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 1000px;
}
.split {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
overflow-y: auto;
overflow-x: hidden;
snapOffset: 0;
}
.top {
position:relative;
}
.log {
position:relative;
}
.content {
border: 1px solid #C0C0C0;
box-shadow: inset 0 1px 2px #e4e4e4;
background-color: #fff;
}
.gutter {
background-color: transparent;
background-repeat: no-repeat;
background-position: 75%;
}
.gutter.gutter-horizontal {
cursor: col-resize;
}
.gutter.gutter-vertical {
cursor: row-resize;
}
.button {
background-color: #652F8F; /* Blinka purple */
border: none;
color: white;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
outline: none;
}
.button-right {
float:right; /* move right */
background-color: #652F8F; /* Blinka purple */
border: none;
color: white;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
outline: none;
}
.input-button {
display: inline-block;
background-color: #652F8F;
border: none;
color: white;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 8px;
outline: none;
}
.image-button {
display: inline-block;
background-color: #FFFFFF;
border: none;
color: white;
padding: 7px 10px;
text-decoration: none;
display: inline-block;
border-radius: 8px;
float:left;
margin-right:0.5em;
outline: none;
}
input[type="file"] {
display: none;
}
.separator {
content: '';
display: inline-block;
background: #888;
margin: 0px 4px;
height: 18px;
width: 1px;
}
.repl-textarea {
height: 100%;
width: 100%;
font-size: 18px;
outline-width: 0;
}
</style>
<script src="./src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="./src-min-noconflict/ext-language_tools.js"></script>
<script type="text/javascript">
window.onload=function(){
var split = Split(['#top', '#log'], {
gutterSize: 10,
sizes: [75, 25],
direction: 'vertical',
onDragEnd: function() {
console.log(split.getSizes());
},
});
}
</script>
</head>
<body>
<div id="notSupported">
Sorry, <b>Web Serial</b> is not supported on this device, make sure you're
running Chrome 78 or later and have enabled the
<code><a href="chrome://flags/#enable-experimental-web-platform-features">chrome://flags/#enable-experimental-web-platform-features</a></code>
</div>
<div>
<a href="https://circuitpython.org" target="_blank"><button class="image-button" id="imageButton"><img src="./adafruit_blinka_computer.png"></button></a>
<span class="separator"></span>
<button class="button" id="butConnect">Connect ↔</button>
<span class="separator"></span>
<label class="input-button"><input accept=".py,
text/plain" type="file" id="fileToLoad" name="myFiles" onchange="loadFile();"/>Load ↑</label>
<button class="button" id="saveToFile" onclick="saveFile();">Save ↓</button>
<span class="separator"></span>
<button class="button" id="butRun" onclick="runFile();">Run →</button>
<button class="button" id="butStop" onclick="stopFile();">Stop ▪</button>
<button class="button" id="butClear" onclick="clearREPL();">Clear ◌</button>
<span class="separator"></span>
<button class="button" onclick="fontPlus();">Font +</button>
<button class="button" onclick="fontMinus();">Font -</button>
<button class="button" onclick="changeTheme();">Theme ►</button>
<button class="button" onclick="hiddenCharacters();">Hidden ѻ</button>
<a href="https://github.com/Mr-Coxall/CircuitPython-IDE" target="_blank"><button class="button-right">About ?</button></a>
</div>
<div id="top" style="background-color:black" class="split content">
<textarea id="editor"></textarea>
<script>
var fontSize = 24;
var themes = ["ace/theme/eclipse", "ace/theme/github", "ace/theme/ambiance", "ace/theme/twilight"];
var themeNumber = 3;
var hidden = false;
var currentFileName = null;
var editor = ace.edit("editor");
//editor.setTheme("ace/theme/twilight");
editor.setTheme(themes[themeNumber]);
editor.session.setMode("ace/mode/python");
// use setOptions method to set several options at once
editor.setOptions({
autoScrollEditorIntoView: true,
copyWithEmptySelection: true,
autoScrollEditorIntoView: true,
tabSize: 4, // python standard, 4 spaces
useSoftTabs: true, // python standard no tabs, spaces
showInvisibles: hidden,
fontSize: fontSize,
hScrollBarAlwaysVisible: true,
vScrollBarAlwaysVisible: true,
newLineMode: "unix",
enableLiveAutocompletion: true,
enableSnippets: true,
});
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
// got this from here: https://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript
function loadFile() {
// clear editor first
editor.setValue("");
const selectedFile = document.getElementById('fileToLoad').files[0];
// update the new file name
currentFileName = selectedFile.name;
const reader = new FileReader();
reader.onload = (function(evt) {
var result = evt.target.result;
editor.setValue(result, 1);
});
reader.readAsText(selectedFile);
}
function download(strData, strFileName, strMimeType) {
var D = document,
A = arguments,
a = D.createElement("a"),
d = A[0],
n = A[1],
t = A[2] || "text/plain";
//build download link:
a.href = "data:" + strMimeType + "charset=utf-8," + escape(strData);
if ('download' in a) {
a.setAttribute("download", n);
a.innerHTML = "downloading...";
D.body.appendChild(a);
setTimeout(function() {
var e = D.createEvent("MouseEvents");
e.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
D.body.removeChild(a);
}, 66);
return true;
}; /* end if('download' in a) */
//do iframe dataURL download: (older W3)
var f = D.createElement("iframe");
D.body.appendChild(f);
f.src = "data:" + (A[2] ? A[2] : "application/octet-stream") + (window.btoa ? ";base64" : "") + "," + (window.btoa ? window.btoa : escape)(strData);
setTimeout(function() {
D.body.removeChild(f);
}, 333);
return true;
}
function saveFile() {
// save file, if currentFileName = null, ask for file name first
if (currentFileName == null) {
currentFileName = "code.py";
}
download(editor.getValue(), currentFileName, 'text/plain');
}
function runFile() {
// run the current file, code is in script.js since you are sending CNTR-D to REPL
sendCTRLD();
}
function stopFile() {
// stop program from running
sendCTRLC();
}
function clearREPL() {
// clear REPL
document.getElementById("log").innerHTML="";
log.textContent = null;
}
function fontPlus() {
// increase font size
fontSize +=1;
editor.setOptions({
fontSize: fontSize,
});
}
function fontMinus() {
// decrease font size
fontSize -=1;
editor.setOptions({
fontSize: fontSize,
});
}
function changeTheme() {
// change theme
themeNumber +=1;
if (themeNumber > themes.length - 1) {
themeNumber = 0;
}
editor.setTheme(themes[themeNumber]);
}
function hiddenCharacters() {
// hidden characters
if (hidden == false) {
hidden = true;
}
else if (hidden == true) {
hidden = false;
}
editor.setOptions({
showInvisibles: hidden,
});
}
</script>
</div>
<table border="0">
<tr>
<textarea id="log" class="repl-textarea"></textarea>
</tr>
<tr>
<td nowrap><label for="repl_input">REPL Input: </label></td>
<td width="100%">
<input name="repl_input" id="repl_input" type="text" style="width: 100%; font-size: 18px;"/>
</td>
<td>
<input type="button" onclick="writeToStream(repl_input.value);" value="Send" style="height:27px; width:50px"/>
</td>
</tr>
</table>
</body>
</html>