Skip to main content

Module diff_view

Module diff_view 

Source
Expand description

DiffView primitive: a two-pane side-by-side or unified diff viewer.

§Backend contract

Purely declarative — hunks are app-computed via quadraui::diff::compute_hunks; backends only render. The app calls compute_hunks(left, right) whenever the inputs change, stores the result in DiffView::hunks, and passes the struct to the backend for rasterisation. Backends never recompute the diff.

§Scroll model

A single scroll_offset drives lock-step scrolling of both panes. The offset counts display rows from the beginning of the first hunk. Per-pane independent scrolling is out of scope for v1; the planned additive field is right_scroll_offset: Option<usize>.

§Editability

DiffEditability::RightEditable signals to consumers that the right pane should accept edits on TUI. Events in this architecture flow from AppLogic::handle, not from rasterisers — the app processes key input, mutates DiffView::right, and recomputes hunks itself. Full text-input machinery (cursor, insertion, deletion) is a follow-up story; on GTK v1 the right pane remains read-only regardless of this setting.

§Distinct from Editor with diff_status

DiffView renders a self-contained diff primitive from pre-computed hunks. The Editor primitive decorates live buffer content with per-line gutter colours. They are not interchangeable.

§Shared layout

Row/pane geometry — pane widths, the divider position, the optional header strip, and the scroll-clamped visible-line window — is now computed once by DiffView::layout rather than re-derived by every backend independently. row_colors / unified_row_style / unified_row_text / unified_hunk_header are the single source of colour/text selection. Every backend (gtk, macos, tui, win) calls these instead of carrying its own copy.

Structs§

DiffDisplayLine
One on-screen line resolved by DiffView::layout — already scroll-clamped, so DiffView::layout(..).lines is exactly the visible window in paint order.
DiffHeaderGeometry
Header strip geometry for side-by-side mode (only present when left_label/right_label is set). Resolved once by DiffView::layout rather than re-derived by each backend.
DiffHunk
A contiguous group of rows to display, bracketed by context lines.
DiffPaneGeometry
Top-level pane geometry for side-by-side mode — present even when lines is empty (e.g. an empty diff), so a backend painting trailing blank rows or an empty-pane divider never needs to re-derive left_w/right_w/divider_x by hand.
DiffRow
A single display row in a DiffHunk.
DiffView
The DiffView primitive: a two-pane or unified diff viewer.
DiffViewGeometry
Fully-resolved DiffView geometry — the row-position/colour-agnostic spatial layout that backends need to render. Computed once by DiffView::layout rather than re-derived independently by each backend. Backends still own colour selection (row_colors / unified_row_style) and text painting; this answers only “where”.
DiffViewLayout
Layout information returned by draw_diff_view.

Enums§

DiffEditability
Whether the right pane of the diff is editable.
DiffLineContent
What a DiffDisplayLine renders: either a synthesized unified @@ … @@ hunk header, or a real diff row.
DiffMode
Display mode for the diff widget.
DiffPane
Which pane has keyboard focus.
DiffRowKind
The kind of change a DiffRow represents.
DiffViewHit
Hit-test classification for a click against a DiffViewGeometry.

Constants§

DIFF_DIVIDER_W
Divider thickness between the left and right panes, in the backend’s native units (1 cell on TUI, 1 px/DIP everywhere else — every backend used the same numeric value before #737, so it is a shared constant rather than a fourth per-backend copy).

Functions§

row_colors
The row kind → colour table for side-by-side mode — used by every backend’s rasteriser (gtk, macos, tui, win). This single function is the only definition, and every backend converts its Color output to its own native colour type at the call site (qc on TUI, cairo_rgb on GTK, a passthrough on macOS/Win).
unified_hunk_header
Render a hunk’s @@ -l,n +r,m @@ unified-diff header line.
unified_row_style
The row kind → (prefix, colour) table for unified mode — the single-column twin of row_colors, likewise lifted out of three backend copies.
unified_row_text
The unified-mode content text for a DiffRow: the left text for a Removed row, otherwise the right text falling back to the left (Changed/Added/Same). Lifted out of three identical match arms.