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§
- Diff
Display Line - One on-screen line resolved by
DiffView::layout— already scroll-clamped, soDiffView::layout(..).linesis exactly the visible window in paint order. - Diff
Header Geometry - Header strip geometry for side-by-side mode (only present when
left_label/right_labelis set). Resolved once byDiffView::layoutrather than re-derived by each backend. - Diff
Hunk - A contiguous group of rows to display, bracketed by context lines.
- Diff
Pane Geometry - Top-level pane geometry for side-by-side mode — present even when
linesis empty (e.g. an empty diff), so a backend painting trailing blank rows or an empty-pane divider never needs to re-deriveleft_w/right_w/divider_xby hand. - DiffRow
- A single display row in a
DiffHunk. - Diff
View - The
DiffViewprimitive: a two-pane or unified diff viewer. - Diff
View Geometry - Fully-resolved
DiffViewgeometry — the row-position/colour-agnostic spatial layout that backends need to render. Computed once byDiffView::layoutrather than re-derived independently by each backend. Backends still own colour selection (row_colors/unified_row_style) and text painting; this answers only “where”. - Diff
View Layout - Layout information returned by
draw_diff_view.
Enums§
- Diff
Editability - Whether the right pane of the diff is editable.
- Diff
Line Content - What a
DiffDisplayLinerenders: either a synthesized unified@@ … @@hunk header, or a real diff row. - Diff
Mode - Display mode for the diff widget.
- Diff
Pane - Which pane has keyboard focus.
- Diff
RowKind - The kind of change a
DiffRowrepresents. - Diff
View Hit - 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 → colourtable 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 itsColoroutput to its own native colour type at the call site (qcon TUI,cairo_rgbon 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 ofrow_colors, likewise lifted out of three backend copies. - unified_
row_ text - The unified-mode content text for a
DiffRow: the left text for aRemovedrow, otherwise the right text falling back to the left (Changed/Added/Same). Lifted out of three identicalmatcharms.