diff

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package diff provides shared diff parsing and rendering utilities for the OpenCode TUI. This package contains common types and functions for rendering unified diffs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffHunk

type DiffHunk struct {
	OldStart int
	OldCount int
	NewStart int
	NewCount int
	Header   string
	Lines    []DiffLine
}

DiffHunk represents a hunk (group of changes) in a diff.

func ParseUnifiedDiff

func ParseUnifiedDiff(diffContent string) []DiffHunk

ParseUnifiedDiff parses a unified diff string into structured DiffHunks.

type DiffLine

type DiffLine struct {
	Content    string
	LineType   DiffLineType
	OldLineNum int
	NewLineNum int
}

DiffLine represents a single line in a diff with its metadata.

type DiffLineType

type DiffLineType string

DiffLineType represents the type of line in a diff.

const (
	DiffLineAdded   DiffLineType = "+"
	DiffLineRemoved DiffLineType = "-"
	DiffLineContext DiffLineType = " "
	DiffLineHunk    DiffLineType = "@@"
)

type Viewer

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

Viewer is a component for viewing file diffs with line-by-line coloring.

func NewViewer

func NewViewer() *Viewer

NewViewer creates a new diff viewer component.

func NewViewerWithMaxWidth

func NewViewerWithMaxWidth(maxWidth int) *Viewer

NewViewerWithMaxWidth creates a new diff viewer with the given maximum width.

func (*Viewer) Focused

func (dv *Viewer) Focused() bool

Focused returns whether the diff viewer is focused.

func (*Viewer) Init

func (dv *Viewer) Init() tea.Cmd

Init implements tea.Model interface.

func (*Viewer) Render

func (dv *Viewer) Render(diffContent string) string

Render renders the diff viewer and returns the formatted string.

func (*Viewer) RenderSimple

func (dv *Viewer) RenderSimple(diffContent string) string

RenderSimple renders a diff without borders, useful for inline display.

func (*Viewer) SetDiffContent

func (dv *Viewer) SetDiffContent(content string) string

SetDiffContent sets the diff content to display.

func (*Viewer) SetFocused

func (dv *Viewer) SetFocused(focused bool)

SetFocused sets the focused state of the diff viewer.

func (*Viewer) SetMaxWidth

func (dv *Viewer) SetMaxWidth(maxWidth int)

SetMaxWidth sets the maximum width for the diff viewer.

func (*Viewer) SetSize

func (dv *Viewer) SetSize(width, height int)

SetSize sets the dimensions of the diff viewer.

func (*Viewer) SetTheme

func (dv *Viewer) SetTheme(t theme.Theme)

SetTheme sets the theme for the diff viewer.

func (*Viewer) Update

func (dv *Viewer) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model interface.

func (*Viewer) View

func (dv *Viewer) View() string

View implements tea.Model interface.

Jump to

Keyboard shortcuts

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