diff

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 7 Imported by: 0

README

Overview

A simple lib to diff two string with pretty output.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTheme = func(t Type) gop.Color {
	switch t {
	case AddSymbol, AddLine:
		return gop.Green
	case DelSymbol, DelLine:
		return gop.Red
	}
	return gop.None
}

DefaultTheme colors for Sprint

View Source
var NoTheme = func(t Type) gop.Color {
	return gop.None
}

NoTheme 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 func(Type) gop.Color) string

Format tokens into a human readable string

func TokenizeLine

func TokenizeLine(x, y string) ([]*Token, []*Token)

TokenizeLine two different lines

Types

type Char

type Char rune

Char is a rune

func (Char) Hash

func (c Char) Hash() []byte

Hash interface

type Comparable

type Comparable interface {
	// Hash for comparison
	Hash() []byte
}

Comparable interface

func LCS

func LCS(x, y []Comparable) []Comparable

LCS computes the lcs of x and y

type Line

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

Line of a string for fast comparison.

func NewLine

func NewLine(b []byte) *Line

NewLine from bytes

func (*Line) Hash

func (c *Line) Hash() []byte

Hash interface

type String

type String []Comparable

String of Char list

func NewString

func NewString(s string) String

NewString from string

func (String) String

func (s String) String() string

String interface

type Text

type Text []Comparable

Text of Char list

func NewText

func NewText(s string) Text

NewText from string. It will split the s via newlines.

func (Text) String

func (s Text) String() string

String interface

type Token

type Token struct {
	Type    Type
	Literal string
}

Token presents a symbol in diff layout

func TokenizeText

func TokenizeText(x, y string) []*Token

TokenizeText text block a and b into diff tokens.

type Type

type Type int

Type of token

const (
	// LineNum type
	LineNum Type = iota

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