Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ShellOutputEntryValue = any;
type Glyph = 'ChevronRight' | 'XWithCircle' | 'ChevronLeft';

export interface ShellOutputEntry {
key?: number | string;
format: 'input' | 'output' | 'error';
type?: string | null;
value: ShellOutputEntryValue;
Expand Down
5 changes: 4 additions & 1 deletion packages/browser-repl/src/components/shell-output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class ShellOutput extends Component<ShellOutputProps> {

renderLine = (entry: ShellOutputEntry, index: number): JSX.Element => {
return (
<ShellOutputLine key={`shell-output-entry-${index}`} entry={entry} />
<ShellOutputLine
key={`shell-output-entry-${entry.key ?? index}`}
entry={entry}
/>
);
};

Expand Down
3 changes: 3 additions & 0 deletions packages/browser-repl/src/components/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ const capLengthStart = (elements: unknown[], maxLength: number) => {
elements.splice(maxLength);
};

let lastKey = 0;

const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
{
runtime,
Expand Down Expand Up @@ -262,6 +264,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
...(outputRef.current ?? []),
...result.map(
(entry): ShellOutputEntry => ({
key: lastKey++,
format: 'output',
type: entry.type,
value: entry.printable,
Expand Down
16 changes: 13 additions & 3 deletions packages/browser-repl/src/sandbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,26 @@ class DemoServiceProvider {

const runtime = new IframeRuntime(new DemoServiceProvider() as any);

const lotsOfLines: ShellOutputEntry[] = [];
for (let i = 0; i < 99; i++) {
lotsOfLines.push({ key: `entry-${i}`, format: 'output', value: { i } });
}

const IframeRuntimeExample: React.FunctionComponent = () => {
const [darkMode, setDarkMode] = useState(true);
const [redactInfo, setRedactInfo] = useState(false);
const [maxOutputLength, setMaxOutputLength] = useState(1000);
const [maxHistoryLength, setMaxHistoryLength] = useState(1000);
const [maxOutputLength, setMaxOutputLength] = useState(100);
const [maxHistoryLength, setMaxHistoryLength] = useState(100);
const [initialEvaluate, setInitialEvaluate] = useState<string[]>([]);

const [initialText, setInitialText] = useState('');
const [output, setOutput] = useState<ShellOutputEntry[]>([
{ format: 'output', value: { foo: 1, bar: true, buz: function () {} } },
...lotsOfLines,
{
key: 'test',
format: 'output',
value: { foo: 1, bar: true, buz: function () {} },
},
]);
const [history, setHistory] = useState([
'show dbs',
Expand Down