diff

package
v0.43.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2025 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const DIFF_DIFF = `diff -p -U _CONTEXT_ --`
View Source
const GIT_DIFF = `git diff --no-color --no-ext-diff --exit-code -U_CONTEXT_ --no-index --`

Variables

View Source
var DiffExe = sync.OnceValue(func() string {
	return utils.FindExe("diff")
})
View Source
var GitExe = sync.OnceValue(func() string {
	return utils.FindExe("git")
})
View Source
var RelevantKittyOpts = sync.OnceValue(func() KittyOpts {
	return read_relevant_kitty_opts()
})

Functions

func Diff

func Diff(oldName, old, newName, new string, num_of_context_lines int) []byte

Diff returns an anchored diff of the two texts old and new in the “unified diff” format. If old and new are identical, Diff returns a nil slice (no output).

Unix diff implementations typically look for a diff with the smallest number of lines inserted and removed, which can in the worst case take time quadratic in the number of lines in the texts. As a result, many implementations either can be made to run for a long time or cut off the search after a predetermined amount of work.

In contrast, this implementation looks for a diff with the smallest number of “unique” lines inserted and removed, where unique means a line that appears just once in both old and new. We call this an “anchored diff” because the unique lines anchor the chosen matching regions. An anchored diff is usually clearer than a standard diff, because the algorithm does not try to reuse unrelated blank lines or closing braces. The algorithm also guarantees to run in O(n log n) time instead of the standard O(n²) time.

Some systems call this approach a “patience diff,” named for the “patience sorting” algorithm, itself named for a solitaire card game. We avoid that name for two reasons. First, the name has been used for a few different variants of the algorithm, so it is imprecise. Second, the name is frequently interpreted as meaning that you have to wait longer (to be patient) for the diff, meaning that it is a slower algorithm, when in fact the algorithm is faster than the standard one.

func EntryPoint

func EntryPoint(parent *cli.Command)

Types

type AsyncResult

type AsyncResult struct {
	// contains filtered or unexported fields
}

type Center

type Center struct {
	// contains filtered or unexported fields
}

type Chunk

type Chunk struct {
	// contains filtered or unexported fields
}

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

func (*Collection) Apply

func (self *Collection) Apply(f func(path, typ, changed_path string) error) error

func (*Collection) Items

func (self *Collection) Items() int

func (*Collection) Len

func (self *Collection) Len() int

type DiffData

type DiffData struct {
	// contains filtered or unexported fields
}

type HalfScreenLine

type HalfScreenLine struct {
	// contains filtered or unexported fields
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

type Hunk

type Hunk struct {
	// contains filtered or unexported fields
}

type KittyOpts

type KittyOpts struct {
	Wheel_scroll_multiplier int
	Copy_on_select          bool
}

type LineType

type LineType int
const (
	TITLE_LINE LineType = iota
	CHANGE_LINE
	CONTEXT_LINE
	HUNK_TITLE_LINE
	IMAGE_LINE
	EMPTY_LINE
)

type LogicalLine

type LogicalLine struct {
	// contains filtered or unexported fields
}

func (*LogicalLine) IncrementScrollPosBy

func (self *LogicalLine) IncrementScrollPosBy(pos *ScrollPos, amt int) (delta int)

type LogicalLines

type LogicalLines struct {
	// contains filtered or unexported fields
}

func (*LogicalLines) At

func (self *LogicalLines) At(i int) *LogicalLine

func (*LogicalLines) IncrementScrollPosBy

func (self *LogicalLines) IncrementScrollPosBy(pos *ScrollPos, amt int) (delta int)

func (*LogicalLines) Len

func (self *LogicalLines) Len() int

func (*LogicalLines) Minus

func (self *LogicalLines) Minus(a, b ScrollPos) (delta int)

a - b in terms of number of screen lines between the positions

func (*LogicalLines) NumScreenLinesTo

func (self *LogicalLines) NumScreenLinesTo(a ScrollPos) (ans int)

func (*LogicalLines) ScreenLineAt

func (self *LogicalLines) ScreenLineAt(pos ScrollPos) *ScreenLine

type Patch

type Patch struct {
	// contains filtered or unexported fields
}

func (*Patch) Len

func (self *Patch) Len() int

type Reference

type Reference struct {
	// contains filtered or unexported fields
}

type ResolvedColors

type ResolvedColors struct {
	Added_bg             style.RGBA
	Added_margin_bg      style.RGBA
	Background           style.RGBA
	Filler_bg            style.RGBA
	Foreground           style.RGBA
	Highlight_added_bg   style.RGBA
	Highlight_removed_bg style.RGBA
	Hunk_bg              style.RGBA
	Hunk_margin_bg       style.RGBA
	Margin_bg            style.RGBA
	Margin_fg            style.RGBA
	Margin_filler_bg     style.NullableColor
	Removed_bg           style.RGBA
	Removed_margin_bg    style.RGBA
	Search_bg            style.RGBA
	Search_fg            style.RGBA
	Select_bg            style.RGBA
	Select_fg            style.NullableColor
	Title_bg             style.RGBA
	Title_fg             style.RGBA
}

type ResultType

type ResultType int
const (
	COLLECTION ResultType = iota
	DIFF
	HIGHLIGHT
	IMAGE_LOAD
	IMAGE_RESIZE
)

type ScreenLine

type ScreenLine struct {
	// contains filtered or unexported fields
}

type ScrollPos

type ScrollPos struct {
	// contains filtered or unexported fields
}

func (ScrollPos) Add

func (self ScrollPos) Add(other ScrollPos) ScrollPos

func (ScrollPos) Less

func (self ScrollPos) Less(other ScrollPos) bool
type Search struct {
	// contains filtered or unexported fields
}

func (*Search) Has

func (self *Search) Has(pos ScrollPos) bool

func (*Search) Len

func (self *Search) Len() int

type Span

type Span struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL