Skip to content

Commit

Permalink
Add reset interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Baptiste Doderlein committed Jul 10, 2024
1 parent b7ca46c commit 95e4e2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ <h2 class="center white-text">Loading Python Interpreter</h2>
<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 -->
Expand Down Expand Up @@ -162,6 +165,9 @@ <h4>Configuration</h4>
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>
Expand Down Expand Up @@ -336,8 +342,11 @@ <h4>Graphics main window</h4>

addEventListener("mpy:ready", () => {
// show running for an instance
console.log("Python interpreter ready")
$('#loader-wrapper').addClass("tester")
terminal.terminal.loadAddon(terminalFitter);
// 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);
});
Expand Down
15 changes: 14 additions & 1 deletion src/js/editor_change.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const files = document.getElementById("editor-files");
const mobile_sidenav = document.getElementById("mobile-sidenav");
const buttons = document.getElementById("menu-button");

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

var MOBILE = false;

Expand Down Expand Up @@ -220,6 +220,19 @@ let current_bloc_selected = function (instance) {
return { start: undefined, end: undefined };
}

let restart_toplevel = function () {
// Get the worker to stop
terminal.xworker.terminate();
// Delete the node
let parent = terminal.parentNode;
terminal.parentNode.removeChild(terminal.parentNode.querySelector("py-terminal"))
let interpreter_code = parent.innerHTML;
parent.innerHTML = "";
// Inject the exact same node
parent.innerHTML = interpreter_code;
// Restart the terminal
terminal = document.querySelector("#toplevel-terminal");
}

/**
* Calculate the cursor of the code to highlight
Expand Down

0 comments on commit 95e4e2e

Please sign in to comment.