/** * The diff panel: a full-size overlay with the changed files on the left and the selected file's * diff on the right (one pane at a time below 100 columns). Keyboard first, with the mouse as an * extra: click a file or a tab, wheel to scroll. * * j k / arrows files (list) or lines (diff) ] [ next / previous hunk * enter l open the diff pane h back to the list * ctrl+d ctrl+u half a page g G top / bottom * tab changes <-> branch r reload * a actions added by other extensions esc q close * * The loader is injected, so the view can be tested with no git and no terminal. */ import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent"; import { type Component, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui"; import type { FileDiff, Loaded } from "./git-diff.ts"; import type { DiffAction } from "./types.ts"; export type Source = "changes" | "branch" | "external"; /** Width below which the two panes become one. */ export declare const TWO_PANE_MIN = 100; export interface ViewDeps { tui: { terminal: { rows: number; columns: number; }; requestRender(): void; }; theme: Theme; ctx: ExtensionContext; cwd: string; /** Actions to offer under `a`, read each time the menu opens. */ actions: () => DiffAction[]; /** Close the panel. */ done: () => void; load: (source: "changes" | "branch", cwd: string) => Promise; /** A diff that did not come from git here: shown instead of the two git sources. */ external?: { title: string; files: FileDiff[]; }; initial?: "changes" | "branch"; /** Select this file (a path, relative to `cwd` or absolute) once the first load finishes. */ file?: string; } interface Layout { w: number; h: number; two: boolean; listW: number; diffX: number; diffW: number; contentH: number; } export declare function layoutFor(w: number, h: number): Layout; export declare class DiffView implements Component { private readonly d; private source; private readonly data; private loading; private token; private closed; private sel; private listTop; private top; /** The hunk `]` and `[` moved to, which actions use. It follows the scroll when the view scrolls. */ private cursor; private shift; private focus; private bodyFor; private menu; /** Where the menu was drawn: its first row, its columns, its row count, and the item shown on the first row after the title. */ private menuRect; private tabs; private lay; private flash; /** The file to select when the first load finishes; cleared after. */ private wantFile; constructor(deps: ViewDeps); private ensure; private get loaded(); private get files(); private get file(); private get body(); dispose(): void; invalidate(): void; private select; private keepSelectionVisible; private maxTop; private scroll; /** When the view actually moved, the current hunk is the one at the top. */ private followScroll; private switchSource; /** Move to the next or previous hunk, scrolling only as far as needed to bring it into view. */ private jumpHunk; private openMenu; private runAction; handleInput(data: string): void; private listInput; private diffInput; private goTo; private menuInput; handleMouse(e: TuiMouseEvent): TuiMouseEventResult | undefined; private menuClick; render(width: number): string[]; private stateNote; private noteRow; private header; private contentRow; private footer; /** * The action menu, drawn over the middle rows of the panel. It keeps to the rows between the * header and the footer: on a short screen only as many items as fit are shown, scrolled so the * selected one is always among them. */ private drawMenu; } export {};