Documentation
¶
Overview ¶
Package diff ...
Index ¶
- Variables
- func Diff(x, y string) string
- func Format(ts []Token, theme Theme) string
- func Render(ts []Token) string
- func Split(s string) []string
- func Text(t Token) string
- func TokenizeLine(ctx context.Context, x, y string) ([]Token, []Token)
- func Words(ctx context.Context, lines []*TokenLine)
- type AddGutter
- type ConcatToken
- type DelGutter
- type SameGutter
- type SegToken
- type Styled
- type Theme
- type Token
- type TokenLine
- type Type
Constants ¶
This section is empty.
Variables ¶
var SplitKey = contextSplitKey{}
SplitKey is the context key used to override the default word-splitting function consumed by TokenizeLine.
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
ThemeNone colors for Sprint
Functions ¶
func Split ¶ added in v0.26.0
Split splits a line into words. Short lines are split per-rune; longer lines are split into alphabetic, digit, or single-character tokens.
func TokenizeLine ¶
TokenizeLine two different lines
Types ¶
type AddGutter ¶ added in v0.43.0
type AddGutter struct{ N, Xl, Yl int }
AddGutter renders the added-line gutter: "<Xl+1 spaces><N pad Yl> +".
type ConcatToken ¶ added in v0.43.0
type ConcatToken struct {
T Type
// contains filtered or unexported fields
}
ConcatToken holds a run of strSegs sharing one Type. Produced by mergeRuns so that merging is zero-copy: parts are concatenated only at Build time.
func (ConcatToken) Build ¶ added in v0.43.0
func (x ConcatToken) Build(sb *strings.Builder)
Build writes each part into sb in order.
type DelGutter ¶ added in v0.43.0
type DelGutter struct{ N, Xl, Yl int }
DelGutter renders the deleted-line gutter: "<N pad Xl> <Yl+1 spaces>-".
type SameGutter ¶ added in v0.43.0
type SameGutter struct{ A, B, Xl, Yl int }
SameGutter renders the unchanged-line gutter: "<A pad Xl> <B pad Yl> ".
func (SameGutter) Build ¶ added in v0.43.0
func (g SameGutter) Build(sb *strings.Builder)
Build writes the gutter into sb.
type SegToken ¶ added in v0.43.0
type SegToken struct {
T Type
// contains filtered or unexported fields
}
SegToken carries a single strSeg tagged with a Type.
type Styled ¶ added in v0.43.0
Styled wraps an inner token with ANSI styles applied at Build time.
type Token ¶
Token is a lazily-rendered piece of diff output.
func SpreadTokenLines ¶ added in v0.23.2
SpreadTokenLines to tokens
type TokenLine ¶ added in v0.23.2
TokenLine of tokens
func ParseTokenLines ¶ added in v0.23.2
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 )