difffmt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const UnifiedTimeFormat = "2006-01-02 15:04:05.000000000 -0700"

Variables

Functions

This section is empty.

Types

type ColorMode added in v0.2.0

type ColorMode uint8
const (
	ColorNone ColorMode = iota
	ColorAlways
	ColorTerminalOnly
)

type Colorizer added in v0.2.0

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

func NewColorizer added in v0.2.0

func NewColorizer(mode ColorMode, attrs ...color.Attribute) *Colorizer

func (*Colorizer) Fprint added in v0.2.0

func (c *Colorizer) Fprint(w io.Writer, a ...interface{}) (int, error)

func (*Colorizer) Fprintf added in v0.2.0

func (c *Colorizer) Fprintf(w io.Writer, format string, a ...interface{}) (int, error)

func (*Colorizer) SetMode added in v0.2.0

func (c *Colorizer) SetMode(mode ColorMode)

type DiffTarget

type DiffTarget struct {
	Path         string
	ModifiedTime time.Time
}

func NewDiffTarget

func NewDiffTarget(path string) *DiffTarget

func (*DiffTarget) LoadStat

func (t *DiffTarget) LoadStat() error

func (*DiffTarget) ReadText

func (t *DiffTarget) ReadText() (string, error)

type Hunk

type Hunk struct {
	Diffs        []LineDiff
	OldLineFrom  int
	OldLineTo    int
	OldLineCount int
	NewLineFrom  int
	NewLineTo    int
	NewLineCount int
}

func MakeHunks added in v0.2.0

func MakeHunks(diffs []LineDiff, contextSize int) []Hunk

func NewHunk

func NewHunk() Hunk

func (*Hunk) AppendDiff

func (h *Hunk) AppendDiff(diff LineDiff)

type LineDiff

type LineDiff struct {
	Operation Operation
	Text      string
	OldLine   int
	NewLine   int
	IsEndedLF bool
}

func MakeLineDiffsFromDMP added in v0.2.0

func MakeLineDiffsFromDMP(diffs []diffmatchpatch.Diff) []LineDiff

In order to make line diffs from github.com/seri/diffmatchpatch, you can make by steps shown below:

// Computing a line-mode diff by github.com/seri/diffmatchpatch
// @see https://github.com/google/diff-match-patch/wiki/Line-or-Word-Diffs
dmp := diffmatchpatch.New()
runes1, runes2, lineArray := dmp.DiffLinesToRunes(text1, text2)
diffs := dmp.DiffMainRunes(runes1, runes2, false)
diffs = dmp.DiffCharsToLines(diffs, lineArray)

// Make `[]LineDiff` from `[]diffmatchpatch.Diff`
lineDiffs := difffmt.MakeLineDiffsFromDMP(diffs)

type Operation

type Operation int8
const (
	OperationDelete Operation = -1
	OperationInsert Operation = 1
	OperationEqual  Operation = 0
)

type UnifiedFormat

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

func NewUnifiedFormat added in v0.2.0

func NewUnifiedFormat(option UnifiedFormatOption) *UnifiedFormat

func (*UnifiedFormat) Fprint

func (u *UnifiedFormat) Fprint(w io.Writer, targetA *DiffTarget, targetB *DiffTarget, hunks []Hunk)

func (*UnifiedFormat) Print

func (u *UnifiedFormat) Print(targetA *DiffTarget, targetB *DiffTarget, hunks []Hunk)

func (*UnifiedFormat) Sprint

func (u *UnifiedFormat) Sprint(targetA *DiffTarget, targetB *DiffTarget, hunks []Hunk) string

type UnifiedFormatOption added in v0.2.0

type UnifiedFormatOption struct {
	ColorMode           ColorMode
	IsHidingNoLFMessage bool
}

Jump to

Keyboard shortcuts

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