From 6480f5595ac4737832fb7262ea3ef4b35570b55d Mon Sep 17 00:00:00 2001 From: Guy Mor Date: Mon, 8 Sep 2025 01:03:51 +0300 Subject: [PATCH 1/3] moved PadPage.tsx --- frontend/src/{ => components}/PadPage.tsx | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) rename frontend/src/{ => components}/PadPage.tsx (96%) diff --git a/frontend/src/PadPage.tsx b/frontend/src/components/PadPage.tsx similarity index 96% rename from frontend/src/PadPage.tsx rename to frontend/src/components/PadPage.tsx index c76b78f..107812f 100644 --- a/frontend/src/PadPage.tsx +++ b/frontend/src/components/PadPage.tsx @@ -1,12 +1,12 @@ import { Navigate, useParams } from 'react-router-dom'; -import { PadEditor } from './components/PadEditor'; +import { PadEditor } from './PadEditor'; import { useCallback, useEffect, useMemo, useState } from 'react'; -import { RUNNERS } from './runners/runner'; -import { Button } from './components/Button'; -import { TabLayout } from './components/TabLayout'; -import { SideBySideLayout } from './components/SideBySideLayout'; -import { CollaborationBalloon, CollaborationToggle } from './components/CollaborationBalloon'; -import { useCollaboration } from './hooks/useCollaboration'; +import { RUNNERS } from '../runners/runner'; +import { Button } from './Button'; +import { TabLayout } from './TabLayout'; +import { SideBySideLayout } from './SideBySideLayout'; +import { CollaborationBalloon, CollaborationToggle } from './CollaborationBalloon'; +import { useCollaboration } from '../hooks/useCollaboration'; import { BAD_KEY_ERROR, getLanguageCodeSample, @@ -15,15 +15,16 @@ import { type PadRoom, SUPPORTED_LANGUAGES, } from 'coderjam-shared'; -import { getUserColorClassname } from './utils/userColors'; -import { useLocalStorageState } from './hooks/useLocalStorageState'; -import useIsOnMobile from './hooks/useIsOnMobile'; -import { Header } from './components/Header'; +import { getUserColorClassname } from '../utils/userColors'; +import { useLocalStorageState } from '../hooks/useLocalStorageState'; +import useIsOnMobile from '../hooks/useIsOnMobile'; +import { Header } from './Header'; const INITIAL_OUTPUT: OutputEntry[] = [ { type: 'log', text: 'Code execution results will be displayed here.' }, ]; -const CLEAN_OUTPUT: OutputEntry[] = [{ type: 'log', text: 'Output cleared.' }]; +// Output entries that will be set when clearing output +const CLEAN_OUTPUT: OutputEntry[] = []; export function PadPage() { const { padId } = useParams<{ padId: string }>(); From e502ba5c58f8afb4913b6c577d8eb7a34f22ccca Mon Sep 17 00:00:00 2001 From: Guy Mor Date: Mon, 8 Sep 2025 01:04:16 +0300 Subject: [PATCH 2/3] newlines no indentation --- frontend/src/App.tsx | 2 +- frontend/src/runners/go-runner.ts | 9 +++++++-- frontend/src/runners/python-runner.ts | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c63499f..cddd734 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,6 +1,6 @@ import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; import { HomePage } from './components/HomePage'; -import { PadPage } from './PadPage'; +import { PadPage } from './components/PadPage'; function App() { return ( diff --git a/frontend/src/runners/go-runner.ts b/frontend/src/runners/go-runner.ts index 1672d44..cb09b80 100644 --- a/frontend/src/runners/go-runner.ts +++ b/frontend/src/runners/go-runner.ts @@ -69,6 +69,10 @@ const allPermissions = 0o777; // All permissions let singletonGo: Go | undefined = undefined; let cmd: WebAssembly.WebAssemblyInstantiatedSource; +function postprocessOutput(output: OutputEntry[]): OutputEntry[] { + return output.filter(entry => entry.text !== '# command-line-arguments'); +} + function isReady(): boolean { return singletonGo !== undefined; } @@ -175,7 +179,8 @@ async function runCode(code: string): Promise { } // Run the Go code using the child process - return await runGoCommand(['run', USER_CODE_FILENAME]); + const runOutput = await runGoCommand(['run', USER_CODE_FILENAME]); + return { ...runOutput, output: postprocessOutput(runOutput.output) }; } async function runGoCommand(args: string[], printExitCode: boolean = true): Promise { @@ -211,4 +216,4 @@ async function runGoCommand(args: string[], printExitCode: boolean = true): Prom } // noinspection JSUnusedGlobalSymbols -export default { init, runCode, runGoCommand, isReady }; +export default { init, runCode, isReady }; diff --git a/frontend/src/runners/python-runner.ts b/frontend/src/runners/python-runner.ts index 388c6e7..7b3ee4f 100644 --- a/frontend/src/runners/python-runner.ts +++ b/frontend/src/runners/python-runner.ts @@ -44,8 +44,12 @@ async function runCode(code: string): Promise { }); const outputEntries: OutputEntry[] = []; - const addStdout = (text: string) => outputEntries.push({ text, type: 'log' }); - const addStderr = (text: string) => outputEntries.push({ text, type: 'error' }); + const addStdout = (text: string) => { + text.split('\n').forEach(line => outputEntries.push({ text: line, type: 'log' })); + }; + const addStderr = (text: string) => { + text.split('\n').forEach(line => outputEntries.push({ text: line, type: 'error' })); + }; pyodide.setStdout({ batched: addStdout }); pyodide.setStderr({ batched: addStderr }); try { @@ -53,10 +57,12 @@ async function runCode(code: string): Promise { } catch (errRaw: unknown) { const err = errRaw as Error; console.error('Pyodide error:', err); - outputEntries.push({ - text: `${err.name}: ${err.message}`, - type: 'error', - }); + for (const line of err.message.split('\n')) { + outputEntries.push({ + text: ' ' + line, + type: 'error', + }); + } } pyodide.setStdout({}); pyodide.setStderr({}); From 1c3b0f5ae452904fe25aa8c85fd75603ed85dd81 Mon Sep 17 00:00:00 2001 From: Guy Mor Date: Mon, 8 Sep 2025 13:32:18 +0300 Subject: [PATCH 3/3] with indentation --- frontend/src/components/PadPage.tsx | 5 +++-- frontend/src/runners/python-runner.ts | 12 +++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/PadPage.tsx b/frontend/src/components/PadPage.tsx index 107812f..f4ebace 100644 --- a/frontend/src/components/PadPage.tsx +++ b/frontend/src/components/PadPage.tsx @@ -403,7 +403,8 @@ export function PadPage() { className="flex-1 p-4 bg-dark-900 overflow-y-auto font-mono text-sm" > {(pad.output ?? INITIAL_OUTPUT)?.map((entry, index) => ( -
for preserving line breaks and spacing +
                                         {entry.text}
-                                    
+ ))} diff --git a/frontend/src/runners/python-runner.ts b/frontend/src/runners/python-runner.ts index 7b3ee4f..9d52371 100644 --- a/frontend/src/runners/python-runner.ts +++ b/frontend/src/runners/python-runner.ts @@ -44,12 +44,8 @@ async function runCode(code: string): Promise { }); const outputEntries: OutputEntry[] = []; - const addStdout = (text: string) => { - text.split('\n').forEach(line => outputEntries.push({ text: line, type: 'log' })); - }; - const addStderr = (text: string) => { - text.split('\n').forEach(line => outputEntries.push({ text: line, type: 'error' })); - }; + const addStdout = (text: string) => outputEntries.push({ text: text, type: 'log' }); + const addStderr = (text: string) => outputEntries.push({ text: text, type: 'error' }); pyodide.setStdout({ batched: addStdout }); pyodide.setStderr({ batched: addStderr }); try { @@ -57,12 +53,10 @@ async function runCode(code: string): Promise { } catch (errRaw: unknown) { const err = errRaw as Error; console.error('Pyodide error:', err); - for (const line of err.message.split('\n')) { outputEntries.push({ - text: ' ' + line, + text: err.message, type: 'error', }); - } } pyodide.setStdout({}); pyodide.setStderr({});