diff

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package diff provides a minimal, reusable structured-data diff viewer for Bubble Tea applications.

The MVP focuses on a two-pane layout (list/detail), substring search, and value redaction. It intentionally defers exporters, plugin registries, multiple providers, and advanced renderers to future iterations.

Quick start:

provider := &StaticProvider{ /* implement DataProvider */ }
config := DefaultConfig()
config.Title = "My Diff"
model := NewModel(provider, config)
_ = tea.NewProgram(model, tea.WithAltScreen()).Run()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category interface {
	Name() string
	Changes() []Change
}

Category groups changes under a named section.

type Change

type Change interface {
	Path() string
	Status() ChangeStatus
	Before() any
	After() any
	Sensitive() bool
}

Change represents a single change, including before/after values.

type ChangeStatus

type ChangeStatus string

ChangeStatus represents the type of change in a diff line.

const (
	// ChangeStatusAdded indicates a value was added.
	ChangeStatusAdded ChangeStatus = "added"
	// ChangeStatusUpdated indicates a value was updated.
	ChangeStatusUpdated ChangeStatus = "updated"
	// ChangeStatusRemoved indicates a value was removed.
	ChangeStatusRemoved ChangeStatus = "removed"
)

type Config

type Config struct {
	Title               string
	RedactSensitive     bool
	SplitPaneRatio      float64 // default 0.35
	EnableSearch        bool
	EnableStatusFilters bool
	InitialFilter       StatusFilter
}

Config controls the diff model behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the diff model.

type DataProvider

type DataProvider interface {
	Title() string
	Items() []DiffItem
}

DataProvider supplies items to the diff model. Implementations can adapt any domain-specific structures into DiffItem.

type DiffItem

type DiffItem interface {
	ID() string
	Name() string
	Categories() []Category
}

DiffItem represents a logical entity with grouped changes.

type Model

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

Model implements the Bubble Tea model for the diff component.

func NewModel

func NewModel(provider DataProvider, config Config) Model

NewModel creates a new diff model with the given provider and configuration.

func NewModelWith

func NewModelWith(provider DataProvider, config Config, options ...Option) Model

NewModelWith creates a new diff model and applies optional Config options.

func (Model) Init

func (m Model) Init() tea.Cmd

func (*Model) SetRedactSensitive

func (m *Model) SetRedactSensitive(enabled bool)

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

func (*Model) SetSplitPaneRatio

func (m *Model) SetSplitPaneRatio(ratio float64)

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model) View

func (m Model) View() string

type Option

type Option func(*Config)

Option mutates the Config when building a Model.

func WithSearch

func WithSearch(enabled bool) Option

WithSearch enables or disables search UI and matching.

func WithStatusFilters

func WithStatusFilters(enabled bool, initial StatusFilter) Option

WithStatusFilters enables status filters and sets an initial value.

type StatusFilter

type StatusFilter struct {
	ShowAdded   bool
	ShowRemoved bool
	ShowUpdated bool
}

StatusFilter controls which change statuses are visible in detail view.

type Styles

type Styles struct {
	Title          lipgloss.Style
	ListBase       lipgloss.Style
	ListFocused    lipgloss.Style
	DetailBase     lipgloss.Style
	DetailFocused  lipgloss.Style
	CategoryHeader lipgloss.Style
	Path           lipgloss.Style
	RemovedLine    lipgloss.Style
	AddedLine      lipgloss.Style
	UpdatedLine    lipgloss.Style
	SensitiveValue lipgloss.Style
	BadgeAdded     lipgloss.Style
	BadgeRemoved   lipgloss.Style
	BadgeUpdated   lipgloss.Style
	FilterOn       lipgloss.Style
	FilterOff      lipgloss.Style
}

Styles contains style definitions used by the diff component.

Jump to

Keyboard shortcuts

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