Skip to content

Commit 1375977

Browse files
tarasclaude
andcommitted
feat(repl): replace the loop checkbox with an ∞ toggle
Follow the revised Flow 1 spec. The loop toggle draws only ∞, is named loop and exposes whether it is pressed: cyan #7ed3e8 while on and grey #7b858d while off, focus included. Enter or Space toggles it in place. The tray draws and walks Stop, ∞, Send; the toggle's own three cells space it from the filled buttons, and Send keeps its fill on the box edge. The tray's own palette entries take the spec's exact button fill and title colours. Tests read the toggle's state from its ink at capture, and the Flow 1 regression covers both states, keyboard focus and toggling, order and colours at 160x36 and 120x30. Refs #1526 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 40e04fc commit 1375977

17 files changed

Lines changed: 314 additions & 127 deletions

‎examples/repl-bench/journeys/layout-queue.test.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<Terminal.WaitForText text="Queue gate held" />
7777

7878
<Terminal.Focus target="sidekick-composer" />
79-
<Terminal.WaitForText text="]loop" as="controls" />
79+
<Terminal.WaitForText text="∞" as="controls" />
8080
<Terminal.WaitForText text="Stop" row={controls.row} />
8181
<Terminal.WaitForText text="Send" row={controls.row} />
8282
<Each in={["Wait for tax check.", "Send results later."]} let="message">

‎examples/repl-bench/journeys/repl-inline-recovery.test.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<ReplBench.Key key="Alt+ArrowUp" />
1616
<ReplBench.WaitForText text=">Send" bold={true} />
1717
<ReplBench.Key key="Alt+ArrowUp" />
18+
<ReplBench.WaitForText text=">∞" bold={true} />
19+
<ReplBench.Key key="Alt+ArrowUp" />
1820
<ReplBench.WaitForText text=">Stop" bold={true} />
1921
<ReplBench.Key key="Enter" />
2022
<ReplBench.WaitForText text=" Stop " present={false} />

