diffview

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package diffview renders a unified diff as a color-coded, scrollable terminal block. Additions are green, removals are red, hunk headers are highlighted, context lines are muted. Optional line numbers from either side of the diff.

The component is render-only: a consumer parses (or generates) a list of Line values, hands them to WithLines, and the view does the rest. A ParseUnified helper is provided for the common `diff -u` case.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind classifies a diff line.

const (
	KindContext Kind = iota
	KindAdded
	KindRemoved
	KindHunk // @@ -1,3 +1,4 @@
	KindFile // --- a/file, +++ b/file
)

type Line

type Line struct {
	Kind    Kind
	Old     int // 1-based old line number, 0 if not applicable
	New     int // 1-based new line number, 0 if not applicable
	Content string
}

Line is a single rendered row in the diff.

func ParseUnified

func ParseUnified(diff string) []Line

ParseUnified converts a standard unified-diff string into a slice of Line values. Lines starting with "+++", "---", "diff", or "index" are classified as KindFile. Lines starting with "@@" are KindHunk. The usual leading-space / + / - convention drives KindContext, KindAdded, KindRemoved.

type View

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

View is a Bubble Tea model that renders a slice of Line values.

func New

func New(t theme.Theme) View

New constructs an empty View with line numbers enabled.

func (View) Init

func (v View) Init() tea.Cmd

Init implements tea.Model.

func (View) Offset

func (v View) Offset() int

Offset returns the current scroll offset (lines from top).

func (View) TotalLines

func (v View) TotalLines() int

TotalLines returns the number of rendered rows. Equals len(WithLines).

func (View) Update

func (v View) Update(msg tea.Msg) (View, tea.Cmd)

Update handles scroll keys.

func (View) View

func (v View) View() string

View renders the visible window. Lines longer than the available content width are truncated with an ellipsis.

func (View) WithLineNumbers

func (v View) WithLineNumbers(show bool) View

WithLineNumbers toggles the left-side line-number columns.

func (View) WithLines

func (v View) WithLines(lines []Line) View

WithLines sets the diff content. Offset resets to 0.

func (View) WithSize

func (v View) WithSize(w, h int) View

WithSize sets rendered width and visible-row height.

Jump to

Keyboard shortcuts

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