| 54 | const errorElement = document.getElementById('error'); |
| 55 | |
| 56 | function runCodeFromTextarea() { |
| 57 | // Clean the console and errors |
| 58 | consoleElement.value = ''; |
| 59 | errorElement.textContent = ''; |
| 60 | |
| 61 | const code = editor.state.doc.toString(); |
| 62 | try { |
| 63 | rp.pyExec(code, { |
| 64 | stdout: (output) => { |
| 65 | const shouldScroll = |
| 66 | consoleElement.scrollHeight - consoleElement.scrollTop === |
| 67 | consoleElement.clientHeight; |
| 68 | consoleElement.value += output; |
| 69 | if (shouldScroll) { |
| 70 | consoleElement.scrollTop = consoleElement.scrollHeight; |
| 71 | } |
| 72 | }, |
| 73 | }); |
| 74 | } catch (err) { |
| 75 | if (err instanceof WebAssembly.RuntimeError) { |
| 76 | err = window.__RUSTPYTHON_ERROR || err; |
| 77 | } |
| 78 | errorElement.textContent = err; |
| 79 | console.error(err); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | const snippets = document.getElementById('snippets'); |
| 84 | |