diffviewer

package
v0.0.0-...-1b2216e Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DirHeaderHeight = 3

DirHeaderHeight is the height of the header band rendered above the diff viewport. Exported so callers translating mouse coordinates into content rows (see tui.go's diffPanePoint) can skip past it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	common.Common
	// contains filtered or unexported fields
}

func New

func New(sideBySide bool, theme string) Model

func (*Model) ClearCache

func (m *Model) ClearCache()

func (*Model) ClearSelection

func (m *Model) ClearSelection()

ClearSelection drops all selection state.

func (*Model) CurrentFilePath

func (m *Model) CurrentFilePath() string

CurrentFilePath returns the path of the currently displayed file, or "" if none.

func (*Model) DebugSelection

func (m *Model) DebugSelection() (anchor, head Point, band [2]int, active bool)

DebugSelection exposes the current selection's anchor/head/band for tests. Only intended for diagnostics — not part of any public contract.

func (*Model) EndSelection

func (m *Model) EndSelection() (string, bool)

EndSelection finalizes an active selection. If the head never moved away from the anchor it returns ("", false) with the selection cleared. Otherwise it returns (selectedText, true) and leaves the finalized highlight in place until the next event clears it.

func (*Model) ExtendSelection

func (m *Model) ExtendSelection(p Point)

ExtendSelection moves the selection head to p, clamping p.Col into the active colBand. The line axis is never clamped — vertical drag spans the full content. No-op when no drag is active.

func (*Model) GutterCol

func (m *Model) GutterCol() int

GutterCol returns the detected side-by-side divider column, or -1 for unified mode / undetected.

func (*Model) HasDir

func (m *Model) HasDir() bool

HasDir returns true when a directory patch is currently displayed.

func (*Model) HasFile

func (m *Model) HasFile() bool

HasFile returns true when a file patch is currently displayed.

func (*Model) HasSelection

func (m *Model) HasSelection() bool

HasSelection reports whether a finalized non-empty selection exists.

func (*Model) Height

func (m *Model) Height() int

Height returns the diff viewport's visible row count (excluding the dir-header band). Mouse-edge logic uses this to detect dragging past the pane edge.

func (Model) Init

func (m Model) Init() tea.Cmd

func (*Model) IsSelecting

func (m *Model) IsSelecting() bool

IsSelecting reports whether a drag is currently in progress.

func (*Model) RootDiffStats

func (m *Model) RootDiffStats() (int64, int64)

func (*Model) ScrollBottom

func (m *Model) ScrollBottom()

ScrollBottom scrolls the viewport to the bottom.

func (*Model) ScrollDown

func (m *Model) ScrollDown(lines int)

ScrollDown scrolls the viewport down by the given number of lines.

func (*Model) ScrollTop

func (m *Model) ScrollTop()

ScrollTop scrolls the viewport to its top.

func (*Model) ScrollUp

func (m *Model) ScrollUp(lines int)

ScrollUp scrolls the viewport up by the given number of lines.

func (*Model) SetContent

func (m *Model) SetContent(s string)

SetContent loads a string directly into the underlying viewport, bypassing the delta render pipeline. Intended for tests that need scrollable content without invoking the external delta binary.

func (*Model) SetDarkBackground

func (m *Model) SetDarkBackground(isDark bool) tea.Cmd

func (Model) SetDirPatch

func (m Model) SetDirPatch(dirPath string, files []*gitdiff.File) (Model, tea.Cmd)

func (Model) SetFilePatch

func (m Model) SetFilePatch(file *gitdiff.File) (Model, tea.Cmd)

func (*Model) SetPreamble

func (m *Model) SetPreamble(preamble string)

SetPreamble stores the preamble text (e.g. commit metadata from git show).

func (*Model) SetSideBySide

func (m *Model) SetSideBySide(sideBySide bool) tea.Cmd

SetSideBySide updates the diff view mode and re-renders.

func (*Model) SetSize

func (m *Model) SetSize(width, height int) tea.Cmd

func (*Model) StartSelection

func (m *Model) StartSelection(p Point)

StartSelection begins a new selection anchored at p. Derives colBand from p.Col, m.gutterCol, and the detected per-side content columns. The band excludes the leading border, line numbers, and post-LN border on whichever side the click landed.

Lines without the standard side-by-side layout — hunk-header boxes ("60: struct …"), filename decorations, separators — opt out of side- specific clamping so the user can select content that lives outside the post-line-number borders. Sets active=true, has=false. Any prior selection is replaced.

func (*Model) TotalLineCount

func (m *Model) TotalLineCount() int

TotalLineCount returns the number of content lines currently loaded into the viewport.

func (Model) Update

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

func (Model) View

func (m Model) View() string

func (*Model) Width

func (m *Model) Width() int

Width returns the diff viewport's content column count (excluding the scrollbar gutter).

func (*Model) YOffset

func (m *Model) YOffset() int

YOffset returns the viewport's current top content row.

type Point

type Point struct {
	Line int
	Col  int
}

Point identifies a position within the rendered diff content.

Col is a *visual column* — the same coordinate space as paneX and ansi.Cut/lipgloss.Width — never a rune index or byte offset. Callers must translate any rune-index-derived value into visual columns before storing it in a Point.

Jump to

Keyboard shortcuts

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