‎examples/repl-bench/tests/screen.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Deno.test("finds the composer's bordered input whatever it holds, and reads focu
3737
[REPL_PALETTE.muted, "Hello World!", false],
3838
] satisfies readonly (readonly [number, string, boolean])[]) {
3939
const { backend, screen } = screenOf([
40-
" [x]loop Send ",
40+
" ∞ Send ",
4141
...boxed(edge, held, 1, 40),
4242
" [exit]",
4343
]);

‎packages/cli/src/repl/application.ts‎

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import {
8787
TAB_GAP,
8888
BUTTON_GAP,
8989
BUTTON_PROPS,
90+
LOOP_PROPS,
9091
workspaceBlockProps,
9192
workspaceBodyProps,
9293
workspaceColumnProps,
@@ -13672,39 +13673,35 @@ function workspaceControls(
1367213673
),
1367313674
);
1367413675
}
13675-
if (workspace.follow !== undefined) {
13676-
items.push(
13677-
row(
13678-
"follow",
13679-
`[${workspace.follow ? "x" : " "}]loop`,
13680-
{ select: "toggle-follow" },
13681-
// The tray row is unshaded: its controls carry no surface of their own.
13682-
styleOf("navigate"),
13683-
{
13684-
here: view.focused,
13685-
runs: [
13686-
{ text: `[${workspace.follow ? "x" : " "}]`, token: "checkbox" },
13687-
{ text: "loop", token: "output" },
13688-
],
13689-
},
13690-
),
13691-
);
13692-
}
1369313676
if (reading.busy) {
1369413677
items.push(
13695-
row("sidekick:stop", "Stop", { select: "stop-sidekick" }, styleOf("failed-outcome"), {
13678+
row("sidekick:stop", "Stop", { select: "stop-sidekick" }, styleOf("stop-title"), {
1369613679
here: view.focused,
1369713680
button: true,
1369813681
}),
1369913682
);
1370013683
}
13684+
// Described in the order drawn, which is the order the keyboard walks.
13685+
if (workspace.follow !== undefined) {
13686+
items.push(
13687+
// Only the glyph is drawn: its name and whether it is pressed travel
13688+
// with the control rather than as words on the row.
13689+
row(
13690+
"follow",
13691+
"∞",
13692+
{ select: "toggle-follow", name: "loop", pressed: workspace.follow },
13693+
styleOf(workspace.follow ? "loop-on" : "loop-off"),
13694+
{ here: view.focused, button: true },
13695+
),
13696+
);
13697+
}
1370113698
// Dim while there is nothing to send, as the Draft's own Send is.
1370213699
items.push(
1370313700
row(
1370413701
"sidekick:send",
1370513702
"Send",
1370613703
{ select: "send-message" },
13707-
styleOf(state.message.length === 0 ? "inactive" : "navigate"),
13704+
styleOf(state.message.length === 0 ? "inactive" : "button-title"),
1370813705
{ here: view.focused, button: true },
1370913706
),
1371013707
);
@@ -14821,27 +14818,29 @@ function workspacePresentation(input: {
1482114818
}
1482214819
const left = parts(headerKeysOf(spec.left, candidates), region, surface);
1482314820
const grouped = parts(headerKeysOf(spec.right, candidates), region, surface);
14824-
// The tray's Stop and Send are filled buttons one cell apart.
14825-
const buttons = grouped.filter(
14826-
(one) => one.key === "sidekick:stop" || one.key === "sidekick:send",
14827-
);
14821+
// The tray's actions in their own order: Stop, the loop toggle, Send. The
14822+
// toggle's own cells space it from the filled buttons beside it; without
14823+
// it, the buttons sit one cell apart.
14824+
const actions =
14825+
id === "tray"
14826+
? ["sidekick:stop", "follow", "sidekick:send"].flatMap((key) =>
14827+
grouped.filter((one) => one.key === key),
14828+
)
14829+
: [];
1482814830
const right =
14829-
id !== "tray" || buttons.length === 0
14831+
actions.length === 0
1483014832
? grouped
14831-
: grouped.flatMap((one) =>
14832-
one === buttons[0]
14833-
? [
14834-
box({
14835-
id: "box:tray:buttons",
14836-
region,
14837-
props: fittedRowProps(BUTTON_GAP),
14838-
children: buttons.map((button) => box({ ...button, props: BUTTON_PROPS })),
14839-
}),
14840-
]
14841-
: buttons.includes(one)
14842-
? []
14843-
: [one],
14844-
);
14833+
: [
14834+
box({
14835+
id: "box:tray:buttons",
14836+
region,
14837+
props: fittedRowProps(actions.some((one) => one.key === "follow") ? 0 : BUTTON_GAP),
14838+
children: actions.map((one) =>
14839+
box({ ...one, props: one.key === "follow" ? LOOP_PROPS : BUTTON_PROPS }),
14840+
),
14841+
}),
14842+
...grouped.filter((one) => !actions.includes(one)),
14843+
];
1484514844
if (left.length === 0 && right.length === 0) {
1484614845
return [];
1484714846
}

‎packages/cli/src/repl/components/rows.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ export const SELECT_ROW: ReplComponent<ReplAction> = component<ReplAction>({
172172
if (event.text === " " && input?.["select"] === "toggle-usage") {
173173
return { kind: "toggle-usage" };
174174
}
175+
if (event.text === " " && input?.["select"] === "toggle-follow") {
176+
return { kind: "toggle-follow" };
177+
}
175178
if (event.text === " " && input?.["select"] === "pane" && input["pane"] === "todo") {
176179
return { kind: "select-pane", pane: "todo" };
177180
}

‎packages/cli/src/repl/layout.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,18 @@ export const BUTTON_PROPS: ReplBoxProps = Object.freeze({
614614
bg: terminalColour(REPL_PALETTE.buttonSurface),
615615
});
616616

617+
/**
618+
* The tray's loop toggle: its marker cell, its glyph and one cell after, on the
619+
* pane's own surface. Focus fills all three with the focus surface.
620+
*/
621+
export const LOOP_PROPS: ReplBoxProps = Object.freeze({
622+
layout: Object.freeze({
623+
width: fit(),
624+
height: fixed(1),
625+
padding: Object.freeze({ right: 1 }),
626+
}),
627+
});
628+
617629
/**
618630
* How many blank rows each shared column keeps above its first heading.
619631
*

‎packages/cli/src/repl/presentation-style.ts‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ export type ReplPresentationRole =
7878
| "interrupted-outcome"
7979
/** Something that has not settled, and the affordance that attends to it. */
8080
| "waiting"
81-
/** A checkbox's brackets and mark, beside the label it sets. */
82-
| "checkbox"
81+
/** The Sidekick's loop toggle while it is on. */
82+
| "loop-on"
83+
/** The Sidekick's loop toggle while it is off, which focus does not brighten. */
84+
| "loop-off"
85+
/** A tray button's title while it has something to act on. */
86+
| "button-title"
87+
/** The tray's Stop button title. */
88+
| "stop-title"
8389
/** A control that has nothing to act on yet. */
8490
| "inactive"
8591
/** Something activating does. */
@@ -317,9 +323,15 @@ export const REPL_PALETTE = Object.freeze({
317323
/** The tray and the Sidekick's composer. */
318324
composerSurface: 0x0d1215,
319325
/** The fill of the Sidekick's Stop and Send buttons. */
320-
buttonSurface: 0x171d21,
326+
buttonSurface: 0x151d21,
327+
/** A tray button's title while it has something to act on. */
328+
buttonTitle: 0xe6ecf0,
321329
/** A button's title while it has nothing to act on. */
322-
inactiveAction: 0x4b5258,
330+
inactiveAction: 0x495259,
331+
/** The tray's Stop title. */
332+
stopTitle: 0xc3756e,
333+
/** The Sidekick's loop toggle while it is on; off is muted. */
334+
loopOn: 0x7ed3e8,
323335
/** The one-cell rule between two columns. */
324336
paneDivider: 0x1c252b,
325337
/** A message waiting behind the active exchange. */
@@ -487,8 +499,14 @@ function colourOf(role: ReplPresentationRole, inspected: boolean): number {
487499
case "metadata":
488500
case "field-hint":
489501
return REPL_PALETTE.muted;
490-
case "checkbox":
491-
return REPL_PALETTE.focus;
502+
case "loop-on":
503+
return REPL_PALETTE.loopOn;
504+
case "loop-off":
505+
return REPL_PALETTE.muted;
506+
case "button-title":
507+
return REPL_PALETTE.buttonTitle;
508+
case "stop-title":
509+
return REPL_PALETTE.stopTitle;
492510
case "inactive":
493511
return REPL_PALETTE.inactiveAction;
494512
case "successful-outcome":

‎packages/cli/tests/repl-page.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function composerShown(reading: ScreenReading): boolean {
4040
return reading.composer !== undefined;
4141
}
4242

43-
/** The Sidekick's checked loop toggle, which shares its row with the Sidekick's Send. */
44-
const LOOP = "[x]loop";
43+
/** The Sidekick's loop toggle, which shares its row with the Sidekick's Send. */
44+
const LOOP = "∞";
4545

4646
/** The Sidekick's own Send, scoped by the one bounded layout statement made here. */
4747
const SIDEKICK_SEND: ScreenScope = { onRow: LOOP, rightOf: LOOP };

‎packages/cli/tests/repl-presentation-style.test.ts‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ import { journalModel, emptyModel } from "./fixtures/repl/journals.ts";
118118
import { referenceEvents } from "./fixtures/repl/reference.ts";
119119
import { QUEUE_WINDOW } from "../src/repl/application.ts";
120120
import { readDescription } from "../src/repl/description.ts";
121-
import { useCountingRenderer } from "./fixtures/repl/presentation.ts";
121+
import type { ReplDescription } from "../src/repl/description.ts";
122+
import { measuringContext, useCountingRenderer } from "./fixtures/repl/presentation.ts";
122123
import { useReplRenderer } from "../src/repl/renderer.ts";
123124
import { useReplPage } from "./support/repl-page.ts";
124125
import type { ReplPage, ScreenReading } from "./support/repl-page.ts";
@@ -1073,6 +1074,49 @@ describe("REPL appearance - the shipping profiles' geometry", () => {
10731074
describe("REPL appearance - the archive's inks, from the mounted terminal", () => {
10741075
beforeAll(() => useTempFileCompiler());
10751076

1077+
it("F1: the loop toggle draws only its glyph, names itself loop and exposes whether it is pressed", function* () {
1078+
const model = yield* settledFailedAndRunning();
1079+
const presenter = yield* usePresenter(WIDE);
1080+
const live: ReplLive = { ...NOTHING_LIVE, sidekick: SIDEKICK_QUIET };
1081+
for (const follow of [true, false]) {
1082+
const view = withWorkspace(reading(stateWith({}), model, live, WIDE), {
1083+
...workspaceOf(model),
1084+
follow,
1085+
});
1086+
const found: { key: string; input: unknown }[] = [];
1087+
const walk = (description: ReplDescription<ReplAction>): void => {
1088+
const read = readDescription(description);
1089+
if (read.key === "follow") {
1090+
found.push({ key: read.key, input: read.input });
1091+
}
1092+
read.children.forEach(walk);
1093+
};
1094+
presentationFor(view, measuringContext(WIDE)).descriptions.forEach(walk);
1095+
expect(found).toEqual([
1096+
{
1097+
key: "follow",
1098+
input: expect.objectContaining({
1099+
label: "∞",
1100+
name: "loop",
1101+
pressed: follow,
1102+
select: "toggle-follow",
1103+
}),
1104+
},
1105+
]);
1106+
const observed = yield* presenter.commit(view);
1107+
const toggle = placed(observed, "follow");
1108+
// Marker cell, glyph, one cell after: all on the unshaded pane.
1109+
expect(toggle.width).toBe(3);
1110+
expect(presenter.grid.at(toggle.x + 1, toggle.y)).toBe("∞");
1111+
expect(presenter.grid.styleAt(toggle.x + 1, toggle.y).foreground).toBe(
1112+
follow ? 0x7ed3e8 : 0x7b858d,
1113+
);
1114+
for (let x = toggle.x; x < toggle.x + toggle.width; x += 1) {
1115+
expect(presenter.grid.styleAt(x, toggle.y).background).toBe(0x0a0c0e);
1116+
}
1117+
}
1118+
});
1119+
10761120
it("an outcome, a syntax role and the field surfaces are the archive's, and the grounds differ", function* () {
10771121
// The same screen the appearance rows read, composed from a journal that
10781122
// really ran: one entry settled, one failed, one still running, with both

‎packages/cli/tests/repl-sidekick-journey.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import {
130130
STOP,
131131
TRAY_CONTROLS,
132132
sidekickStopShown,
133+
LOOP,
133134
} from "./support/screen-journeys.ts";
134135

135136
const OWNER = "packages/cli/tests/repl-sidekick-journey.test.ts";
@@ -4452,8 +4453,8 @@ describe("Follow: submitted rounds in the running command", () => {
44524453
page.repl.fake.script({ reply: followSubmission("<Output>OFF-ROUND</Output>") });
44534454
yield* sendMessage(page, "one round only");
44544455
yield* cleaning.operation;
4455-
yield* page.press("[x]loop");
4456-
yield* page.until("unchecked live Follow", (one) => one.shows("[ ]loop"));
4456+
yield* page.press(LOOP, TRAY_CONTROLS);
4457+
yield* page.until("unchecked live Follow", (one) => one.loop === "released");
44574458
expect(page.repl.fake.prompts).toHaveLength(1);
44584459
release.resolve();
44594460
yield* savedReplies(page.repl, 1);
@@ -4474,7 +4475,7 @@ describe("Follow: submitted rounds in the running command", () => {
44744475
return (yield* settledReading(page.repl)).model.entries[1]?.terminal?.status === "ok";
44754476
});
44764477
expect(page.repl.fake.prompts).toHaveLength(3);
4477-
expect(page.screen().shows("[ ]loop")).toBe(true);
4478+
expect(page.screen().loop).toBe("released");
44784479
});
44794480
});
44804481

0 commit comments

Comments
 (0)