Documentation
¶
Overview ¶
Package diff turns two versions of a file into the whole-file line sequence the Backups preview renders: every line of the file in order, tagged with what turning one version into the other does to it.
It is deliberately UI-free - no theme, no lipgloss, no bubbles. The rendering phase (docs/plans/backups-rework.md, Phase 5) colours these lines; the engine stays pure and cheap to test on its own.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind int
Kind classifies one line of a whole-file diff.
const ( // Equal is a line both sides of the diff agree on. Equal Kind = iota // Insert is a line the second side has that the first does not. In the // preview's direction (live, backup) it is content a restore would add. Insert // Delete is a line the first side has that the second does not. In the // preview's direction it is content a restore would remove from the // live file. Delete )
type Line ¶
type Line struct {
Kind Kind
// Content is the line's text without its trailing newline: the renderer
// draws one Line per row, and a newline inside Content would render as
// a blank row.
Content string
Spans []Span
}
Line is one line of the whole-file view of a diff.
func Lines ¶
Lines diffs before against after into the sequence of lines a whole-file view renders: every line in file order, each tagged Equal, Insert or Delete.
Called as Lines(live, backup) it answers "what does restoring this copy do to my file right now?" - a Delete line is content the restore would remove from the live file, an Insert line is content it would add, and an Equal line is content both agree on.
The result covers the whole file, not hunks: the panel renders every line and scrolls to the first change, so Equal context is kept without a context limit.
Chunking follows udiff's line-boundary expansion: an edit inside a line restates that line as a Delete+Insert pair with identical content. The case that reaches real files is an append to a file whose last line has no newline (see Lines_test.go). Smoothing those pairs out is a pairing heuristic, and it belongs to the rendering phase's deferred intra-line work, not to this engine.
Lines returns nil when there is nothing to diff (both inputs empty), and on the unreachable internal error below. Callers read nil as "diff unavailable" and fall back to showing the copy's plain bytes - the same degradation a missing live file gets - rather than as a separate error.
type Span ¶
Span is a half-open byte range within a Line's Content that carries an intra-line change.
Spans is present and empty from day one so the intra-line highlighting work (docs/plans/backups-rework.md, *Deferred*) fills a field rather than changing this type's shape - and so every caller that ignores it today is already correct when it starts arriving.