Skip to content

Commit b3e4478

Browse files
committed
feat: add LICENCE
1 parent be83070 commit b3e4478

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Cael
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

frontend/src/components/Output/Output.module.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
/* output message */
1010
.output {
11-
@apply whitespace-pre-wrap p-2 bg-stone-100 font-mono empty:hidden;
11+
@apply overflow-x-auto p-2 bg-stone-100 font-mono empty:hidden;
12+
}
13+
14+
.output p {
15+
@apply whitespace-nowrap;
1216
}
1317

1418
.wrapper[data-status="error"] .output {

frontend/src/components/Output/Output.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import { useAppContext } from "@/contexts/AppProvider";
77

88
export default function Output() {
99
const { output, setOutput } = useAppContext();
10+
const lines = output.msg.split("\n").filter((line) => line !== "");
1011

1112
if (output.status === "idle" || output.status === "loading") return null;
1213

1314
return (
1415
<div data-status={output.status} className={clsx(style.wrapper, "dark:text-gray-300")}>
15-
<p className={clsx(style.output, "dark:bg-zinc-800")}>{output.msg || "Sorry, there is no output"}</p>
16+
<div className={clsx(style.output, "dark:bg-zinc-800")}>
17+
{lines.length === 0 && <p>Sorry, there is no output</p>}
18+
{lines.map((line) => (
19+
<p key={line}>{line}</p>
20+
))}
21+
</div>
1622
<button
1723
type="button"
1824
className={clsx(style["clear-button"], "dark:text-gray-400 sm:hover:text-blue-600 sm:dark:hover:text-gray-300")}

frontend/src/workers/pyodide-worker.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@ self.importScripts("https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide.js");
22

33
let message = "";
44
let pyodide = null;
5+
56
const stderr = (msg) => (message += msg + "\n");
67
const stdout = (msg) => (message += msg + "\n");
7-
const indexURL = "https://cdn.jsdelivr.net/pyodide/v0.25.0/full/";
88
const postmessage = (status, msg) => self.postMessage({ lang: "python", output: { status, msg } });
99

1010
async function waitPyodideReady() {
1111
postmessage("loading", "Python is loading, please wait...");
12-
pyodide = await loadPyodide({ indexURL, stdout, stderr });
12+
pyodide = await loadPyodide({ stdout, stderr });
1313
postmessage("idle", "Python is ready");
1414
}
1515

16-
waitPyodideReady();
17-
1816
self.onmessage = async (event) => {
1917
const { data, ...context } = event.data;
2018

21-
// add all the context to the worker
22-
for (const key of Object.keys(context)) self[key] = context[key];
23-
24-
if (!pyodide) await waitPyodideReady();
25-
2619
// only run the code if the language is python
2720
const { lang, code } = event.data;
2821
if (lang === "python") {
22+
// add all the context to the worker
23+
for (const key of Object.keys(context)) self[key] = context[key];
24+
25+
// wait for pyodide to be ready
26+
if (!pyodide) await waitPyodideReady();
27+
2928
if (!code) postmessage("error", "Python code is empty");
3029
else {
3130
try {
@@ -41,3 +40,5 @@ self.onmessage = async (event) => {
4140
}
4241
}
4342
};
43+
44+
waitPyodideReady();

0 commit comments

Comments
 (0)