Documentation
¶
Overview ¶
Package diff is base's DiffView, a port of NSH's: the changes between two texts, or the files of a patch, side by side or one over the other, the words changed within lines marked, the unchanged lines between changes collapsed into separators that expand, and the text colored by the Editor's highlighting. It has no look of its own: Styles gives every part, the added and deleted tints among them, its look.
It is a package of its own because its highlighting links chroma's lexers.
Index ¶
- type Annotation
- type Change
- type Classes
- type DiffView
- type Expansion
- type File
- type FileStatus
- type Highlighter
- type Hunk
- type HunkBounds
- type Indicators
- type Inline
- type Line
- type LineRange
- type Ref
- func (r *Ref) AcceptHunk(i int)
- func (r *Ref) AcceptRegion(x Region)
- func (r *Ref) CollapseAll()
- func (r *Ref) CollapseFile(path string)
- func (r *Ref) CurrentHunk() (int, bool)
- func (r *Ref) Expand(gap int, how Expansion, lines int)
- func (r *Ref) ExpandAll()
- func (r *Ref) ExpandFile(path string)
- func (r *Ref) Files() []File
- func (r *Ref) GoToHunk(i int)
- func (r *Ref) HunkBounds() []HunkBounds
- func (r *Ref) Hunks() []Hunk
- func (r *Ref) NextHunk() (int, bool)
- func (r *Ref) PreviousHunk() (int, bool)
- func (r *Ref) RevertHunk(i int)
- func (r *Ref) RevertRegion(x Region)
- func (r *Ref) ScrollOffset() core.Points
- func (r *Ref) ScrollToFile(path string)
- func (r *Ref) SelectedLines() (LineRange, bool)
- func (r *Ref) SelectedText() string
- func (r *Ref) SetScrollOffset(y core.Points)
- func (r *Ref) SetSelectedLines(lines *LineRange)
- func (r *Ref) Stats() Stats
- func (r *Ref) ToggleFile(path string)
- type Region
- type Separator
- type Side
- type Stats
- type Styles
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotation ¶
Annotation is the app's content under a line (a review comment, a thread), drawn by RenderAnnotation across its side, as tall as it lays out. ID tells it apart from the others; Line is from 0 of Side's text. It shows while its line does.
type Change ¶
type Change struct{ OldValue, NewValue string }
Change is the texts after a change was reverted or kept.
type Classes ¶
type Classes struct {
Side, Gutter, LineNumber, LineNumberAdded, LineNumberDeleted string
Content, Line, LineAdded, LineDeleted, Filler string
WordAdded, WordDeleted string
IndicatorAdded, IndicatorDeleted string
Separator, HunkActions, FileHeader string
LineSelected, Annotation, AddAnnotation, Region string
}
Classes are Tailwind classes of a DiffView's parts, by Styles' names, each under its part's style.
type DiffView ¶
type DiffView struct {
OldValue, NewValue func() string
// Patch is a unified diff of one file or several: git diff's, git
// format-patch's, diff -u's. Each hunk shows under a separator of its
// header, its lines numbered as in the file.
Patch func() string
// Language colors the text; a patch's files by their paths without
// it.
Language string
// Highlighter gives the app's highlighter for a language's name or a
// file's path, nil for the built-in one.
Highlighter func(language string) Highlighter
// Unified shows one column, the deleted lines over the added ones,
// rather than two sides.
Unified bool
Inline Inline
Indicators Indicators
// ContextLines is the unchanged lines shown around each change: 3 when
// 0, none when negative. ExpandAll shows every one.
ContextLines int
ExpandAll bool
// NoLineNumbers hides the numbers; SoftWrap wraps long lines at the
// side's width.
NoLineNumbers, SoftWrap bool
// Selectable lets the user select and copy each column's text, its
// numbers and separators left out.
Selectable bool
// FontFamily (the monospaced font when empty), FontSize (13) and
// LineHeight (20). SeparatorHeight is the height of separators and
// file headers, LineHeight when 0.
FontFamily string
FontSize, LineHeight, SeparatorHeight core.Points
// RenderFileHeader draws a patch's file headers, a header above a
// patch of one file too; its controls call Ref.ToggleFile. Without it
// a header shows the file's path and counts, and a press toggles it.
RenderFileHeader func(cx *core.Scope, f File) core.Node
// RenderSeparator draws the separators of collapsed lines and a
// patch's hunk headers; its controls call Ref.Expand. Without it a
// separator says what it hides, and a press shows every line.
RenderSeparator func(cx *core.Scope, s Separator) core.Node
// RenderHunkActions draws the app's actions on a change (revert,
// keep), at its first row's right.
RenderHunkActions func(cx *core.Scope, h Hunk) core.Node
// RenderRegionActions draws the app's actions on lines (stage, discard)
// in a frame around them, at its top right: the change the pointer is
// over, or the whole lines the text selection touches or those selected
// on the numbers, which take its place while they last. The text is
// selectable with it.
RenderRegionActions func(cx *core.Scope, r Region) core.Node
// Annotations are the app's content under lines, each drawn by
// RenderAnnotation across its line's side (the view unified).
Annotations func() []Annotation
RenderAnnotation func(cx *core.Scope, a Annotation) core.Node
// RenderAddAnnotation draws the app's control to add an annotation,
// beside the line the pointer is over and the last selected one: lines
// are the selected ones when its line is one of them, else its line.
RenderAddAnnotation func(cx *core.Scope, lines LineRange) core.Node
// Classes go under Styles, and Class under Style.
Classes Classes
Styles Styles
StylesFunc func() Styles
Class string
Style core.Style
StyleFunc func() core.Style
Ref *Ref
TestID string
// OnLayout and Tooltip are its view's, as a core.View's.
OnLayout func(core.Bounds)
Tooltip core.Node
// OnChange receives the texts after a change was reverted or kept.
OnChange func(Change)
OnLineNumberPress func(Line)
// OnLineSelectionChange receives the lines selected on the numbers, nil
// for none: a press selects a line, a Shift-press extends to it, and a
// mouse drag over the numbers selects those it goes over.
OnLineSelectionChange func(lines *LineRange)
// OnStatsChange receives the counts once and whenever a diff counts
// otherwise.
OnStatsChange func(Stats)
OnFileToggle func(File)
// OnScroll receives the rows' scroll position from the first layout
// on, with each scroll, resize or relayout that changes it.
OnScroll func(core.ScrollEvent)
// OnHunkBoundsChange receives each change's box when one moves.
OnHunkBoundsChange func([]HunkBounds)
// OnError receives a patch that cannot be read.
OnError func(error)
}
DiffView shows the changes between OldValue and NewValue, or the files of Patch when they are nil.
type File ¶
type File struct {
Index int
Path, OldPath string
Status FileStatus
Binary bool
Added, Deleted int
Hunks, FirstHunk int
Collapsed bool
}
File is a file of a patch: its index among the patch's files, its paths (OldPath for renames and copies), status, counts, its changes from FirstHunk, and whether it is collapsed.
type FileStatus ¶
type FileStatus uint8
FileStatus is what a patch did to a file.
const ( FileModified FileStatus = iota FileAdded FileDeleted FileRenamed FileCopied )
type Highlighter ¶
type Highlighter = syntax.Highlighter
Highlighter is the app's highlighting of a language, in place of the built-in one, as the Editor takes it.
type Hunk ¶
Hunk is a change: its index, its file's index in a patch (0 for two texts), and its lines as 1-based numbers and counts on each side.
type HunkBounds ¶
HunkBounds is the box of change Index's rows: wrapped lines and annotations count, and a collapsed file's changes have none.
type Indicators ¶
type Indicators uint8
Indicators is how changed lines are marked beside their numbers.
const ( // IndicatorBars is a bar at the gutter's left edge. IndicatorBars Indicators = iota // IndicatorClassic is + and −. IndicatorClassic IndicatorNone )
type Inline ¶
type Inline uint8
Inline is what is highlighted within changed lines.
const ( // InlineWordAlt marks the words that changed, joined when one // character apart, so a changed phrase reads as one. InlineWordAlt Inline = iota // InlineWord marks each word that changed. InlineWord // InlineChar marks each character that changed. InlineChar // InlineNone marks nothing: the lines' tints alone. InlineNone )
type LineRange ¶
LineRange is lines Start to End (both included, from 0) of a side's text: the lines selected on the numbers, or those an annotation is added to.
type Ref ¶
type Ref struct {
// contains filtered or unexported fields
}
Ref is a DiffView's methods, bound once it mounts.
func (*Ref) AcceptHunk ¶
AcceptHunk makes change i's new lines the old text's and reports the texts.
func (*Ref) AcceptRegion ¶
AcceptRegion makes r's lines the old text's, as staging them does, and reports the texts. It takes two texts' lines, not a patch's.
func (*Ref) CollapseAll ¶
func (r *Ref) CollapseAll()
CollapseAll collapses the unchanged lines again.
func (*Ref) CollapseFile ¶
CollapseFile shows only the header of the file at path.
func (*Ref) CurrentHunk ¶
CurrentHunk returns the change gone to while the view stays there, else the one at the top of the view or the first in view; false for none in view.
func (*Ref) Expand ¶
Expand shows lines separator gap hides: every one, or lines (20 when 0) up or down.
func (*Ref) ExpandAll ¶
func (r *Ref) ExpandAll()
ExpandAll shows every unchanged line; CollapseAll collapses them again.
func (*Ref) ExpandFile ¶
ExpandFile shows the lines of the file at path again.
func (*Ref) GoToHunk ¶
GoToHunk scrolls change i's first row to the top, expanding a collapsed file first.
func (*Ref) HunkBounds ¶
func (r *Ref) HunkBounds() []HunkBounds
HunkBounds returns each change's box across the viewport, in the rows' coordinates, for an overview ruler.
func (*Ref) NextHunk ¶
NextHunk scrolls the next change to the top and returns its index, after the last the first; false without changes. It goes on from the change gone to while the view stays there, else from the top of the view.
func (*Ref) PreviousHunk ¶
PreviousHunk scrolls the previous change to the top and returns its index, before the first the last.
func (*Ref) RevertHunk ¶
RevertHunk puts change i's old lines back into the new text and reports the texts.
func (*Ref) RevertRegion ¶
RevertRegion puts r's lines back as they are in the old text and reports the texts. It takes two texts' lines, not a patch's.
func (*Ref) ScrollOffset ¶
ScrollOffset returns how far the rows are scrolled.
func (*Ref) ScrollToFile ¶
ScrollToFile scrolls the header of the file at path to the top.
func (*Ref) SelectedLines ¶
SelectedLines returns the lines selected on the numbers; ok is false for none.
func (*Ref) SelectedText ¶
SelectedText returns the selected lines' text.
func (*Ref) SetScrollOffset ¶
SetScrollOffset scrolls the rows to y at once, as far as they go, for a thumb that follows the pointer.
func (*Ref) SetSelectedLines ¶
SetSelectedLines selects lines of a side, nil for none, without OnLineSelectionChange.
func (*Ref) ToggleFile ¶
ToggleFile collapses the file at path, or expands it.
type Region ¶
Region is what RenderRegionActions acts on: the changed lines of Old and New it holds, from 0, and whether the user selected them rather than the pointer being over a change.
type Separator ¶
Separator is what RenderSeparator draws: the gap of unchanged lines it collapses (0 before the first change, i between changes i-1 and i), the lines it hides (0 for a patch's hunk header), whether it is before the first change or after the last, and a patch's hunk header.
type Stats ¶
type Stats struct{ Added, Deleted, Hunks int }
Stats is the lines added and deleted and the number of changes.
type Styles ¶
type Styles struct {
// Side is each side (split) or the one column (unified); Gutter a
// side's numbers and indicators; LineNumber every number, with
// LineNumberAdded and LineNumberDeleted after it on changed lines.
Side, Gutter, LineNumber, LineNumberAdded, LineNumberDeleted core.Style
// Content is a side's text beside its gutter; Line every row, with
// LineAdded and LineDeleted after it, on a changed row's gutter too;
// Filler the empty half of a split row beside a line the other side
// lacks, its Color hatching it.
Content, Line, LineAdded, LineDeleted, Filler core.Style
// WordAdded and WordDeleted mark the words changed within lines, a
// box a line tall behind them, whose Background and CornerRadius the
// words' text leaves to it.
WordAdded, WordDeleted core.Style
// IndicatorAdded and IndicatorDeleted are the bars, or the + and −.
IndicatorAdded, IndicatorDeleted core.Style
// Separator is a separator of collapsed lines or a patch's hunk
// header; HunkActions the box of the app's actions on a change;
// FileHeader a patch's file's header.
Separator, HunkActions, FileHeader core.Style
// LineSelected is over the selected lines' rows of their side, gutter
// and text; Annotation the box of an annotation; AddAnnotation the box
// of the add control, the gutter's width and a line tall.
LineSelected, Annotation, AddAnnotation core.Style
// Region frames the lines RenderRegionActions acts on.
Region core.Style
}
Styles are the styles of a DiffView's parts, its whole look.