enh: pyodide python result handling

This commit is contained in:
Timothy Jaeryang Baek 2025-02-02 16:56:21 -08:00
parent b94b691993
commit 74172461c7
2 changed files with 28 additions and 9 deletions

View File

@ -379,15 +379,27 @@ __builtins__.input = input`);
class="bg-[#202123] text-white max-w-full overflow-x-auto scrollbar-hidden"
/>
{#if executing}
<div class="bg-[#202123] text-white px-4 py-4 rounded-b-lg">
<div class=" text-gray-500 text-xs mb-1">STDOUT/STDERR</div>
<div class="text-sm">Running...</div>
</div>
{:else if stdout || stderr || result}
<div class="bg-[#202123] text-white px-4 py-4 rounded-b-lg">
<div class=" text-gray-500 text-xs mb-1">STDOUT/STDERR</div>
<div class="text-sm">{stdout || stderr || result}</div>
{#if executing || stdout || stderr || result}
<div class="bg-[#202123] text-white !rounded-b-lg py-4 px-4 flex flex-col gap-2">
{#if executing}
<div class=" ">
<div class=" text-gray-500 text-xs mb-1">STDOUT/STDERR</div>
<div class="text-sm">Running...</div>
</div>
{:else}
{#if stdout || stderr}
<div class=" ">
<div class=" text-gray-500 text-xs mb-1">STDOUT/STDERR</div>
<div class="text-sm">{stdout || stderr}</div>
</div>
{/if}
{#if result}
<div class=" ">
<div class=" text-gray-500 text-xs mb-1">RESULT</div>
<div class="text-sm">{`${result}`}</div>
</div>
{/if}
{/if}
</div>
{/if}
{/if}

View File

@ -61,9 +61,16 @@ self.onmessage = async (event) => {
try {
self.result = await self.pyodide.runPythonAsync(code);
try {
self.result = self.result.toJSON();
} catch (error) {
console.error(error);
}
} catch (error) {
self.stderr = error.toString();
}
self.postMessage({ id, result: self.result, stdout: self.stdout, stderr: self.stderr });
};