Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
30 changes: 16 additions & 14 deletions frontend/src/PadPage.tsx → frontend/src/components/PadPage.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 }>();
Expand Down Expand Up @@ -402,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) => (
<div
// <pre> for preserving line breaks and spacing
<pre
key={index}
className={`mb-1 ${
entry.type === 'error'
Expand All @@ -411,7 +413,7 @@ export function PadPage() {
}`}
>
{entry.text}
</div>
</pre>
))}
</div>
</div>
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/runners/go-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -175,7 +179,8 @@ async function runCode(code: string): Promise<RunResult> {
}

// 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<RunResult> {
Expand Down Expand Up @@ -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 };
12 changes: 6 additions & 6 deletions frontend/src/runners/python-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ async function runCode(code: string): Promise<RunResult> {
});

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) => 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 {
await pyodide.runPythonAsync(code);
} catch (errRaw: unknown) {
const err = errRaw as Error;
console.error('Pyodide error:', err);
outputEntries.push({
text: `${err.name}: ${err.message}`,
type: 'error',
});
outputEntries.push({
text: err.message,
type: 'error',
});
}
pyodide.setStdout({});
pyodide.setStderr({});
Expand Down