diff

package
v0.33.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: MIT Imports: 6 Imported by: 0

README

Overview

A simple lib to diff two string with pretty output. It also provide some low-level API to customize the output.

Documentation

Overview

Package diff ...

Index

Constants

This section is empty.

Variables

View Source
var ThemeDefault = func(t Type) []gop.Style {
	switch t {
	case AddSymbol:
		return []gop.Style{gop.Green}
	case DelSymbol:
		return []gop.Style{gop.Red}
	case AddWords:
		return []gop.Style{gop.Green}
	case DelWords:
		return []gop.Style{gop.Red}
	case ChunkStart:
		return []gop.Style{gop.Black, gop.BgMagenta}
	}
	return []gop.Style{gop.None}
}

ThemeDefault colors for Sprint

View Source
var ThemeNone = func(t Type) []gop.Style {
	return []gop.Style{gop.None}
}

ThemeNone colors for Sprint

Functions

func Diff

func Diff(x, y string) string

Diff x and y into a human readable string.

func Format

func Format(ts []*Token, theme Theme) string

Format tokens into a human readable string

func TokenizeLine

func TokenizeLine(ctx context.Context, x, y string) ([]*Token, []*Token)

TokenizeLine two different lines

func Words added in v0.26.0

func Words(ctx context.Context, lines []*TokenLine)

Words diff

Types

type Theme added in v0.24.0

type Theme func(t Type) []gop.Style

Theme for diff

type Token

type Token struct {
	Type    Type
	Literal string
}

Token presents a symbol in diff layout

func SpreadTokenLines added in v0.23.2

func SpreadTokenLines(lines []*TokenLine) []*Token

SpreadTokenLines to tokens

func Tokenize added in v0.24.0

func Tokenize(ctx context.Context, x, y string) []*Token

Tokenize x and y into diff tokens with diff words and narrow chunks.

func TokenizeText

func TokenizeText(ctx context.Context, x, y string) []*Token

TokenizeText text block a and b into diff tokens.

type TokenLine added in v0.23.2

type TokenLine struct {
	Type   Type
	Tokens []*Token
}

TokenLine of tokens

func Narrow added in v0.23.2

func Narrow(n int, lines []*TokenLine) []*TokenLine

Narrow the context around each diff section to n lines.

func ParseTokenLines added in v0.23.2

func ParseTokenLines(ts []*Token) []*TokenLine

ParseTokenLines of tokens

type Type

type Type int

Type of token

const (
	// Newline type
	Newline Type = iota
	// Space type
	Space

	// ChunkStart type
	ChunkStart
	// ChunkEnd type
	ChunkEnd

	// SameSymbol type
	SameSymbol
	// SameLine type
	SameLine

	// AddSymbol type
	AddSymbol
	// AddLine type
	AddLine

	// DelSymbol typ
	DelSymbol
	// DelLine type
	DelLine

	// SameWords type
	SameWords
	// AddWords type
	AddWords
	// DelWords type
	DelWords

	// EmptyLine type
	EmptyLine
)

Jump to

Keyboard shortcuts

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