renderer

package
v0.2.1-0...-4d7afa4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package renderer contains the logic for formatting and displaying diffs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDiff

func FormatDiff(diffs []diffmatchpatch.Diff, options DiffOptions) string

FormatDiff formats a slice of diffs according to the provided options.

func GenerateDiffWithOptions

func GenerateDiffWithOptions(_ context.Context, current, desired *un.Unstructured, logger logging.Logger, _ DiffOptions) (*t.ResourceDiff, error)

GenerateDiffWithOptions produces a structured diff between two unstructured objects.

func GetLineDiff

func GetLineDiff(oldText, newText string) []diffmatchpatch.Diff

GetLineDiff performs a proper line-by-line diff and returns the raw diffs.

Types

type CompactDiffFormatter

type CompactDiffFormatter struct{}

CompactDiffFormatter formats diffs with limited context lines.

func (*CompactDiffFormatter) Format

func (f *CompactDiffFormatter) Format(diffs []diffmatchpatch.Diff, options DiffOptions) string

Format implements the DiffFormatter interface for CompactDiffFormatter.

type DefaultDiffRenderer

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

DefaultDiffRenderer implements the DiffRenderer interface.

func (*DefaultDiffRenderer) RenderDiffs

func (r *DefaultDiffRenderer) RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff) error

RenderDiffs formats and prints the diffs to the provided writer.

func (*DefaultDiffRenderer) SetDiffOptions

func (r *DefaultDiffRenderer) SetDiffOptions(options DiffOptions)

SetDiffOptions updates the diff options used by the renderer.

type DiffFormatter

type DiffFormatter interface {
	Format(diffs []diffmatchpatch.Diff, options DiffOptions) string
}

DiffFormatter is the interface that defines the contract for diff formatters.

func NewFormatter

func NewFormatter(compact bool) DiffFormatter

NewFormatter returns a DiffFormatter based on whether compact mode is desired.

type DiffOptions

type DiffOptions struct {
	// UseColors determines whether to colorize the output
	UseColors bool

	// AddPrefix is the prefix for added lines (default "+")
	AddPrefix string

	// DeletePrefix is the prefix for deleted lines (default "-")
	DeletePrefix string

	// ContextPrefix is the prefix for unchanged lines (default " ")
	ContextPrefix string

	// ContextLines is the number of unchanged lines to show before/after changes in compact mode
	ContextLines int

	// ChunkSeparator is the string used to separate chunks in compact mode
	ChunkSeparator string

	// Compact determines whether to show a compact diff
	Compact bool
}

DiffOptions holds configuration options for the diff output.

func DefaultDiffOptions

func DefaultDiffOptions() DiffOptions

DefaultDiffOptions returns the default options with colors enabled.

type DiffRenderer

type DiffRenderer interface {
	// RenderDiffs formats and outputs diffs to the provided writer
	RenderDiffs(stdout io.Writer, diffs map[string]*dt.ResourceDiff) error
}

DiffRenderer handles rendering diffs to output.

func NewDiffRenderer

func NewDiffRenderer(logger logging.Logger, diffOpts DiffOptions) DiffRenderer

NewDiffRenderer creates a new DefaultDiffRenderer with the given options.

type FullDiffFormatter

type FullDiffFormatter struct{}

FullDiffFormatter formats diffs with all context lines.

func (*FullDiffFormatter) Format

func (f *FullDiffFormatter) Format(diffs []diffmatchpatch.Diff, options DiffOptions) string

Format implements the DiffFormatter interface for FullDiffFormatter.

Directories

Path Synopsis
Package types provides types used in the renderer in order to facilitate code reuse in test
Package types provides types used in the renderer in order to facilitate code reuse in test

Jump to

Keyboard shortcuts

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