From 95e4e2e45591f43666db0e2963ca3a058329e5d9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Doderlein Date: Wed, 10 Jul 2024 18:01:56 +0200 Subject: [PATCH] Add reset interpreter --- src/index.html | 11 ++++++++++- src/js/editor_change.js | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/index.html b/src/index.html index 499d104..f089d3a 100644 --- a/src/index.html +++ b/src/index.html @@ -96,6 +96,9 @@

Loading Python Interpreter

delete + refresh @@ -162,6 +165,9 @@

Configuration

class="material-icons">remove + refreshReset + Python Interpreter

Help

codeShortcuts @@ -336,8 +342,11 @@

Graphics main window

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); }); diff --git a/src/js/editor_change.js b/src/js/editor_change.js index 7c36fc3..7594bf3 100644 --- a/src/js/editor_change.js +++ b/src/js/editor_change.js @@ -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; @@ -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