Skip to content

Commit 95e4e2e

Browse files
author
Jean-Baptiste Doderlein
committed
Add reset interpreter
1 parent b7ca46c commit 95e4e2e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ <h2 class="center white-text">Loading Python Interpreter</h2>
9696
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
9797
onclick="terminal.terminal.clear()"><i
9898
class="material-icons">delete</i></a>
99+
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
100+
onclick="restart_toplevel()"><i
101+
class="material-icons">refresh</i></a>
99102
</div>
100103

101104
<!-- Quick execute and clean console on mobile -->
@@ -162,6 +165,9 @@ <h4>Configuration</h4>
162165
class="material-icons">remove</i></a>
163166
</div>
164167
</div>
168+
<a class="waves-effect waves-light btn config-element" onclick="restart_toplevel()"><i
169+
class="material-icons right">refresh</i>Reset
170+
Python Interpreter</a>
165171
<h4>Help</h4>
166172
<a href="#shortcut" class="waves-effect waves-light btn shortcut-button modal-trigger"><i
167173
class="material-icons right">code</i>Shortcuts</a>
@@ -336,8 +342,11 @@ <h4>Graphics main window</h4>
336342

337343
addEventListener("mpy:ready", () => {
338344
// show running for an instance
345+
console.log("Python interpreter ready")
339346
$('#loader-wrapper').addClass("tester")
340-
terminal.terminal.loadAddon(terminalFitter);
347+
// check if the terminal is ready
348+
let local_terminal = document.querySelector("#toplevel-terminal");
349+
local_terminal.terminal.loadAddon(terminalFitter);
341350
terminalFitter.fit();
342351
change_font_size("toplevel",0);
343352
});

src/js/editor_change.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const files = document.getElementById("editor-files");
1010
const mobile_sidenav = document.getElementById("mobile-sidenav");
1111
const buttons = document.getElementById("menu-button");
1212

13-
const terminal = document.querySelector("#toplevel-terminal");
13+
var terminal = document.querySelector("#toplevel-terminal");
1414

1515
var MOBILE = false;
1616

@@ -220,6 +220,19 @@ let current_bloc_selected = function (instance) {
220220
return { start: undefined, end: undefined };
221221
}
222222

223+
let restart_toplevel = function () {
224+
// Get the worker to stop
225+
terminal.xworker.terminate();
226+
// Delete the node
227+
let parent = terminal.parentNode;
228+
terminal.parentNode.removeChild(terminal.parentNode.querySelector("py-terminal"))
229+
let interpreter_code = parent.innerHTML;
230+
parent.innerHTML = "";
231+
// Inject the exact same node
232+
parent.innerHTML = interpreter_code;
233+
// Restart the terminal
234+
terminal = document.querySelector("#toplevel-terminal");
235+
}
223236

224237
/**
225238
* Calculate the cursor of the code to highlight

0 commit comments

Comments
 (0)