diffview

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package diffview renders unified diffs from `gh pr diff` in a TUI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Path  string
	Adds  int
	Dels  int
	Lines []Line
}

File is one file's worth of changes from a unified diff.

func Parse

func Parse(diff string) []File

Parse splits a unified diff (as produced by `gh pr diff --patch` or `git diff`) into per-file blocks. Adds/Dels are counted only for content lines (not file/hunk headers). The parser is intentionally lenient: any content that doesn't match an expected prefix is treated as context.

type Highlighter

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

Highlighter colorizes diff content lines using chroma based on file extension. Lexers and the formatter are looked up once per extension and reused. When NO_COLOR is set or the lexer is unknown, Highlight returns the input unchanged.

func NewHighlighter

func NewHighlighter() *Highlighter

func (*Highlighter) Highlight

func (h *Highlighter) Highlight(path, src string) string

Highlight returns the colorized form of src for the lexer matching path's extension. Falls back to src on any error or when disabled.

type Line

type Line struct {
	Kind LineKind
	Text string
}

Line is one rendered line of the diff (file header, hunk header, or content). Kind drives coloring; Text is the raw text without trailing newline.

type LineKind

type LineKind int
const (
	LineContext   LineKind = iota // " foo"
	LineAdd                       // "+foo"
	LineDel                       // "-foo"
	LineFile                      // "diff --git ..." / "--- a/" / "+++ b/"
	LineHunk                      // "@@ -1,3 +1,4 @@"
	LineNoNewLine                 // "\ No newline at end of file"
)

type Model

type Model struct {
	Title string // e.g. "#687 wall drawing UX"
	Files []File
	// contains filtered or unexported fields
}

Model is the bubbletea model for the PR diff viewer.

func New

func New(title string, files []File) Model

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model) View

func (m Model) View() string

Jump to

Keyboard shortcuts

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