const editor = CodeMirror(document.getElementById("editor"), { mode: "python", indentUnit: 4, indentWithTabs: true, smartIndent: true, lineNumbers: true, matchBrackets : true, autoCloseBrackets: true, trailingspace: true, foldGutter: true, gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"], }); const output = document.getElementById("output"); const runButton = document.getElementById("run"); runButton.addEventListener("click", () => { try { const result = evalPython(editor.getValue()); output.textContent = result; } catch (e) { console.error(e); output.textContent = `Erreur : ${e.message}`; } }); function evalPython(code) { let output = ""; function print(text) { output += text + "\n"; } if (window.__BRYTHON__) { output.textContent = `je suis dans window.__BRYTHON__ `; window.__BRYTHON__.stdout = print; window.__BRYTHON__.stderr = print; window.__BRYTHON__.run_py(code); } else { output.textContent = `je suis dans l erreur de window.__BRYTHON__ `; console.error("Brython n'a pas été correctement chargé ou initialisé."); } return output; } window.addEventListener("BrythonLoaded", () => { window.__BRYTHON__ = window.Brython; console.log("Brython prêt"); editor.refresh(); });