-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
437 lines (390 loc) · 17.9 KB
/
index.html
File metadata and controls
437 lines (390 loc) · 17.9 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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!DOCTYPE html>
<html lang="en">
<head>
<title>BetterPython</title>
<meta name="description"
content="An efficient, intuitive and cross-platform web IDE for the Python language (recent: v3.7), with your code interpreted and running in your browser! (no server is needed!)">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./mini-coi.js" scope="./"></script>
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" sizes="48x48" href="icon/icon-48x48.png">
<link rel="apple-touch-icon" sizes="192x192" href="icon/icon-192x192.png">
<link rel="icon" type="image/png" sizes="192x192" href="icon/icon-192x192.png">
<link rel="icon" type="image/png" sizes="36x36" href="icon/icon-36x36.png">
<link rel="icon" type="image/png" sizes="96x96" href="icon/icon-96x96.png">
<meta name="msapplication-TileColor" content="#263238">
<meta name="msapplication-TileImage" content="icon/icon-144x144.png">
<meta name="theme-color" content="#263238">
<link href="css/icon.css" rel="stylesheet">
<link rel="stylesheet" id="css_theme" href="css/theme/material.css">
<link rel="stylesheet" href="css/materialize/materialize.min.css">
<link rel="stylesheet" href="css/codemirror/codemirror.min.css">
<link rel="stylesheet" href="css/codemirror/dialog.css"/>
<link rel="stylesheet" href="css/codemirror/show-hint.css"/>
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="js/pyscript/core.css"/>
<script src="js/codemirror/codemirror.js"></script>
<script src="js/codemirror/matchbrackets.min.js"></script>
<script src="js/codemirror/closebrackets.js"></script>
<script src="js/codemirror/python.js"></script>
<script src="js/codemirror/dialog.js"></script>
<script src="js/codemirror/searchcursor.js"></script>
<script src="js/codemirror/search.js"></script>
<script src="js/codemirror/jump-to-line.js"></script>
<script src="js/codemirror/show-hint.js"></script>
<script src="js/codemirror/annotatescrollbar.js"></script>
<script src="js/codemirror/matchesonscrollbar.js"></script>
<script src="js/codemirror/python-hint.js"></script>
<script async src="js/resizer.js"></script>
<script async defer src="js/buttons.js"></script>
<script src="js/tree-sitter/tree-sitter.js"></script>
<script type="module" src="js/pyscript/core.js"></script>
<script src="js/pyscript/addon-fit.js"></script>
</head>
<!-- Loading screen -->
<div id="loader-wrapper">
<div id="loader" class="container">
<img alt="Betterpython Splash" src="icon/banner.png">
<h2 class="center white-text">Loading Python Interpreter</h2>
<p class="center white-text">BetterPython will be ready in a few seconds ...</p>
<div class="progress">
<div class="indeterminate"></div>
</div>
</div>
</div>
<body>
<!-- Nav -->
<nav class="nav-extended">
<div class="nav-wrapper">
<ul id="editor-files" class="normal-tabs tabs left">
</ul>
<ul id="menu-button" class="right">
<li id="flexible-mobile-button">
<a onclick="editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.py', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));"><i
class="material-icons">add</i></a></li>
<li><a onclick="exec_all(editors[current_editor()])"><i class="material-icons">play_arrow</i></a></li>
<li><a onclick="save(editors[current_editor()]);"><i class="material-icons">save</i></a></li>
<li>
<a>
<label for="file-upload" class="custom-file-upload">
<i class="material-icons">folder</i> <input id="file-upload" type="file"
style="display: none;"/>
</label>
</a>
</li>
<li><a class="modal-trigger" href="#help"><i class="material-icons">settings</i></a></li>
</ul>
</div>
</nav>
<!-- Mobile Sidenav -->
<ul id="mobile-sidenav" class="sidenav mobile-tabs tabs">
<li id="add_tab" class="tab col s3 onglet">
<a onclick="editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.py', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));">
Add file
<i class="material-icons add-icon">add</i>
</a>
</li>
</ul>
<!-- Clean console button -->
<div class="fixed-action-btn hide-on-small-and-down" style="bottom: 15px; right: 15px;">
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="terminal.terminal.clear()"><i
class="material-icons">delete</i></a>
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="restart_toplevel()"><i
class="material-icons">refresh</i></a>
</div>
<!-- Quick execute and clean console on mobile -->
<div class="fixed-action-btn mobile-button hide-on-med-and-up" style="bottom: 15px; right: 15px;">
<a class="btn-floating btn-small waves-effect waves-light zoom-button" onclick="exec_all(editors[current_editor()])"><i
class="material-icons">play_arrow</i></a>
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="terminal.terminal.clear()"><i
class="material-icons">delete</i></a>
</div>
<!-- Configuration modal -->
<div id="help" class="modal help">
<div class="modal-content">
<h4>Configuration</h4>
<div class="config-section">
Theme :
<select name="theme" id="theme-select" class="config-element theme-select">
<option value="material">Default</option>
<option value="monokai">Monokai</option>
<option value="mdn-like">MDN</option>
<option value="pycharm">Pycharm</option>
</select>
<div class="switch config-element">
<label>
Row style
<input id="rbar-checkbox" type="checkbox" onclick="
change_resize_bar(resize_bar, (localStorage.getItem('betterocaml-resize-bar')==='H')?'V':'H')
">
<span class="lever"></span>
Column Style
</label>
</div>
<p class="config-element">
<label>
<input id="autocomplete-checkbox" type="checkbox" onclick="
change_configuration('betterocaml-autocomplete', (localStorage.getItem('betterocaml-autocomplete') === 'false'), editors)
"/>
<span>Autocomplete</span>
</label>
</p>
<div class="zoom-option config-element">
Editor zoom :
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="change_font_size('editor', 0.1)"><i
class="material-icons">add</i></a>
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="change_font_size('editor', -0.1)"><i
class="material-icons">remove</i></a>
</div>
<div class="zoom-option config-element">
Console zoom :
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="change_font_size('toplevel', 0.1)"><i
class="material-icons">add</i></a>
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
onclick="change_font_size('toplevel', -0.1)"><i
class="material-icons">remove</i></a>
</div>
</div>
<a class="waves-effect waves-light btn config-element" onclick="restart_toplevel()"><i
class="material-icons right">refresh</i>Reset
Python Interpreter</a>
<h4>Help</h4>
<a href="#shortcut" class="waves-effect waves-light btn shortcut-button modal-trigger"><i
class="material-icons right">code</i>Shortcuts</a>
<div class="help-section">
<a class="github-button" href="https://github.com/jbdoderlein/BetterPython" data-size="large"
aria-label="Issue jbdoderlein/BetterPython on GitHub">Open in Github</a>
<a class="github-button" href="https://github.com/jbdoderlein/BetterPython/issues"
data-icon="octicon-issue-opened"
data-size="large" aria-label="Issue jbdoderlein/BetterPython on GitHub">Issue</a>
</div>
</div>
<div class="modal-footer help">
<a href="#" class="modal-close waves-effect waves-green btn-flat white-text">Close</a>
</div>
</div>
<!-- Shortcut modal -->
<div id="shortcut" class="modal help">
<div class="modal-content">
<h4>Shortcuts</h4>
<h5>Editor</h5>
<div class="help-section">
<blockquote class="commands">
<div class="shortcut-command ctrl"> + Enter </div> : Execute the highlighted code
</blockquote>
<blockquote class="commands">
<div class="shortcut-command ctrl">+ Shift + Enter </div> : Execute the entire code
</blockquote>
<blockquote class="commands">
<div class="shortcut-command ctrl"> + Space </div> : Show the autocompletion box
</blockquote>
</div>
<h5>Toplevel</h5>
<div class="help-section">
<blockquote class="commands">
<div class="shortcut-command ctrl"> + E </div> : Paste Mode
</blockquote>
</div>
<h5>Search / Replace</h5>
<div class="help-section">
<blockquote class="commands">
<div class="shortcut-command ctrl"> + F </div> : Start searching
</blockquote>
<blockquote class="commands">
<div class="shortcut-command ctrl"> + G </div> : Find next
</blockquote>
<blockquote class="commands">
<div class="shortcut-command ctrl"> + Shift + G </div> : Find previous
</blockquote>
<blockquote class="commands">
<div class="shortcut-command ctrl"> + Shift + F </div> : Replace
</blockquote>
<blockquote class="commands">
<div class="shortcut-command ctrl"> + Shift + R </div> : Replace all
</blockquote>
<blockquote class="commands">
<div class="shortcut-command">Alt + F </div> : Persistent search
</blockquote>
<blockquote class="commands">
<div class="shortcut-command">Alt + G </div> : Jump to line
</blockquote>
</div>
</div>
<div class="modal-footer help">
<a href="#" class="modal-close waves-effect waves-green btn-flat white-text">Close</a>
</div>
</div>
<!-- Save modal-->
<div id="saveas" class="modal help">
<div class="modal-content">
<h4>Save as ...</h4>
<div class="input-field col s6">
<input placeholder="untitled.py" id="saveas_text" type="text" class="white-text">
</div>
</div>
<div class="modal-footer help">
<button class="btn modal-close waves-effect waves-light zoom-button right"
onclick="name_and_save(editors[current_editor()]);">
Save
<i class="material-icons right">save</i>
</button>
</div>
</div>
<div id="graphics" class="modal help">
<div class="modal-content">
<h4>Graphics main window</h4>
<canvas id="test-canvas">
</canvas>
</div>
<div class="modal-footer help">
<a href="#" class="modal-close waves-effect waves-green btn-flat white-text">Close</a>
</div>
</div>
<div class="container-boc container horizontal">
<!-- Editor flexboxs -->
<div id="box_1" class="box editor-box" style="display:flex;flex-direction:column">
<div class="editorCollection" id="editorCollection">
</div>
</div>
<div name="resizerH1"></div>
<!-- Toplevel flexbox -->
<div id="box_2" class="box console-box">
<div id="emtopx" style="font-size: var(--toplevel-font-size);display: none;"></div>
<div id="toplevel-container">
<mpy-config>
interpreter = "js/micropython/micropython.mjs"
</mpy-config>
<script id="toplevel-terminal" type="mpy" terminal worker name="toplevel" env="main">
import code
import asyncio
import sys
from pyscript import window
def _execute_current():
current = int(window.current_editor())
value = window.editors[current].getValue()
try:
exec(value)
except Exception as e:
sys.print_exception(e)
code.interact()
</script>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="js/materialize.min.js"></script>
<script src="js/editor_change.js"></script>
<script type="text/javascript">
// Loading global var
init_local_storage();
var editors, resize_bar;
// Editors load
editors = {}
editors[0] = create_editor(id = 0, name = 'untitled.py');
let terminalFitter = new FitAddon.FitAddon();
// Screen load
window.addEventListener("load", function () {
//Load the correct css theme
let href = document.getElementById('css_theme').href;
document.getElementById('css_theme').href = href.replace(/[^\/]+$/g, '') + (localStorage.getItem("betterocaml-theme") || "material") + ".css"
// Create the resize bar
resize_bar = new Resizer(document.querySelector('[name=resizerH1]'), 'H',{
callbackStop: () => {terminalFitter.fit();}
});
change_resize_bar(resize_bar, (localStorage.getItem("betterocaml-resize-bar") || "H"));
// Set text zoom
let r = document.querySelector(':root')
r.style.setProperty('--editor-font-size', (localStorage.getItem("betterocaml-text-editor") || "1.2em"));
r.style.setProperty('--toplevel-font-size', (localStorage.getItem("betterocaml-text-toplevel") || "1.2em"));
// Init navbar size
navbar_resize()
}, false);
// Loading Animation
addEventListener("mpy:ready", () => {
// show running for an instance
console.log("Python interpreter ready")
$('#loader-wrapper').addClass("tester")
// check if the terminal is ready
let local_terminal = document.querySelector("#toplevel-terminal");
local_terminal.terminal.loadAddon(terminalFitter);
terminalFitter.fit();
change_font_size("toplevel",0);
});
document.getElementById("loader-wrapper").addEventListener("animationend", (ev) => {
if (ev.type === "animationend") {
document.getElementById("loader-wrapper").style.display = "none";
$('body').off('DOMNodeInserted');
if (autosave_number() > 0) {
if (confirm("Des documents ont été sauvegardés automatiquement lors de la dernière session, voulez vous les restaurer ?")) {
restore_editors();
remove_editor(0);
}
clear_autosave()
}
}
}, false);
// Prevent exiting without saving
window.onbeforeunload = function () {
if (Object.keys(editors).length >= 1) {
if (!editors[id].is_saved) {
autosave_editor(id);
return "Your code is not saved, do you really want to leave ?"
}
}
};
// Auto resize
new ResizeObserver(navbar_resize).observe(files);
window.addEventListener("resize", navbar_resize);
// Load Materialize Components
$(document).ready(function () {
$('.modal').modal();
if (MOBILE) {
$('.mobile-tabs').tabs();
} else {
$('.normal-tabs').tabs();
}
$('.sidenav').sidenav();
$('#theme-select').find('option[value=' + (localStorage.getItem('betterocaml-theme') || 'material') + ']').prop('selected', true);
$("#theme-select").formSelect();
$("#autocomplete-checkbox").prop("checked", localStorage.getItem('betterocaml-autocomplete') === "true");
$("#rbar-checkbox").prop("checked", localStorage.getItem('betterocaml-resize-bar') === "H");
});
// Open file
document.getElementById('file-upload')
.addEventListener('change', readSingleFile, false);
// Change theme
document.getElementById('theme-select')
.addEventListener('change',
function (e) {
change_configuration('betterocaml-theme', e.target.value, editors);
}, false);
// Shortcut for Mac
document.querySelector(':root').style.setProperty('--shortcut_system', /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)?`"Cmd"`:`"Ctrl"`);
const Parser = window.TreeSitter;
let parser,query,error_quey;
Parser.init().then(() => {
parser = new Parser;
Parser.Language.load('js/tree-sitter/tree-sitter-python.wasm').then((language) => {
parser.setLanguage(language);
query = language.query(`
(function_definition)@bloc
(if_statement)@bloc
(for_statement)@bloc
(while_statement)@bloc
(try_statement)@bloc
(import_statement)@expr
(expression_statement)@expr`);
error_query = language.query(`
(ERROR)@error`);
});
});
</script>
</body>
</html>