diffpreview

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderYAML

func RenderYAML(node *AnnotatedNode, theme Theme, opts RenderOptions) string

RenderYAML turns an AnnotatedNode tree into syntax-highlighted YAML with colored backgrounds on changed lines.

Types

type AnnotatedNode

type AnnotatedNode struct {
	Value    any
	Change   ChangeType
	Children map[string]*AnnotatedNode
	List     []*AnnotatedNode
}

AnnotatedNode represents a single node in the diff tree.

A node is exactly one of: a map (Children is set), a list (List is set), or a scalar leaf (Value is set). Change records what happened to the node between the old and new versions.

func Diff

func Diff(a, b map[string]any) *AnnotatedNode

Diff compares two maps and returns a tree where every node is annotated with a ChangeType. Pass the result to RenderYAML to get highlighted output.

type ChangeType

type ChangeType int
const (
	Unchanged ChangeType = iota
	Added
	Removed
	Modified
)

type RenderOptions

type RenderOptions struct {
	IndentSize                int
	EnableBackgroundHighlight bool
	// ChangesOnly, when true, omits map keys and list items that have no
	// changes anywhere in their subtree, producing a compact diff that shows
	// only what changed (with the surrounding path kept for context).
	ChangesOnly bool
}

type Theme

type Theme struct {
	KeyStyle    lipgloss.Style
	StringStyle lipgloss.Style
	NumberStyle lipgloss.Style
	BoolStyle   lipgloss.Style
	NullStyle   lipgloss.Style

	AddedBg    lipgloss.Style
	RemovedBg  lipgloss.Style
	ModifiedBg lipgloss.Style
}

Theme defines the colours used when rendering YAML diffs.

Jump to

Keyboard shortcuts

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