diff

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyCommit

func ApplyCommit(commit Commit, writeFn func(string, string) error, removeFn func(string) error) error

func FormatDiff

func FormatDiff(diffText string, opts ...SideBySideOption) (string, error)

FormatDiff creates a side-by-side formatted view of a diff

func GenerateDiff

func GenerateDiff(beforeContent, afterContent, fileName string) (string, int, int)

GenerateDiff creates a unified diff from two file contents

func HighlightIntralineChanges

func HighlightIntralineChanges(h *Hunk)

HighlightIntralineChanges updates lines in a hunk to show character-level differences

func IdentifyFilesAdded

func IdentifyFilesAdded(text string) []string

func IdentifyFilesNeeded

func IdentifyFilesNeeded(text string) []string

func LoadFiles

func LoadFiles(paths []string, openFn func(string) (string, error)) (map[string]string, error)

func OpenFile

func OpenFile(p string) (string, error)

func ProcessPatch

func ProcessPatch(text string, openFn func(string) (string, error), writeFn func(string, string) error, removeFn func(string) error) (string, error)

func RemoveFile

func RemoveFile(p string) error

func RenderSideBySideHunk

func RenderSideBySideHunk(fileName string, h Hunk, opts ...SideBySideOption) string

RenderSideBySideHunk formats a hunk for side-by-side display

func SyntaxHighlight

func SyntaxHighlight(w io.Writer, source, fileName, formatter string, bg lipgloss.TerminalColor) error

SyntaxHighlight applies syntax highlighting to text based on file extension

func ValidatePatch

func ValidatePatch(patchText string, files map[string]string) (bool, string, error)

func WriteFile

func WriteFile(p string, content string) error

Types

type ActionType

type ActionType string
const (
	ActionAdd    ActionType = "add"
	ActionDelete ActionType = "delete"
	ActionUpdate ActionType = "update"
)

type Chunk

type Chunk struct {
	OrigIndex int      // line index of the first line in the original file
	DelLines  []string // lines to delete
	InsLines  []string // lines to insert
}

type Commit

type Commit struct {
	Changes map[string]FileChange
}

func AssembleChanges

func AssembleChanges(orig map[string]string, updatedFiles map[string]string) Commit

func PatchToCommit

func PatchToCommit(patch Patch, orig map[string]string) (Commit, error)

type DiffError

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

func NewDiffError

func NewDiffError(message string) DiffError

Helper functions for error handling

func (DiffError) Error

func (e DiffError) Error() string

type DiffLine

type DiffLine struct {
	OldLineNo int       // Line number in old file (0 for added lines)
	NewLineNo int       // Line number in new file (0 for removed lines)
	Kind      LineType  // Type of line (added, removed, context)
	Content   string    // Content of the line
	Segments  []Segment // Segments for intraline highlighting
}

DiffLine represents a single line in a diff

type DiffResult

type DiffResult struct {
	OldFile string
	NewFile string
	Hunks   []Hunk
}

DiffResult contains the parsed result of a diff

func ParseUnifiedDiff

func ParseUnifiedDiff(diff string) (DiffResult, error)

ParseUnifiedDiff parses a unified diff format string into structured data

type FileChange

type FileChange struct {
	Type       ActionType
	OldContent *string
	NewContent *string
	MovePath   *string
}

type Hunk

type Hunk struct {
	Header string
	Lines  []DiffLine
}

Hunk represents a section of changes in a diff

type LineType

type LineType int

LineType represents the kind of line in a diff.

const (
	LineContext LineType = iota // Line exists in both files
	LineAdded                   // Line added in the new file
	LineRemoved                 // Line removed from the old file
)

type ParseConfig

type ParseConfig struct {
	ContextSize int // Number of context lines to include
}

ParseConfig configures the behavior of diff parsing

type ParseOption

type ParseOption func(*ParseConfig)

ParseOption modifies a ParseConfig

func WithContextSize

func WithContextSize(size int) ParseOption

WithContextSize sets the number of context lines to include

type Parser

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

func NewParser

func NewParser(currentFiles map[string]string, lines []string) *Parser

func (*Parser) Parse

func (p *Parser) Parse() error

type Patch

type Patch struct {
	Actions map[string]PatchAction
}

func TextToPatch

func TextToPatch(text string, orig map[string]string) (Patch, int, error)

type PatchAction

type PatchAction struct {
	Type     ActionType
	NewFile  *string
	Chunks   []Chunk
	MovePath *string
}

type Segment

type Segment struct {
	Start int
	End   int
	Type  LineType
	Text  string
}

Segment represents a portion of a line for intra-line highlighting

type SideBySideConfig

type SideBySideConfig struct {
	TotalWidth int
}

SideBySideConfig configures the rendering of side-by-side diffs

func NewSideBySideConfig

func NewSideBySideConfig(opts ...SideBySideOption) SideBySideConfig

NewSideBySideConfig creates a SideBySideConfig with default values

type SideBySideOption

type SideBySideOption func(*SideBySideConfig)

SideBySideOption modifies a SideBySideConfig

func WithTotalWidth

func WithTotalWidth(width int) SideBySideOption

WithTotalWidth sets the total width for side-by-side view

Jump to

Keyboard shortcuts

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