diff

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: GPL-3.0 Imports: 36 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 DefaultStyle = sync.OnceValue(func() *chroma.Style {

	return styles.Register(chroma.MustNewStyle("default", chroma.StyleEntries{
		chroma.TextWhitespace:        "#bbbbbb",
		chroma.Comment:               "italic #3D7B7B",
		chroma.CommentPreproc:        "noitalic #9C6500",
		chroma.Keyword:               "bold #008000",
		chroma.KeywordPseudo:         "nobold",
		chroma.KeywordType:           "nobold #B00040",
		chroma.Operator:              "#666666",
		chroma.OperatorWord:          "bold #AA22FF",
		chroma.NameBuiltin:           "#008000",
		chroma.NameFunction:          "#0000FF",
		chroma.NameClass:             "bold #0000FF",
		chroma.NameNamespace:         "bold #0000FF",
		chroma.NameException:         "bold #CB3F38",
		chroma.NameVariable:          "#19177C",
		chroma.NameConstant:          "#880000",
		chroma.NameLabel:             "#767600",
		chroma.NameEntity:            "bold #717171",
		chroma.NameAttribute:         "#687822",
		chroma.NameTag:               "bold #008000",
		chroma.NameDecorator:         "#AA22FF",
		chroma.LiteralString:         "#BA2121",
		chroma.LiteralStringDoc:      "italic",
		chroma.LiteralStringInterpol: "bold #A45A77",
		chroma.LiteralStringEscape:   "bold #AA5D1F",
		chroma.LiteralStringRegex:    "#A45A77",
		chroma.LiteralStringSymbol:   "#19177C",
		chroma.LiteralStringOther:    "#008000",
		chroma.LiteralNumber:         "#666666",
		chroma.GenericHeading:        "bold #000080",
		chroma.GenericSubheading:     "bold #800080",
		chroma.GenericDeleted:        "#A00000",
		chroma.GenericInserted:       "#008400",
		chroma.GenericError:          "#E40000",
		chroma.GenericEmph:           "italic",
		chroma.GenericStrong:         "bold",
		chroma.GenericPrompt:         "bold #000080",
		chroma.GenericOutput:         "#717171",
		chroma.GenericTraceback:      "#04D",
		chroma.Error:                 "border:#FF0000",
		chroma.Background:            " bg:#f8f8f8",
	}))
})
View Source
var DiffExe = sync.OnceValue(func() string {
	return utils.FindExe("diff")
})
View Source
var ErrNoLexer = errors.New("No lexer available for this format")
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(filepath.Join(utils.ConfigDir(), "kitty.conf"))
})

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 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