Skip to content

Commit

Permalink
fix: consider object output
Browse files Browse the repository at this point in the history
  • Loading branch information
MR-Addict committed Sep 22, 2024
1 parent 91945f8 commit 08377dd
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 331 deletions.
683 changes: 392 additions & 291 deletions backend/Cargo.lock

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
"devDependencies": {
"@babel/standalone": "^7.25.6",
"@types/node": "^22.5.5",
"@types/react": "^18.3.5",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"ace-builds": "^1.36.2",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.1",
"million": "^3.1.11",
"postcss": "^8.4.45",
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"pyodide": "^0.26.2",
"react": "^18.3.1",
"react-ace": "^12.0.0",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
"tailwindcss": "^3.4.11",
"tailwindcss": "^3.4.12",
"typescript": "^5.6.2",
"vite": "^5.4.5",
"vite": "^5.4.7",
"zod": "^3.23.8"
},
"prettier": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Output/Output.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

.line {
@apply whitespace-pre-wrap;
@apply whitespace-pre-wrap flex flex-row gap-1;
}

/* wrap button */
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/Output/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ export default function Output() {
<p className={style.line}>&gt; Sorry, there is no output</p>
)}
{output.data.map((line, index) => (
<p key={index} data-color={line.color} className={style.line}>
{"> " + line.msg}
</p>
<div key={index} data-color={line.color} className={style.line}>
<span>&gt;</span>
<ul>
{line.msg.map((msg, index) => (
<li key={index}>{typeof msg === "string" ? msg : JSON.stringify(msg, null, 2)}</li>
))}
</ul>
</div>
))}
</div>

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/contexts/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => {
// start new worker
const newWorker = new Worker(workers[lang], { type: "classic", name: `${lang}-worker` });
newWorker.onmessage = (event: MessageEvent) => {
const parsedOutput = Output.safeParse(event.data.output);
const parsedLang = Language.safeParse(event.data.lang);
const parsedOutput = Output.safeParse(event.data.output);
if (!parsedOutput.success || !parsedLang.success) return;
setOutputs((prev) => ({
...prev,
[parsedLang.data]: { status: parsedOutput.data.status, data: [...prev[lang].data, ...parsedOutput.data.data] }
}));

const data = parsedOutput.data.data;
const status = parsedOutput.data.status;
setOutputs((prev) => ({ ...prev, [parsedLang.data]: { status, data: [...prev[lang].data, ...data] } }));
};
setWorker(newWorker);
}, [editor.lang]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Output = z.object({
status: z.enum(["idle", "loading", "running", "finished"]),
data: z.array(
z.object({
msg: z.string(),
msg: z.array(z.any()),
color: z.enum(["red", "yellow", "normal"])
})
)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/workers/javascript-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const postmessage = (status, msg) => self.postMessage({ lang: "javascript", output: { status, data: msg } });

self.console.error = (...msg) => postmessage("running", [{ color: "red", msg: msg.join(" ") }]);
self.console.log = (...msgs) => postmessage("running", [{ color: "normal", msg: msgs.join(" ") }]);
self.console.error = (...msg) => postmessage("running", [{ color: "red", msg }]);
self.console.log = (...msg) => postmessage("running", [{ color: "normal", msg }]);

self.onmessage = async (event) => {
const { data, ...context } = event.data;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/workers/python-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ self.importScripts("https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js");

let pyodide = null;

const postmessage = (status, msg) => self.postMessage({ lang: "python", output: { status, data: msg } });
const postmessage = (status, msg) => self.postMessage({ lang: "python", output: { status, data: [msg] } });
const stderr = (msg) => postmessage("running", [{ color: "red", msg }]);
const stdout = (msg) => {
// if the message is FLUSHHH, then ignore it
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/workers/typescript-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ self.importScripts("https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/babel-standal

const postmessage = (status, msg) => self.postMessage({ lang: "typescript", output: { status, data: msg } });

self.console.error = (...msg) => postmessage("running", [{ color: "red", msg: msg.join(" ") }]);
self.console.log = (...msgs) => postmessage("running", [{ color: "normal", msg: msgs.join(" ") }]);
self.console.error = (...msg) => postmessage("running", [{ color: "red", msg }]);
self.console.log = (...msg) => postmessage("running", [{ color: "normal", msg }]);

async function waitBabelReady() {
Babel.transform("", { filename: "typescript.ts", presets: ["typescript"] });
Expand Down

0 comments on commit 08377dd

Please sign in to comment.