Skip to content
Open
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
16 changes: 16 additions & 0 deletions website/src/lib/tutorial-shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ describe("TutorialShell program dispatch", () => {
expect(output.join("")).toContain("$ ");
});

it("forwards trailing bytes to a program launched within the same chunk", () => {
const { program, shell, startProgram } = createHarness();

// A single chunk (e.g. a paste) both launches the program and carries the
// first keystroke for it. The trailing `q` must reach the program, not the
// shell line editor.
shell.handleInput("ascii-splash --no-mouse\rq");

expect(startProgram).toHaveBeenCalledWith(
"ascii-splash",
["--no-mouse"],
expect.any(Function),
);
expect(program.handleInput).toHaveBeenCalledWith("q");
});

it("disposes the active program with the shell", () => {
const { program, shell } = createHarness();

Expand Down
8 changes: 8 additions & 0 deletions website/src/lib/tutorial-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ export class TutorialShell {
this.lineBuffer = '';
this.historyIndex = null;
this.historyDraft = '';
// `processCommand` may have launched an interactive program. Any bytes
// left in this chunk (e.g. a paste of `cmd\rinput`) belong to that
// program, not the shell line editor — forward them and stop parsing.
if (this.activeProgram) {
const rest = data.slice(index + 1);
if (rest) this.activeProgram.handleInput(rest);
return;
}
} else if (ch === '\x7f' || ch === '\b') {
if (this.lineBuffer.length > 0) {
this.lineBuffer = this.lineBuffer.slice(0, -1);
Expand Down
Loading