diff

package
v0.1.2-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package diff compares local and remote files and produces structured diff results.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderPanes

func RenderPanes(result *DiffResult, paneWidth, scrollOffset, count int) (left, right []string)

RenderPanes converts a DiffResult into two parallel slices of rendered strings (left = local, right = remote), each line padded to paneWidth columns. scrollOffset is the first DiffLine index to render; count is the number of rows.

Types

type DiffLine

type DiffLine struct {
	LocalLine  string
	RemoteLine string
	Kind       LineKind
	LocalNum   int // 0 = line not present on this side
	RemoteNum  int
}

DiffLine holds one line of a side-by-side diff.

type DiffResult

type DiffResult struct {
	LocalPath  string
	RemotePath string
	Lines      []DiffLine

	// Existence flags
	LocalOnly  bool // file exists only locally (not on remote)
	RemoteOnly bool // file exists only on remote

	// Metadata
	Binary     bool
	SizeLocal  int64
	SizeRemote int64
	ModLocal   time.Time
	ModRemote  time.Time
}

DiffResult is the comparison output for a single file pair.

func Compare

func Compare(localPath, remotePath string, client RemoteClient) (*DiffResult, error)

Compare produces a DiffResult for a local/remote file pair.

func (*DiffResult) HasDiff

func (r *DiffResult) HasDiff() bool

HasDiff returns true if the files differ in any way.

type LineKind

type LineKind int

LineKind classifies a line in a side-by-side diff.

const (
	LineEqual LineKind = iota
	LineAdded          // present on one side, absent on the other
	LineRemoved
	LineModified
)

type RemoteClient

type RemoteClient interface {
	Stat(path string) (os.FileInfo, error)
	ReadFile(path string) ([]byte, error)
}

RemoteClient is the subset of remote operations needed for diffing.

type Session

type Session struct {
	LocalPath  string
	RemotePath string
	Result     *DiffResult
	Loaded     bool
	Err        error
}

Session pairs a browser selection entry with its loaded DiffResult.

Jump to

Keyboard shortcuts

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