@marimo-team/islands 0.25.3-dev447 → 0.25.3-dev453
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ErrorBoundary-DVbdKroW.js → ErrorBoundary-CIYMOu2p.js} +1 -1
- package/dist/assets/__vite-browser-external-D2z_TiUO.js +1 -0
- package/dist/assets/{worker-BUqfWMtI.js → worker-DLJ9P24O.js} +2 -2
- package/dist/{chat-ui-9oyUBL6M.js → chat-ui-DEHpKH2l.js} +17 -19
- package/dist/{code-visibility-DmsDqWUx.js → code-visibility-BQE60zOk.js} +7 -7
- package/dist/{common-BDo_Jwoz.js → common-DfUux6zJ.js} +4902 -4893
- package/dist/{data-grid-overlay-editor-CpHB_knU.js → data-grid-overlay-editor-B9zW4oN1.js} +1 -1
- package/dist/{error-entries-CWdDf7iZ.js → error-entries-BG7ifiDg.js} +1368 -996
- package/dist/{feedback-button-B_Wmi4to.js → feedback-button-BEUh4iQQ.js} +129 -129
- package/dist/{glide-data-editor-CMiIW5WP.js → glide-data-editor-CbdIXPTZ.js} +3 -3
- package/dist/{globals-DaC3pk9F.js → globals-BkxG-Y8L.js} +1 -1
- package/dist/{html-to-image-CexRSGAZ.js → html-to-image-9HLBGrIx.js} +4115 -4103
- package/dist/main.js +6562 -6671
- package/dist/{number-overlay-editor-Dd4cOJ5I.js → number-overlay-editor-BFzdth50.js} +1 -1
- package/dist/{process-output-hcyVRJCC.js → process-output-B8HPq5iZ.js} +2 -2
- package/dist/{reveal-component-CTmvBdvu.js → reveal-component-DK_-9fAX.js} +166 -167
- package/package.json +1 -1
- package/src/__mocks__/executions.ts +7 -4
- package/src/__mocks__/notebook.ts +20 -4
- package/src/components/editor/cell/DeleteButton.tsx +2 -2
- package/src/components/editor/cell/StopButton.tsx +2 -2
- package/src/components/editor/cell/useRunCells.ts +0 -3
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +1 -1
- package/src/components/editor/notebook-cell.tsx +4 -35
- package/src/components/editor/output/ansi-reduce.ts +124 -61
- package/src/components/editor/output/console/ConsoleOutput.tsx +7 -25
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +15 -44
- package/src/components/editor/renderers/cells-renderer.tsx +2 -5
- package/src/components/editor/renderers/grid-layout/__tests__/grid-layout.test.tsx +1 -1
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +3 -6
- package/src/components/editor/stdin-blocking-alert.tsx +14 -18
- package/src/components/scratchpad/scratchpad.test.tsx +1 -1
- package/src/components/scratchpad/scratchpad.tsx +5 -6
- package/src/components/slides/__tests__/cell-output-block.test.tsx +2 -2
- package/src/components/slides/__tests__/slide-cell-view.test.tsx +2 -2
- package/src/components/tracing/tracing-spec.ts +11 -1
- package/src/components/tracing/tracing.tsx +4 -0
- package/src/core/ai/context/providers/__tests__/cell-output.test.ts +10 -20
- package/src/core/ai/context/providers/__tests__/error.test.ts +5 -27
- package/src/core/ai/context/providers/cell-output.ts +4 -12
- package/src/core/cells/__tests__/cell.test.ts +1 -169
- package/src/core/cells/__tests__/cells.test.ts +32 -709
- package/src/core/cells/__tests__/clear-outputs.test.ts +21 -14
- package/src/core/cells/__tests__/collapseConsoleOutputs.test.ts +71 -2
- package/src/core/cells/__tests__/logs.test.ts +18 -29
- package/src/core/cells/__tests__/runs.test.ts +128 -431
- package/src/core/cells/__tests__/session.test.ts +9 -9
- package/src/core/cells/actions.ts +29 -7
- package/src/core/cells/cell.ts +1 -96
- package/src/core/cells/cells.ts +147 -117
- package/src/core/cells/collapseConsoleOutputs.tsx +71 -40
- package/src/core/cells/command-console.ts +46 -0
- package/src/core/cells/execution-console.ts +230 -0
- package/src/core/cells/focus.ts +9 -29
- package/src/core/cells/logs.ts +10 -2
- package/src/core/cells/runs.ts +62 -118
- package/src/core/cells/session.ts +2 -2
- package/src/core/cells/types.ts +30 -23
- package/src/core/cells/useAnswerPrompt.ts +29 -0
- package/src/core/errors/error-entries.ts +3 -4
- package/src/core/executions/__tests__/atoms.test.ts +6 -20
- package/src/core/executions/__tests__/input.test.ts +3 -3
- package/src/core/executions/__tests__/output-lifecycle.test.ts +2 -8
- package/src/core/executions/atoms.ts +2 -21
- package/src/core/executions/index.ts +2 -1
- package/src/core/executions/input.ts +4 -3
- package/src/core/executions/output.ts +3 -3
- package/src/core/islands/__tests__/bridge.test.ts +59 -0
- package/src/core/islands/bootstrap.ts +29 -12
- package/src/core/islands/bridge.ts +67 -13
- package/src/core/kernel/handlers.ts +2 -21
- package/src/core/kernel/messages.ts +0 -1
- package/src/core/network/types.ts +0 -1
- package/src/core/notebook/document/__tests__/codemirror.test.ts +1 -0
- package/src/core/notebook/replica/__tests__/executions.test.ts +1 -0
- package/src/core/notebook/replica/__tests__/replica.test.ts +113 -0
- package/src/core/notebook/replica/replica.ts +106 -12
- package/src/core/notebook/replica/resources/executions.ts +57 -4
- package/src/core/session/__tests__/backend.test.ts +2 -4
- package/src/core/session/__tests__/useNotebookReplica.hook.test.tsx +1 -0
- package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +601 -35
- package/src/core/session/useNotebookReplica.ts +20 -6
- package/src/core/session/useNotebookSession.tsx +63 -33
- package/src/core/static/virtual-file-tracker.ts +26 -8
- package/src/stories/layout/vertical/one-column.stories.tsx +18 -12
- package/dist/assets/__vite-browser-external-CpRgw4M_.js +0 -1
- package/src/components/editor/alerts/stdin-blocking-alert.tsx +0 -68
- package/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap +0 -703
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type ConnectionStatus,
|
|
11
11
|
type Document,
|
|
12
12
|
type Execution,
|
|
13
|
+
type Item,
|
|
13
14
|
type Executions,
|
|
14
15
|
type NotebookBackend,
|
|
15
16
|
type NotebookReplica,
|
|
@@ -53,10 +54,12 @@ function completed(
|
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
type ExecutionFixture = Protocol.Execution & { items?: readonly Item[] };
|
|
58
|
+
|
|
59
|
+
function mirror(records: readonly ExecutionFixture[]): Executions {
|
|
57
60
|
const executions = new Map<Protocol.ExecutionId, Execution>();
|
|
58
61
|
const latest = new Map<Protocol.CellId, Protocol.ExecutionId>();
|
|
59
|
-
for (const record of records) {
|
|
62
|
+
for (const { items = [], ...record } of records) {
|
|
60
63
|
if (record.cell_id !== null) {
|
|
61
64
|
// The host retains one execution per cell on the stream.
|
|
62
65
|
const previous = latest.get(record.cell_id);
|
|
@@ -68,7 +71,7 @@ function mirror(records: readonly Protocol.Execution[]): Executions {
|
|
|
68
71
|
executions.set(record.id, {
|
|
69
72
|
record,
|
|
70
73
|
outputVersion: 0,
|
|
71
|
-
items: new Map(),
|
|
74
|
+
items: new Map(items.map((item) => [item.id, item])),
|
|
72
75
|
variables: new Map(),
|
|
73
76
|
});
|
|
74
77
|
}
|
|
@@ -234,7 +237,7 @@ export const MockExecutions = {
|
|
|
234
237
|
/** Make the store's active replica report `records`, `runtime`, and `document`. */
|
|
235
238
|
seed(
|
|
236
239
|
store: Store,
|
|
237
|
-
records:
|
|
240
|
+
records: ExecutionFixture[],
|
|
238
241
|
runtime: Protocol.Runtime | null = null,
|
|
239
242
|
document: Document | null = null,
|
|
240
243
|
) {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type CellRuntimeState,
|
|
13
13
|
createCellRuntimeState,
|
|
14
14
|
} from "@/core/cells/types";
|
|
15
|
+
import type { Item } from "@/core/notebook/replica";
|
|
15
16
|
import type { MarimoError } from "@/core/kernel/messages";
|
|
16
17
|
import { Objects } from "@/utils/objects";
|
|
17
18
|
import { MockExecutions } from "./executions";
|
|
@@ -148,6 +149,7 @@ export const MockNotebook = {
|
|
|
148
149
|
cellName: string;
|
|
149
150
|
code?: string;
|
|
150
151
|
error: Partial<Protocol.Error>;
|
|
152
|
+
consoleTraceback?: string;
|
|
151
153
|
}[],
|
|
152
154
|
): NotebookState => {
|
|
153
155
|
const cellData: Record<string, Partial<CellData>> = {};
|
|
@@ -159,10 +161,24 @@ export const MockNotebook = {
|
|
|
159
161
|
}
|
|
160
162
|
const notebookState = MockNotebook.notebookState({ cellData });
|
|
161
163
|
store.set(notebookAtom, notebookState);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
const records = errors.map(({ cellId, error, consoleTraceback }) => {
|
|
165
|
+
const record = MockExecutions.failed(cellId, error);
|
|
166
|
+
if (consoleTraceback === undefined) {
|
|
167
|
+
return record;
|
|
168
|
+
}
|
|
169
|
+
const traceback: Item = {
|
|
170
|
+
kind: "display",
|
|
171
|
+
id: `traceback-${record.id}`,
|
|
172
|
+
execution_id: record.id,
|
|
173
|
+
seq: 0,
|
|
174
|
+
content: {
|
|
175
|
+
mimetype: "application/vnd.marimo+traceback",
|
|
176
|
+
data: consoleTraceback,
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
return { ...record, items: [traceback] };
|
|
180
|
+
});
|
|
181
|
+
MockExecutions.seed(store, records);
|
|
166
182
|
return notebookState;
|
|
167
183
|
},
|
|
168
184
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { Trash2Icon } from "lucide-react";
|
|
3
3
|
import type { JSX } from "react";
|
|
4
|
-
import type {
|
|
4
|
+
import type { CellRunStatus } from "@/core/executions";
|
|
5
5
|
import {
|
|
6
6
|
getConnectionTooltip,
|
|
7
7
|
isAppInteractionDisabled,
|
|
@@ -13,7 +13,7 @@ import { Button } from "../../ui/button";
|
|
|
13
13
|
import { Tooltip } from "../../ui/tooltip";
|
|
14
14
|
|
|
15
15
|
export const DeleteButton = (props: {
|
|
16
|
-
status:
|
|
16
|
+
status: CellRunStatus;
|
|
17
17
|
connectionState: ConnectionState;
|
|
18
18
|
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
19
19
|
}): JSX.Element => {
|
|
@@ -3,7 +3,7 @@ import { SquareIcon } from "lucide-react";
|
|
|
3
3
|
import type { JSX } from "react";
|
|
4
4
|
import { interruptRuntime } from "@/core/executions";
|
|
5
5
|
import { store } from "@/core/state/jotai";
|
|
6
|
-
import type {
|
|
6
|
+
import type { CellRunStatus } from "@/core/executions";
|
|
7
7
|
import { isAppInteractionDisabled } from "@/core/session/connection-utils";
|
|
8
8
|
import type { ConnectionState } from "@/core/session/types";
|
|
9
9
|
import { Functions } from "@/utils/functions";
|
|
@@ -12,7 +12,7 @@ import { ToolbarItem } from "./toolbar";
|
|
|
12
12
|
import { useShouldShowInterrupt } from "./useShouldShowInterrupt";
|
|
13
13
|
|
|
14
14
|
export const StopButton = (props: {
|
|
15
|
-
status:
|
|
15
|
+
status: CellRunStatus;
|
|
16
16
|
connectionState: ConnectionState;
|
|
17
17
|
}): JSX.Element => {
|
|
18
18
|
const { connectionState, status } = props;
|
|
@@ -5,7 +5,6 @@ import { atom, useSetAtom } from "jotai";
|
|
|
5
5
|
import useEvent from "react-use-event-hook";
|
|
6
6
|
import { toast } from "@/components/ui/use-toast";
|
|
7
7
|
import { getNotebook } from "@/core/cells/cells";
|
|
8
|
-
import { useCellActions } from "@/core/cells/actions";
|
|
9
8
|
import type { CellId } from "@/core/cells/ids";
|
|
10
9
|
import { enabledCellIds, staleCellIds } from "@/core/cells/utils";
|
|
11
10
|
import {
|
|
@@ -105,7 +104,6 @@ export function useRunAllCells() {
|
|
|
105
104
|
* debugger view clears, as they would on any run.
|
|
106
105
|
*/
|
|
107
106
|
export function useRunCells() {
|
|
108
|
-
const { prepareForRun } = useCellActions();
|
|
109
107
|
const setHasRunAnyCell = useSetAtom(hasRunAnyCellAtom);
|
|
110
108
|
|
|
111
109
|
const runCellsMemoized = useEvent(async (cellIds: CellId[]) => {
|
|
@@ -123,7 +121,6 @@ export function useRunCells() {
|
|
|
123
121
|
if (ev && getCurrentLanguageAdapter(ev) !== "markdown") {
|
|
124
122
|
closeCompletion(ev);
|
|
125
123
|
}
|
|
126
|
-
prepareForRun({ cellId });
|
|
127
124
|
}
|
|
128
125
|
return runCells(store, cellIds);
|
|
129
126
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { closeCompletion, completionStatus } from "@codemirror/autocomplete";
|
|
3
3
|
import type { EditorView } from "@codemirror/view";
|
|
4
4
|
import clsx from "clsx";
|
|
5
|
-
import { useAtomValue, useSetAtom
|
|
5
|
+
import { useAtomValue, useSetAtom } from "jotai";
|
|
6
6
|
import {
|
|
7
7
|
HelpCircleIcon,
|
|
8
8
|
MoreHorizontalIcon,
|
|
@@ -44,13 +44,11 @@ import {
|
|
|
44
44
|
type CellExecutionView,
|
|
45
45
|
type CellFreshness,
|
|
46
46
|
type CellRunStatus,
|
|
47
|
-
replyInput,
|
|
48
47
|
useCellPresentation,
|
|
49
48
|
useCellOutline,
|
|
50
49
|
useCellOutput,
|
|
51
50
|
} from "@/core/executions";
|
|
52
|
-
import
|
|
53
|
-
import type { OutputMessage } from "@/core/kernel/messages";
|
|
51
|
+
import { useAnswerPrompt } from "@/core/cells/useAnswerPrompt";
|
|
54
52
|
import type { CellConfig } from "@/core/network/types";
|
|
55
53
|
import { useResizeObserver } from "@/hooks/useResizeObserver";
|
|
56
54
|
import { cn } from "@/utils/cn";
|
|
@@ -244,30 +242,6 @@ export interface CellHandle {
|
|
|
244
242
|
editorViewOrNull: EditorView | null;
|
|
245
243
|
}
|
|
246
244
|
|
|
247
|
-
/**
|
|
248
|
-
* Answer the prompt at `index` of the cell's console through the host.
|
|
249
|
-
*
|
|
250
|
-
* The console entry is marked answered right away, as before. The reply
|
|
251
|
-
* itself names the prompt, so the host can mark it answered and turn away
|
|
252
|
-
* a late reply meant for an earlier prompt.
|
|
253
|
-
*/
|
|
254
|
-
function useAnswerPrompt(
|
|
255
|
-
cellId: CellId,
|
|
256
|
-
consoleOutputs: readonly WithResponse<OutputMessage>[],
|
|
257
|
-
) {
|
|
258
|
-
const store = useStore();
|
|
259
|
-
const actions = useCellActions();
|
|
260
|
-
return useEvent((text: string, index: number) => {
|
|
261
|
-
actions.setStdinResponse({ cellId, response: text, outputIndex: index });
|
|
262
|
-
const prompt = consoleOutputs[index];
|
|
263
|
-
if (prompt?.input_id === undefined) {
|
|
264
|
-
Logger.error("The prompt has no id to answer it by", prompt);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
void replyInput(store, prompt.input_id, text);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
245
|
export interface CellProps {
|
|
272
246
|
cellId: CellId;
|
|
273
247
|
theme: Theme;
|
|
@@ -431,7 +405,7 @@ const EditableCellComponent = ({
|
|
|
431
405
|
const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
|
|
432
406
|
const deleteCell = useDeleteCellCallback();
|
|
433
407
|
const runCell = useRunCell(cellId);
|
|
434
|
-
const answerPrompt = useAnswerPrompt(cellId
|
|
408
|
+
const answerPrompt = useAnswerPrompt(cellId);
|
|
435
409
|
const isPendingCut = useIsPendingCut(cellId);
|
|
436
410
|
|
|
437
411
|
const [languageAdapter, setLanguageAdapter] = useState<LanguageAdapterType>();
|
|
@@ -835,7 +809,6 @@ const EditableCellComponent = ({
|
|
|
835
809
|
<ConsoleOutput
|
|
836
810
|
consoleOutputs={cellRuntime.consoleOutputs}
|
|
837
811
|
stale={consoleOutputStale}
|
|
838
|
-
interrupted={interrupted}
|
|
839
812
|
// Empty name if serialization triggered
|
|
840
813
|
cellName={cellRuntime.serialization ? "_" : cellData.name}
|
|
841
814
|
onRefactorWithAI={handleRefactorWithAI}
|
|
@@ -847,7 +820,6 @@ const EditableCellComponent = ({
|
|
|
847
820
|
}}
|
|
848
821
|
onSubmitDebugger={answerPrompt}
|
|
849
822
|
cellId={cellId}
|
|
850
|
-
debuggerActive={cellRuntime.debuggerActive}
|
|
851
823
|
/>
|
|
852
824
|
)}
|
|
853
825
|
<PendingDeleteConfirmation cellId={cellId} />
|
|
@@ -1067,7 +1039,6 @@ const SetupCellComponent = ({
|
|
|
1067
1039
|
const output = useCellOutput(cellId);
|
|
1068
1040
|
const { execution, freshness } = useCellPresentation(cellId);
|
|
1069
1041
|
const errored = execution.outcome === "error";
|
|
1070
|
-
const interrupted = execution.outcome === "interrupted";
|
|
1071
1042
|
const stopped = execution.outcome === "skipped";
|
|
1072
1043
|
const cellActionDropdownRef = useRef<CellActionsDropdownHandle>(null);
|
|
1073
1044
|
// DOM node where the editorView will be mounted
|
|
@@ -1078,7 +1049,7 @@ const SetupCellComponent = ({
|
|
|
1078
1049
|
const deleteCell = useDeleteCellCallback();
|
|
1079
1050
|
const setAiCompletionCell = useSetAtom(aiCompletionCellAtom);
|
|
1080
1051
|
const runCell = useRunCell(cellId);
|
|
1081
|
-
const answerPrompt = useAnswerPrompt(cellId
|
|
1052
|
+
const answerPrompt = useAnswerPrompt(cellId);
|
|
1082
1053
|
|
|
1083
1054
|
const uninstantiated = isUninstantiated(execution);
|
|
1084
1055
|
|
|
@@ -1293,7 +1264,6 @@ const SetupCellComponent = ({
|
|
|
1293
1264
|
<ConsoleOutput
|
|
1294
1265
|
consoleOutputs={cellRuntime.consoleOutputs}
|
|
1295
1266
|
stale={consoleOutputStale}
|
|
1296
|
-
interrupted={interrupted}
|
|
1297
1267
|
// Don't show name
|
|
1298
1268
|
cellName={"_"}
|
|
1299
1269
|
onRefactorWithAI={handleRefactorWithAI}
|
|
@@ -1305,7 +1275,6 @@ const SetupCellComponent = ({
|
|
|
1305
1275
|
}}
|
|
1306
1276
|
onSubmitDebugger={answerPrompt}
|
|
1307
1277
|
cellId={cellId}
|
|
1308
|
-
debuggerActive={cellRuntime.debuggerActive}
|
|
1309
1278
|
/>
|
|
1310
1279
|
</div>
|
|
1311
1280
|
</div>
|
|
@@ -13,6 +13,21 @@ export interface Cursor {
|
|
|
13
13
|
export class TerminalBuffer {
|
|
14
14
|
private lines: string[] = [""];
|
|
15
15
|
private cursor: Cursor = { row: 0, col: 0 };
|
|
16
|
+
|
|
17
|
+
// The cursor is relative to the retained lines. Absolute ANSI positions
|
|
18
|
+
// still refer to the original screen after old lines have been discarded.
|
|
19
|
+
private firstRow: number;
|
|
20
|
+
|
|
21
|
+
public constructor(firstRow = 0) {
|
|
22
|
+
this.firstRow = firstRow;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public copy(dropLines = 0): TerminalBuffer {
|
|
26
|
+
const copy = new TerminalBuffer(this.firstRow + dropLines);
|
|
27
|
+
copy.lines = this.lines.slice(dropLines);
|
|
28
|
+
copy.cursor = { row: this.cursor.row - dropLines, col: this.cursor.col };
|
|
29
|
+
return copy;
|
|
30
|
+
}
|
|
16
31
|
private static readonly ESCAPE_REGEX = new RegExp(
|
|
17
32
|
String.raw`\u001B\[([0-9;]*)([A-DJKH])`,
|
|
18
33
|
"u",
|
|
@@ -27,7 +42,7 @@ export class TerminalBuffer {
|
|
|
27
42
|
|
|
28
43
|
/** Move cursor by relative offsets. */
|
|
29
44
|
private moveCursor(rowDelta: number, colDelta: number) {
|
|
30
|
-
this.cursor.row = Math.max(
|
|
45
|
+
this.cursor.row = Math.max(-this.firstRow, this.cursor.row + rowDelta);
|
|
31
46
|
this.cursor.col = Math.max(0, this.cursor.col + colDelta);
|
|
32
47
|
this.ensureLine(this.cursor.row);
|
|
33
48
|
// Cursor movement does not erase content. This matters for multi-line
|
|
@@ -36,24 +51,20 @@ export class TerminalBuffer {
|
|
|
36
51
|
|
|
37
52
|
/** Move cursor to a specific absolute position. */
|
|
38
53
|
private setCursor(row: number, col: number) {
|
|
39
|
-
this.cursor.row = Math.max(0, row);
|
|
54
|
+
this.cursor.row = Math.max(0, row) - this.firstRow;
|
|
40
55
|
this.cursor.col = Math.max(0, col);
|
|
41
56
|
this.ensureLine(this.cursor.row);
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
/** Write a visible character at the current cursor position. */
|
|
45
60
|
public writeChar(ch: string) {
|
|
46
|
-
this.
|
|
47
|
-
const line = this.lines[this.cursor.row];
|
|
48
|
-
const padded = line.padEnd(this.cursor.col, " ");
|
|
49
|
-
this.lines[this.cursor.row] =
|
|
50
|
-
padded.slice(0, this.cursor.col) + ch + padded.slice(this.cursor.col + 1);
|
|
51
|
-
this.cursor.col++;
|
|
61
|
+
this.writeString(ch);
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
/** Write a string of visible characters at the current cursor position (optimized batch write). */
|
|
55
65
|
public writeString(str: string) {
|
|
56
|
-
if (str.length === 0) {
|
|
66
|
+
if (this.cursor.row < 0 || str.length === 0) {
|
|
67
|
+
this.cursor.col += str.length;
|
|
57
68
|
return;
|
|
58
69
|
}
|
|
59
70
|
this.ensureLine(this.cursor.row);
|
|
@@ -131,10 +142,14 @@ export class TerminalBuffer {
|
|
|
131
142
|
case "J": // Erase in display
|
|
132
143
|
if (params[0] === 2) {
|
|
133
144
|
this.lines = [""];
|
|
145
|
+
this.firstRow = 0;
|
|
134
146
|
this.setCursor(0, 0);
|
|
135
147
|
}
|
|
136
148
|
break;
|
|
137
149
|
case "K": // Erase line
|
|
150
|
+
if (this.cursor.row < 0) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
138
153
|
this.ensureLine(this.cursor.row);
|
|
139
154
|
switch (params[0]) {
|
|
140
155
|
case 0:
|
|
@@ -215,7 +230,23 @@ export class AnsiParser {
|
|
|
215
230
|
*/
|
|
216
231
|
export class AnsiReducer {
|
|
217
232
|
private parser = new AnsiParser();
|
|
218
|
-
private buffer
|
|
233
|
+
private buffer: TerminalBuffer;
|
|
234
|
+
private incompleteEscape = "";
|
|
235
|
+
private static readonly INCOMPLETE_ESCAPE = new RegExp(
|
|
236
|
+
String.raw`\u001B(?:\[[0-9;]*|\()?$`,
|
|
237
|
+
"u",
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
public constructor(firstRow = 0) {
|
|
241
|
+
this.buffer = new TerminalBuffer(firstRow);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public copy(dropLines = 0): AnsiReducer {
|
|
245
|
+
const copy = new AnsiReducer();
|
|
246
|
+
copy.buffer = this.buffer.copy(dropLines);
|
|
247
|
+
copy.incompleteEscape = this.incompleteEscape;
|
|
248
|
+
return copy;
|
|
249
|
+
}
|
|
219
250
|
|
|
220
251
|
/**
|
|
221
252
|
* Process the entire input string (replaces any previous state).
|
|
@@ -232,6 +263,13 @@ export class AnsiReducer {
|
|
|
232
263
|
* This is efficient for streaming scenarios - only processes the new chunk.
|
|
233
264
|
*/
|
|
234
265
|
public append(input: string): void {
|
|
266
|
+
input = this.incompleteEscape + input;
|
|
267
|
+
// A pipe read can split a CSI or character-set sequence at any byte.
|
|
268
|
+
const partial = AnsiReducer.INCOMPLETE_ESCAPE.exec(input);
|
|
269
|
+
this.incompleteEscape = partial?.[0] ?? "";
|
|
270
|
+
if (partial) {
|
|
271
|
+
input = input.slice(0, partial.index);
|
|
272
|
+
}
|
|
235
273
|
const tokens = this.parser.parse(input);
|
|
236
274
|
|
|
237
275
|
// Fast path: if only one text token (no ANSI codes), handle directly
|
|
@@ -262,6 +300,7 @@ export class AnsiReducer {
|
|
|
262
300
|
*/
|
|
263
301
|
public reset(): void {
|
|
264
302
|
this.buffer = new TerminalBuffer();
|
|
303
|
+
this.incompleteEscape = "";
|
|
265
304
|
}
|
|
266
305
|
|
|
267
306
|
/**
|
|
@@ -361,6 +400,20 @@ export type StringOutputMessage = Omit<OutputMessage, "data"> & {
|
|
|
361
400
|
id?: number;
|
|
362
401
|
};
|
|
363
402
|
|
|
403
|
+
/** Plain writes can extend the rendered string until a control code needs a terminal. */
|
|
404
|
+
function plainLineCount(text: string): number | undefined {
|
|
405
|
+
let count = 1;
|
|
406
|
+
for (let i = 0; i < text.length; i++) {
|
|
407
|
+
const code = text.charCodeAt(i);
|
|
408
|
+
if (code === 10) {
|
|
409
|
+
count++;
|
|
410
|
+
} else if (code < 32) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return count;
|
|
415
|
+
}
|
|
416
|
+
|
|
364
417
|
/**
|
|
365
418
|
* Immutable output message that maintains ANSI state across appends.
|
|
366
419
|
* This is used with react so must be immutable.
|
|
@@ -373,64 +426,74 @@ export class StatefulOutputMessage implements OutputMessage {
|
|
|
373
426
|
public readonly id: StringOutputMessage["id"];
|
|
374
427
|
/** The prompt this entry is, when it asks for input. A reply names it. */
|
|
375
428
|
public readonly input_id: OutputMessage["input_id"];
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
429
|
+
public readonly data: string;
|
|
430
|
+
public readonly lineCount: number;
|
|
431
|
+
private readonly terminal?: AnsiReducer;
|
|
432
|
+
private readonly firstPlainRow: number;
|
|
433
|
+
|
|
434
|
+
private constructor(
|
|
435
|
+
message: StringOutputMessage,
|
|
436
|
+
state: {
|
|
437
|
+
data: string;
|
|
438
|
+
lineCount: number;
|
|
439
|
+
terminal?: AnsiReducer;
|
|
440
|
+
firstPlainRow?: number;
|
|
441
|
+
},
|
|
442
|
+
) {
|
|
443
|
+
this.data = state.data;
|
|
444
|
+
this.lineCount = state.lineCount;
|
|
445
|
+
this.terminal = state.terminal;
|
|
446
|
+
this.firstPlainRow = state.firstPlainRow ?? 0;
|
|
447
|
+
this.mimetype = message.mimetype;
|
|
448
|
+
this.channel = message.channel;
|
|
449
|
+
this.timestamp = message.timestamp;
|
|
450
|
+
this.code = message.code;
|
|
451
|
+
this.id = message.id;
|
|
452
|
+
this.input_id = message.input_id;
|
|
381
453
|
}
|
|
382
454
|
|
|
383
455
|
public static create(message: StringOutputMessage): StatefulOutputMessage {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
channel: message.channel,
|
|
389
|
-
timestamp: message.timestamp,
|
|
390
|
-
ansiReducer,
|
|
391
|
-
code: message.code,
|
|
392
|
-
id: message.id,
|
|
393
|
-
input_id: message.input_id,
|
|
394
|
-
});
|
|
456
|
+
return new StatefulOutputMessage(message, {
|
|
457
|
+
data: "",
|
|
458
|
+
lineCount: 1,
|
|
459
|
+
}).appendData(message.data);
|
|
395
460
|
}
|
|
396
461
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
this
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
this.ansiReducer = ansiReducer;
|
|
421
|
-
this._data = this.ansiReducer.render();
|
|
462
|
+
public appendData(chunk: string): StatefulOutputMessage {
|
|
463
|
+
if (!this.terminal) {
|
|
464
|
+
const lines = plainLineCount(chunk);
|
|
465
|
+
if (lines !== undefined) {
|
|
466
|
+
return new StatefulOutputMessage(this, {
|
|
467
|
+
data: this.data + chunk,
|
|
468
|
+
lineCount: this.lineCount + lines - 1,
|
|
469
|
+
firstPlainRow: this.firstPlainRow,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const terminal =
|
|
474
|
+
this.terminal?.copy() ?? new AnsiReducer(this.firstPlainRow);
|
|
475
|
+
if (!this.terminal) {
|
|
476
|
+
terminal.append(this.data);
|
|
477
|
+
}
|
|
478
|
+
terminal.append(chunk);
|
|
479
|
+
const data = terminal.render();
|
|
480
|
+
return new StatefulOutputMessage(this, {
|
|
481
|
+
data,
|
|
482
|
+
lineCount: data.split("\n").length,
|
|
483
|
+
terminal,
|
|
484
|
+
});
|
|
422
485
|
}
|
|
423
486
|
|
|
424
|
-
public
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
487
|
+
public dropFirstLines(count: number): StatefulOutputMessage {
|
|
488
|
+
if (count === 0) {
|
|
489
|
+
return this;
|
|
490
|
+
}
|
|
491
|
+
const terminal = this.terminal?.copy(count);
|
|
492
|
+
return new StatefulOutputMessage(this, {
|
|
493
|
+
data: terminal?.render() ?? this.data.split("\n").slice(count).join("\n"),
|
|
494
|
+
lineCount: this.lineCount - count,
|
|
495
|
+
terminal,
|
|
496
|
+
firstPlainRow: this.firstPlainRow + count,
|
|
434
497
|
});
|
|
435
498
|
}
|
|
436
499
|
|
|
@@ -78,11 +78,9 @@ interface Props {
|
|
|
78
78
|
className?: string;
|
|
79
79
|
consoleOutputs: ConsoleOutputMessage[];
|
|
80
80
|
stale: boolean;
|
|
81
|
-
interrupted: boolean;
|
|
82
|
-
debuggerActive: boolean;
|
|
83
81
|
onRefactorWithAI?: OnRefactorWithAI;
|
|
84
82
|
onClear?: () => void;
|
|
85
|
-
onSubmitDebugger: (text: string,
|
|
83
|
+
onSubmitDebugger: (text: string, inputId?: string) => void;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
export const ConsoleOutput = (props: Props) => {
|
|
@@ -105,7 +103,6 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
|
|
|
105
103
|
const {
|
|
106
104
|
consoleOutputs: rawConsoleOutputs,
|
|
107
105
|
stale,
|
|
108
|
-
interrupted,
|
|
109
106
|
cellName,
|
|
110
107
|
cellId,
|
|
111
108
|
onSubmitDebugger,
|
|
@@ -117,17 +114,6 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
|
|
|
117
114
|
// Debounce clearing to prevent flickering when cells re-run
|
|
118
115
|
const consoleOutputs = useDebouncedConsoleOutputs(rawConsoleOutputs);
|
|
119
116
|
|
|
120
|
-
/* The debugger UI needs some work. For now just use the regular
|
|
121
|
-
/* console output. */
|
|
122
|
-
/* if (debuggerActive) {
|
|
123
|
-
return (
|
|
124
|
-
<Debugger
|
|
125
|
-
code={consoleOutputs.map((output) => output.data).join("\n")}
|
|
126
|
-
onSubmit={(text) => onSubmitDebugger(text, consoleOutputs.length - 1)}
|
|
127
|
-
/>
|
|
128
|
-
);
|
|
129
|
-
} */
|
|
130
|
-
|
|
131
117
|
const kioskMode = useAtomValue(kioskModeAtom);
|
|
132
118
|
const prompt = useAtomValue(pendingPdbInputAtom);
|
|
133
119
|
const pdbInput =
|
|
@@ -280,14 +266,14 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
|
|
|
280
266
|
|
|
281
267
|
const isPassword = output.mimetype === "text/password";
|
|
282
268
|
|
|
283
|
-
if (output.response
|
|
269
|
+
if (output.response === undefined && lastStdInputIdx === idx) {
|
|
284
270
|
return (
|
|
285
271
|
<StdInput
|
|
286
272
|
key={key}
|
|
287
273
|
output={output.data}
|
|
288
274
|
isPdb={isPdb}
|
|
289
275
|
isPassword={isPassword}
|
|
290
|
-
onSubmit={(text) => onSubmitDebugger(text,
|
|
276
|
+
onSubmit={(text) => onSubmitDebugger(text, output.input_id)}
|
|
291
277
|
onClear={onClear}
|
|
292
278
|
value={stdinValue}
|
|
293
279
|
setValue={setStdinValue}
|
|
@@ -302,7 +288,6 @@ const ConsoleOutputInternal = (props: Props): React.ReactNode => {
|
|
|
302
288
|
output={output.data}
|
|
303
289
|
response={output.response}
|
|
304
290
|
isPassword={isPassword}
|
|
305
|
-
interrupted={interrupted}
|
|
306
291
|
/>
|
|
307
292
|
);
|
|
308
293
|
}
|
|
@@ -405,24 +390,21 @@ const StdInput = (props: {
|
|
|
405
390
|
|
|
406
391
|
const StdInputWithResponse = (props: {
|
|
407
392
|
output: string;
|
|
408
|
-
response?: string;
|
|
393
|
+
response?: string | null;
|
|
409
394
|
isPassword?: boolean;
|
|
410
|
-
interrupted?: boolean;
|
|
411
395
|
}) => {
|
|
412
|
-
const { output, response, isPassword
|
|
413
|
-
const hasResponse = response != null && response !== "";
|
|
414
|
-
const wasInterruptedWithoutResponse = interrupted && !hasResponse;
|
|
396
|
+
const { output, response, isPassword } = props;
|
|
415
397
|
|
|
416
398
|
return (
|
|
417
399
|
<div className="flex gap-2 items-center">
|
|
418
400
|
{renderText(output)}
|
|
419
|
-
{!isPassword &&
|
|
401
|
+
{!isPassword && response != null && (
|
|
420
402
|
<span
|
|
421
403
|
className="inline-flex items-center gap-1 text-(--sky-11)"
|
|
422
404
|
aria-label="stdin response"
|
|
423
405
|
>
|
|
424
406
|
<ChevronRightIcon className="w-4 h-4 shrink-0 opacity-70" />
|
|
425
|
-
{
|
|
407
|
+
{response !== "" ? (
|
|
426
408
|
response
|
|
427
409
|
) : (
|
|
428
410
|
<span className="italic opacity-70">(empty)</span>
|