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 docs/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ From `md` width up, a hint line under the footer mirrors the TUI's hint bar. Idl

The leader followed by `t`, `w`, `s`, `z`, `r`, `c`, `l`, `b`, `o`, `x`, `p`, or `u` does what the matching bullet under [Leader commands](#leader-commands) describes, using the same controls the buttons use. In the browser, `r` is the sizing recovery command and `z` remains an alias. The focus keys `1`, `2`, and `3`–`9`, `0` address the list, the content pane, and terminal panes 1–8 with the same numbering. `Ctrl+Shift+Left` and `Ctrl+Shift+Right` switch projects exactly as they do in the TUI.

`Shift+Left` and `Shift+Right` walk the same ring — the list, the content pane, then each terminal pane — among whatever is on screen: a maximized terminal offers its panes alone, a maximized upper region the list and the content pane, and a narrow screen only the view its bottom navigation chose, which is what the TUI's fullscreen rules amount to. Stepping onto a pane while another is zoomed moves the zoom to it, as the TUI's fullscreen cycle does. A control inside a region — the sidebar's filter, a pane's toolbar — counts as that region; a keyboard nowhere on the ring (in the header or the footer, say) enters it at the near end. The chord is the page's wherever it is not typing, so it never reaches a pane as `ESC[1;2D`; in a text field it stays the browser's word selection.
`Shift+Left` and `Shift+Right` walk the same ring — the list, the content pane, then each terminal pane — among whatever is on screen: a maximized terminal offers its panes alone, a maximized upper region the list and the content pane, and a narrow screen only the view its bottom navigation chose, which is what the TUI's fullscreen rules amount to. Stepping onto a pane while another is zoomed moves the zoom to it, as the TUI's fullscreen cycle does. A control inside a region — the sidebar's filter, a pane's toolbar — counts as that region; a keyboard nowhere on the ring (in the header or the footer, say) enters it at the near end. The physical chord is the page's wherever it is not typing, so it never reaches a pane as `ESC[1;2D`; in a text field it stays the browser's word selection. To send `Shift+Left` to the active terminal instead, for example to answer a Codex question prompt, use the key bar's `⇧←` button.

`Shift+PageUp` and `Shift+PageDown` scroll the focused pane a page, as in the TUI — xterm.js binds them itself.

Expand Down
2 changes: 1 addition & 1 deletion docs/web-viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ From `md` width up, the project tabs run across the header or down the page's le

The terminal toolbar can add a pane, show panes as a grid or tabs (from `md` width up; below it the panel is always tabbed and the control is hidden, since a split grid would give each pane fewer columns than a command line needs), maximize the terminal panel, claim sizing for this screen, show or hide the on-screen key bar, and open a message form for the active pane. The key-bar toggle remains in the terminal toolbar. A project has up to 8 panes. Pane order and zoom are shared while the session runs; they are not restored after the session ends. A PTY has one size, so the client whose most recent key/paste/click/touch/wheel interaction claimed sizing determines the grid rendered by every client. A new connection, browser resize, focus change, or reconnect leaves the current owner in place; the terminal toolbar's sizing button remains available for manual recovery.

On phones and other narrow layouts, the bottom navigation switches among `Repo`, `Content`, and `Terminal`. Swiping the row of terminal tabs scrolls it and tapping a tab switches to it; to reorder by touch, rest a finger on a tab until it dims, then drag (a mouse still drags at once). Scrolling a list, the content pane or a terminal back to its top does not trigger the browser's pull-to-refresh; pulling down on the header or another fixed bar still refreshes. Touch-dragging a terminal scrolls it; the key bar supplies Escape, Tab, arrows, and control keys when a soft keyboard cannot. A soft keyboard opening does not resize the panes: the PTY keeps its grid and the pane shows the part of it around the cursor — the bottom of a full screen, the top of a terminal just opened — so a full-screen program is not made to repaint from the top every time the keyboard comes and goes. Layout changes made while the keyboard is up are applied once it closes. Its `Ctrl` button is a latch for the next typed character. The keyboard-bar preference is stored in the browser, so it can be changed from the terminal toolbar. The shortcut leader key is stored in the browser too, and can be rebound or switched off from the shortcut sheet.
On phones and other narrow layouts, the bottom navigation switches among `Repo`, `Content`, and `Terminal`. Swiping the row of terminal tabs scrolls it and tapping a tab switches to it; to reorder by touch, rest a finger on a tab until it dims, then drag (a mouse still drags at once). Scrolling a list, the content pane or a terminal back to its top does not trigger the browser's pull-to-refresh; pulling down on the header or another fixed bar still refreshes. Touch-dragging a terminal scrolls it; the key bar supplies Escape, Tab, Shift+Tab, arrows, Shift+Left (`⇧←`), and control keys when a soft keyboard cannot. A soft keyboard opening does not resize the panes: the PTY keeps its grid and the pane shows the part of it around the cursor — the bottom of a full screen, the top of a terminal just opened — so a full-screen program is not made to repaint from the top every time the keyboard comes and goes. Layout changes made while the keyboard is up are applied once it closes. Its `Ctrl` button is a latch for the next typed character. The keyboard-bar preference is stored in the browser, so it can be changed from the terminal toolbar. The shortcut leader key is stored in the browser too, and can be rebound or switched off from the shortcut sheet.

The message form (the pencil in the terminal toolbar, or the leader followed by `m`) exists because xterm's hidden input field drops and repeats characters from an IME on iPadOS, which makes Korean typed straight into a pane unreliable; an ordinary text field composes it correctly. Send writes the message into the active pane and presses Return, so it runs at once; Cmd/Ctrl+Return does the same from the keyboard, and Return alone adds a line. When the program has turned on bracketed paste, a multi-line message goes in as one paste rather than one command per line. Clear empties the field. A draft is kept per pane for the life of the page, so closing the form does not lose it. Voice adds one spoken phrase to the end of the draft through the browser's speech recognition, in the browser's language. It never sends; the text waits in the field to be checked. Chrome sends the audio to Google's speech service to recognize it, and Safari to Apple's. The button is missing where the browser has no speech recognition, such as Firefox. Browsers open the microphone only on `https://` or `http://localhost`, so over a plain `http://` address the button is dimmed and does nothing, its tooltip saying why; serve the viewer over HTTPS as [Notifications](notifications.md#web-push) describes. The operating system's own dictation, such as the microphone on a phone keyboard, works in the field everywhere. The TUI has no such form or voice button: it reads keys from the host terminal, whose IME already composes and whose dictation types straight in.

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion viewer-ui/dist/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions viewer-ui/src/components/terminal/TermKeyBar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @vitest-environment happy-dom

import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { ModifierLatch } from "../../hooks/terminal/useModifierLatch";
import { TermKeyBar } from "./TermKeyBar";

afterEach(cleanup);

function latch(): ModifierLatch {
return {
armed: false,
toggle: () => false,
clear: vi.fn(),
consume: (typed) => typed,
};
}

describe("TermKeyBar", () => {
it("sends Shift+Left to the active pane and clears modifier latches", () => {
const onKey = vi.fn();
const ctrl = latch();
const alt = latch();
render(<TermKeyBar onKey={onKey} ctrl={ctrl} alt={alt} onArm={vi.fn()} />);

fireEvent.click(screen.getByRole("button", { name: "Shift Left arrow" }));

expect(onKey).toHaveBeenCalledTimes(1);
expect(onKey).toHaveBeenCalledWith("shift-left");
expect(ctrl.clear).toHaveBeenCalledTimes(1);
expect(alt.clear).toHaveBeenCalledTimes(1);
});
});
10 changes: 10 additions & 0 deletions viewer-ui/src/lib/terminal/termKeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe("termKeySequence", () => {
expect(termKeySequence("shift-tab", true)).toBe("\x1b[Z");
});

it("Shift+Left sends the modified-arrow sequence in either cursor mode", () => {
expect(termKeySequence("shift-left")).toBe("\x1b[1;2D");
expect(termKeySequence("shift-left", true)).toBe("\x1b[1;2D");
});

it("Ctrl combinations send control bytes based on alphabetic order", () => {
// Ctrl-C = 3rd letter = 0x03, and so on down the list.
expect(termKeySequence("ctrl-b")).toBe("\x02");
Expand Down Expand Up @@ -186,6 +191,11 @@ describe("TERM_KEY_BAR", () => {
expect(labels[labels.indexOf("⇧Tab") + 1]).toBe("Alt");
});

it("includes Shift+Left beside the ordinary Left arrow", () => {
const keys = TERM_KEY_BAR.filter((item) => item.kind === "key").map((item) => item.key);
expect(keys[keys.indexOf("left") - 1]).toBe("shift-left");
});

it("the bar has no duplicate keys", () => {
const keys = TERM_KEY_BAR.map((k) => k.label);
expect(new Set(keys).size).toBe(keys.length);
Expand Down
3 changes: 3 additions & 0 deletions viewer-ui/src/lib/terminal/termKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type TermKey =
| "esc"
| "tab"
| "shift-tab"
| "shift-left"
| "ctrl-b"
| "ctrl-c"
| "ctrl-d"
Expand All @@ -37,6 +38,7 @@ export const TERM_KEY_SEQUENCES: Record<TermKey, string> = {
esc: "\x1b",
tab: "\t",
"shift-tab": "\x1b[Z",
"shift-left": "\x1b[1;2D",
"ctrl-b": "\x02",
"ctrl-c": "\x03",
"ctrl-d": "\x04",
Expand Down Expand Up @@ -210,6 +212,7 @@ export const TERM_KEY_BAR: TermBarItem[] = [
{ kind: "key", key: "ctrl-z", label: "^Z", aria: "Control Z" },
{ kind: "key", key: "ctrl-l", label: "^L", aria: "Control L" },
{ kind: "key", key: "ctrl-r", label: "^R", aria: "Control R" },
{ kind: "key", key: "shift-left", label: "⇧←", aria: "Shift Left arrow" },
{ kind: "key", key: "left", label: "←", aria: "Left arrow" },
{ kind: "key", key: "down", label: "↓", aria: "Down arrow" },
{ kind: "key", key: "up", label: "↑", aria: "Up arrow" },
Expand Down
18 changes: 18 additions & 0 deletions viewer-ui/visual/viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test.afterEach(async () => {
});

async function openViewer(page: Page, options: ApiMockOptions = {}) {
const terminalMessages: string[] = [];
await page.clock.setFixedTime(FIXED_TIME);
await page.addInitScript(() => {
const style = document.createElement("style");
Expand All @@ -38,6 +39,7 @@ async function openViewer(page: Page, options: ApiMockOptions = {}) {
});
mocks = await installApiMocks(page, { status, ...options });
await page.routeWebSocket("**/ws/term**", (socket) => {
socket.onMessage((message) => terminalMessages.push(message.toString()));
socket.send(JSON.stringify({ type: "hello", client: 1, panes: 1 }));
socket.send(JSON.stringify({
type: "created", pane: 1, rows: 24, cols: 80, client: 1, title: "shell",
Expand All @@ -49,6 +51,7 @@ async function openViewer(page: Page, options: ApiMockOptions = {}) {
if ((page.viewportSize()?.width ?? 0) >= 768)
await expect(page.locator("[data-terminal-panel] .xterm-screen")).toBeAttached();
await page.evaluate(() => document.fonts.ready);
return terminalMessages;
}

async function capture(page: Page, name: string) {
Expand Down Expand Up @@ -148,6 +151,21 @@ test("a non-repository status is shown in the repository view", async ({ page })
await capture(page, "unavailable-repository");
});

test("the mobile key bar sends Shift+Left to the active terminal", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
const terminalMessages = await openViewer(page);
await page.getByRole("button", { name: "Terminal" }).click();
await expect(page.locator("[data-terminal-panel] .xterm-screen")).toBeAttached();

await page.getByRole("button", { name: "Shift Left arrow" }).click();

await expect.poll(() =>
terminalMessages
.map((raw) => JSON.parse(raw) as { type: string })
.filter((message) => message.type === "input"),
).toContainEqual({ type: "input", pane: 1, data: "\x1b[1;2D" });
});

test("the mobile compose dialog keeps image upload available while uploading", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await openViewer(page, { deferImage: true });
Expand Down
Loading