From 4efb8638ffad6b7da18b437424307e0c60ff9649 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 16 May 2024 19:22:10 -1000 Subject: [PATCH] refac --- .../components/chat/Messages/CodeBlock.svelte | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/components/chat/Messages/CodeBlock.svelte b/src/lib/components/chat/Messages/CodeBlock.svelte index cc75ab313..3ed78dd41 100644 --- a/src/lib/components/chat/Messages/CodeBlock.svelte +++ b/src/lib/components/chat/Messages/CodeBlock.svelte @@ -138,18 +138,14 @@ }; const executePython = async (code) => { + result = null; + stdout = null; + stderr = null; + executed = true; let pyodide = await loadPyodide({ indexURL: '/pyodide/', - stderr: (text) => { - console.log('An error occured:', text); - if (stderr) { - stderr += `${text}\n`; - } else { - stderr = `${text}\n`; - } - }, stdout: (text) => { console.log('Python output:', text); @@ -158,14 +154,22 @@ } else { stdout = `${text}\n`; } + }, + stderr: (text) => { + console.log('An error occured:', text); + if (stderr) { + stderr += `${text}\n`; + } else { + stderr = `${text}\n`; + } } }); result = pyodide.runPython(code); console.log(result); - console.log(stderr); console.log(stdout); + console.log(stderr); }; $: highlightedCode = code ? hljs.highlightAuto(code, hljs.getLanguage(lang)?.aliases).value : '';