Show diffs side by side in a wide conversation
Split view with synced scrolling from 140 columns, unified below that, with the gutter and line colours from theme tokens. Toggle split diff in the palette overrides the choice for the session.
This commit is contained in:
1 parent
4e3717d171
commit
d87026a66b
5 files changed
+80
-7
No files matched your search
+1
-1
@@ -100,7 +100,7 @@ The layout follows T3 Code's web app, and much of it uses the web app's own code
|
||||
- **Turns:** `[`/`]` select a turn and mark its prompt. `R` or `Revert to this turn` asks `Edit from here?`, then rewinds the chat and returns the prompt to the message box, keeping file changes. `Revert files too` in the palette also restores files, including your own edits. Stop a running turn first. Rewinding messages with attachments still needs the app.
|
||||
- **Command output:** expand work with `e` / `Expand all work`, or click a command. Output streams while its expanded row is in view; collapsing it, scrolling away or opening another thread stops it.
|
||||
- **Thread details:** a column beside the conversation with the workspace, model and mode, the branch with ahead/behind and its pull request, uncommitted changes per file, lineage (forks and subagents), background work and the goal. It opens by itself on terminals 160 columns or wider; on narrow ones `d` shows it in place of the conversation.
|
||||
- **Diffs:** pick `View diff` or a file under Changes to see uncommitted changes as unified diffs in place of the conversation. `D` (or `View changes from this turn`) reviews a turn's checkpoint; `View all changes in this thread` reviews the whole thread. `j`/`k` scroll, `[`/`]` choose a file, and `esc` closes. In uncommitted diffs, `x` or `enter` shows the whole file, including unchanged lines; press it again to collapse. Diffs of past checkpoints show only the changed lines.
|
||||
- **Diffs:** pick `View diff` or a file under Changes to see uncommitted changes in place of the conversation: side by side when the conversation is at least 140 columns wide, unified otherwise. `Toggle split diff` in the palette switches between the two for the rest of the session. `D` (or `View changes from this turn`) reviews a turn's checkpoint; `View all changes in this thread` reviews the whole thread. `j`/`k` scroll, `[`/`]` choose a file, and `esc` closes. In uncommitted diffs, `x` or `enter` shows the whole file, including unchanged lines; press it again to collapse. Diffs of past checkpoints show only the changed lines.
|
||||
- **Git:** the branch section offers the quick action (`Commit & push`, `Push`, `Create PR`…) and a menu of the rest. Every action asks first, says when you are on the default branch, and takes an optional commit message (leave it blank and T3 writes one). Progress shows on the bottom line.
|
||||
- **Pull requests:** `P` shows a linked pull request in place of the conversation (with several, you pick one): its state, author and branches, description, checks, reviews, recent comments and the review guide when one was written. `j`/`k` scroll, `o` opens it in the browser, `r` refreshes it, and `esc` closes it. From there, `c` comments and `R` reviews (approve / request changes / comment) in `$EDITOR`, `a` offers the host's actions (merge, close, ready…) behind a confirmation, `w` watches or stops watching, and `u` unlinks it. `Link pull request to thread` in the palette links one by URL or number, and `New thread from pull request…` checks one out into a draft in the project folder or its own worktree.
|
||||
- **Servers and automations:** local dev servers the thread started (stop one from the panel) and T3's scheduled tasks with their schedule and next run (run now, or turn on and off). `New automation` and `Edit automation: …` in the palette open the automation's fields in `$EDITOR` (title, schedule, project, workspace, model, mode, prompt); save and quit to save. `Delete automation: …` asks first. Webhook signatures and filters are left as they are; change those in the app.
|
||||
|
||||
+8
-1
@@ -90,6 +90,8 @@ const DETAILS_WIDTH = 38;
|
||||
const MIN_DETAILS_WIDTH = 28;
|
||||
/** Below this, the details panel takes the conversation's place instead of a column beside it. */
|
||||
const MIN_CONVERSATION_WIDTH = 70;
|
||||
/** The conversation this wide or wider shows diffs side by side. */
|
||||
const SPLIT_DIFF_WIDTH = 140;
|
||||
|
||||
const COMPOSER_KEYS = {
|
||||
enter: [
|
||||
@@ -118,6 +120,8 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
const [filter, setFilter] = useState("");
|
||||
const [showFolded, setShowFolded] = useState(false);
|
||||
const [expandAll, setExpandAll] = useState(false);
|
||||
/** Side-by-side diffs, once toggled for the session; null follows the conversation's width. */
|
||||
const [splitDiffPref, setSplitDiffPref] = useState<boolean | null>(null);
|
||||
/** Folds opened one at a time by a click, for the open thread. */
|
||||
const [expandedIds, setExpandedIds] = useState<ReadonlySet<string>>(() => new Set());
|
||||
/** The thread list's and details column's widths once their edges are dragged; null follows the window. */
|
||||
@@ -874,6 +878,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
const paletteOnly = keys(
|
||||
editorKey,
|
||||
pane?.kind === "server" && { keys: [], run: () => closePane(), command: { id: "pane-close", title: "Close the terminal pane", keywords: ["detach", "hide"] } },
|
||||
{ keys: [], run: () => setSplitDiffPref(!splitDiff), command: { id: "split-diff", title: "Toggle split diff", keywords: ["side by side", "unified", "diff view"] } },
|
||||
queue.keys.input,
|
||||
queue.keys.palette,
|
||||
(projection?.subagents ?? []).filter((agent) => threadId && canStopSubagent(agent)).map((agent): Binding => ({ keys: [], run: () => run("Stop requested", () => session.stopSubagent(agent)), command: { id: `stop-subagent:${agent.id}`, title: `Stop subagent: ${agent.title ?? "subagent"}`, keywords: ["interrupt", "cancel", "kill"] } })),
|
||||
@@ -1076,6 +1081,8 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
const detailsColumn = !pane && panel.show && detailsWidth <= detailsRoom;
|
||||
const detailsInPlace = !pane && panel.show && !detailsColumn;
|
||||
const rightColumn = paneColumn || detailsColumn;
|
||||
const conversationWidth = width - (showList ? listWidth + 1 : 0) - (rightColumn ? detailsWidth + 1 : 0);
|
||||
const splitDiff = splitDiffPref ?? conversationWidth >= SPLIT_DIFF_WIDTH;
|
||||
// The block's height: a row of padding on top, the text, then the model line inside it.
|
||||
// Padding row, text, a blank row, then the model line.
|
||||
const composerHeight = Math.min(MAX_COMPOSER_LINES, composerLines) + 3;
|
||||
@@ -1211,7 +1218,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
) : mode === "pull-request" && pullRequests.view ? (
|
||||
<PullRequestView view={pullRequests.view} scrollRef={scrollRef} onOpenUrl={() => pullRequests.commands.find((candidate) => candidate.id === "pr-open")?.run()} onMenu={openPullRequestMenu} onClose={pullRequests.close} />
|
||||
) : diff ? (
|
||||
<DiffView diff={diff} scrollRef={scrollRef} selected={turns.diffContext.selected} expanded={turns.diffContext.expanded} onFile={turns.diffContext.click} />
|
||||
<DiffView diff={diff} split={splitDiff} scrollRef={scrollRef} selected={turns.diffContext.selected} expanded={turns.diffContext.expanded} onFile={turns.diffContext.click} />
|
||||
) : draft ? (
|
||||
<DraftView lines={newThread.lines(models.open)} />
|
||||
) : threadId && detailsInPlace && mode !== "find" ? (
|
||||
|
||||
+11
-5
@@ -18,8 +18,8 @@ export interface DiffState {
|
||||
readonly error?: string;
|
||||
}
|
||||
|
||||
/** Working-tree or checkpoint changes through the same unified diff renderer. */
|
||||
export function DiffView(props: { readonly diff: DiffState; readonly scrollRef: RefObject<ScrollBoxRenderable | null>; readonly selected: number; readonly expanded: Readonly<Record<string, { patch?: string; error?: string }>>; readonly onFile: (index: number) => void }) {
|
||||
/** Working-tree or checkpoint changes through the same diff renderer: side by side when `split`, else unified. */
|
||||
export function DiffView(props: { readonly diff: DiffState; readonly split: boolean; readonly scrollRef: RefObject<ScrollBoxRenderable | null>; readonly selected: number; readonly expanded: Readonly<Record<string, { patch?: string; error?: string }>>; readonly onFile: (index: number) => void }) {
|
||||
const { diff } = props;
|
||||
const markdownStyle = useMarkdownStyle();
|
||||
const files = diff.patch ? splitPatch(diff.patch) : [];
|
||||
@@ -44,7 +44,8 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
|
||||
{props.expanded[file.path] && !props.expanded[file.path]?.patch ? <text fg={props.expanded[file.path]?.error ? colors.bad : colors.muted}>{props.expanded[file.path]?.error ?? "Loading full file…"}</text> : null}
|
||||
<diff
|
||||
diff={props.expanded[file.path]?.patch ?? file.patch}
|
||||
view="unified"
|
||||
view={props.split ? "split" : "unified"}
|
||||
syncScroll
|
||||
{...(filetypeOf(file.path) ? { filetype: filetypeOf(file.path)! } : {})}
|
||||
syntaxStyle={markdownStyle}
|
||||
showLineNumbers
|
||||
@@ -52,11 +53,16 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
|
||||
fg={colors.text}
|
||||
addedBg={colors.diffAddedBg}
|
||||
removedBg={colors.diffRemovedBg}
|
||||
contextBg={colors.bg}
|
||||
addedContentBg={colors.diffAddedBg}
|
||||
removedContentBg={colors.diffRemovedBg}
|
||||
addedSignColor={colors.good}
|
||||
removedSignColor={colors.bad}
|
||||
contextContentBg={colors.bg}
|
||||
addedSignColor={colors.diffAddedSign}
|
||||
removedSignColor={colors.diffRemovedSign}
|
||||
lineNumberFg={colors.faint}
|
||||
lineNumberBg={colors.diffGutterBg}
|
||||
addedLineNumberBg={colors.diffAddedGutterBg}
|
||||
removedLineNumberBg={colors.diffRemovedGutterBg}
|
||||
/>
|
||||
</box>
|
||||
))}
|
||||
|
||||
@@ -34,6 +34,12 @@ const DARK = {
|
||||
plan: "#fab283",
|
||||
diffAddedBg: "#14261a",
|
||||
diffRemovedBg: "#2a1517",
|
||||
/** The line-number gutter: a shade off the background, deeper beside added and removed lines. */
|
||||
diffGutterBg: "#111111",
|
||||
diffAddedGutterBg: "#1b3322",
|
||||
diffRemovedGutterBg: "#381c1f",
|
||||
diffAddedSign: "#7fd88f",
|
||||
diffRemovedSign: "#e06c75",
|
||||
};
|
||||
|
||||
export type Palette = { readonly [K in keyof typeof DARK]: string };
|
||||
@@ -63,6 +69,11 @@ const LIGHT: Palette = {
|
||||
plan: "#c06a2b",
|
||||
diffAddedBg: "#e3f3e6",
|
||||
diffRemovedBg: "#fbe4e4",
|
||||
diffGutterBg: "#f7f7f7",
|
||||
diffAddedGutterBg: "#cdebd3",
|
||||
diffRemovedGutterBg: "#f5cfcf",
|
||||
diffAddedSign: "#3d9a57",
|
||||
diffRemovedSign: "#d1383d",
|
||||
};
|
||||
|
||||
/** The palette in use. Read at render time, so applyTheme before the first frame sets it everywhere. */
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
|
||||
import { withCompletedTurn } from "./fixtures.ts";
|
||||
import { fakeSession, renderApp } from "./harness.tsx";
|
||||
|
||||
let app: Awaited<ReturnType<typeof renderApp>> | null = null;
|
||||
const open = async (...args: Parameters<typeof renderApp>) => (app = await renderApp(...args));
|
||||
afterEach(() => {
|
||||
app?.destroy();
|
||||
app = null;
|
||||
});
|
||||
|
||||
const patch = "diff --git a/src/index.ts b/src/index.ts\n--- a/src/index.ts\n+++ b/src/index.ts\n@@ -1,2 +1,2 @@\n const kept = 1;\n-const before = 2;\n+const after = 3;\n";
|
||||
const withDiff = () => fakeSession({ projection: withCompletedTurn(), results: { turnDiff: { diff: patch } } });
|
||||
/** The removed and added lines share a row side by side, and stack when unified. */
|
||||
const sideBySide = (frame: string) => frame.split("\n").some((line) => line.includes("before") && line.includes("after"));
|
||||
|
||||
describe("diffs", () => {
|
||||
test("a wide conversation shows them side by side", async () => {
|
||||
const app = await open({ width: 260, session: withDiff() });
|
||||
await app.press("D");
|
||||
await app.settle(50);
|
||||
expect(app.frame()).toContain("const before = 2;");
|
||||
expect(sideBySide(app.frame())).toBe(true);
|
||||
});
|
||||
|
||||
test("a narrower one shows them unified", async () => {
|
||||
const app = await open({ width: 140, session: withDiff() });
|
||||
await app.press("D");
|
||||
await app.settle(50);
|
||||
expect(app.frame()).toContain("const after = 3;");
|
||||
expect(sideBySide(app.frame())).toBe(false);
|
||||
});
|
||||
|
||||
test("Toggle split diff overrides the width for the session", async () => {
|
||||
const app = await open({ width: 140, session: withDiff() });
|
||||
await app.press("k", { ctrl: true });
|
||||
await app.type("split diff");
|
||||
await app.press("return");
|
||||
await app.press("D");
|
||||
await app.settle(50);
|
||||
expect(sideBySide(app.frame())).toBe(true);
|
||||
await app.press("k", { ctrl: true });
|
||||
await app.type("split diff");
|
||||
await app.press("return");
|
||||
await app.settle(50);
|
||||
expect(sideBySide(app.frame())).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user