diffview

package
v0.0.0-...-6b1cd05 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDiff

func FormatDiff(rawDiff string, width int, styles Styles) string

FormatDiff formats a raw unified diff string for display (thin wrapper).

func FormatDiffSummary

func FormatDiffSummary(rawDiff string) string

FormatDiffSummary formats a short summary of changes.

func HighlightDiff

func HighlightDiff(rawDiff string) string

HighlightDiff applies syntax highlighting to an entire diff.

func HighlightDiffLine

func HighlightDiffLine(content, filePath string) string

HighlightDiffLine applies syntax highlighting to a diff line's content.

Types

type ColumnSide

type ColumnSide int

ColumnSide represents which column is focused in side-by-side view.

const (
	ColumnNew ColumnSide = iota // right side, default
	ColumnOld                   // left side
)

type CommentMsg

type CommentMsg struct {
	FilePath   string
	LineNumber int
	LineType   git.DiffLineType
	Side       ColumnSide // which column the comment was made on
	Comment    string
}

CommentMsg is a single pending comment (used internally).

type DiffActionMsg

type DiffActionMsg int

DiffActionMsg represents an action to perform in the diff view.

const (
	DiffActionComment DiffActionMsg = iota
	DiffActionEditComment
	DiffActionSendComments
)

type DiffMode

type DiffMode int

DiffMode represents the current input mode of the diff view.

const (
	DiffModeNormal DiffMode = iota
	DiffModeSearch
	DiffModeComment
)

type DiffRefreshedMsg

type DiffRefreshedMsg struct {
	Diff string
}

DiffRefreshedMsg is emitted by manual refresh (r key) to force a rebuild.

type LineMetadata

type LineMetadata struct {
	FilePath   string
	LineNumber int // source line number from hunk header parsing
	LineType   git.DiffLineType
	IsHeader   bool // border, hunk header, or file list decoration line

	// Side-by-side column info
	OldLineNumber int              // left column line number (0 = blank)
	OldLineType   git.DiffLineType // left column line type
	NewLineNumber int              // right column line number (0 = blank)
	NewLineType   git.DiffLineType // right column line type
}

LineMetadata holds metadata about a rendered line for cursor/comment support.

func FormatDiffWithMetadata

func FormatDiffWithMetadata(rawDiff string, width int, styles Styles) ([]string, []LineMetadata)

FormatDiffWithMetadata formats a raw unified diff and returns per-line rendered strings plus parallel metadata for cursor/comment tracking.

type Model

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

Model is the diff view component.

func New

func New(p theme.ColorPalette, km *keys.KeyMap) Model

New creates a new diff view model.

func (*Model) ClickAt

func (m *Model) ClickAt(y int)

ClickAt moves the cursor to the line at the given Y offset within the viewport's visible area (0 = first visible line). Maps the display line to a source line, skipping injected comment lines.

func (Model) Diff

func (m Model) Diff() string

Diff returns the current raw diff.

func (Model) FileCount

func (m Model) FileCount() int

FileCount returns the number of changed files in the current diff.

func (*Model) ForceSetDiff

func (m *Model) ForceSetDiff(diff string)

ForceSetDiff sets the diff content and always rebuilds, even if unchanged. Used for manual refresh to guarantee visual feedback.

func (Model) Init

func (m Model) Init() tea.Cmd

Init implements tea.Model.

func (Model) Mode

func (m Model) Mode() DiffMode

Mode returns the current diff mode.

func (Model) RawDiffLines

func (m Model) RawDiffLines() int

RawDiffLines returns the number of lines in the raw diff.

func (*Model) ScrollBy

func (m *Model) ScrollBy(delta int)

ScrollBy scrolls the viewport by delta lines and adjusts the cursor to stay within the visible area. Maps display indices back to source lines.

func (Model) ScrollPercent

func (m Model) ScrollPercent() float64

ScrollPercent returns the current scroll position.

func (*Model) SetDiff

func (m *Model) SetDiff(diff string)

SetDiff sets the raw diff content. Skips rebuild if content is unchanged.

func (*Model) SetEditor

func (m *Model) SetEditor(editor string)

SetEditor sets the editor command.

func (*Model) SetFocused

func (m *Model) SetFocused(f bool)

SetFocused sets the focus state.

func (*Model) SetSize

func (m *Model) SetSize(w, h int)

SetSize sets the view dimensions.

func (*Model) SetWorkDir

func (m *Model) SetWorkDir(dir string)

SetWorkDir sets the working directory for diff computation.

func (Model) Update

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

Update implements tea.Model.

func (Model) View

func (m Model) View() string

View implements tea.Model.

type SendCommentsMsg

type SendCommentsMsg struct {
	Comments []CommentMsg
}

SendCommentsMsg is emitted when the user presses ctrl+s to send all pending comments.

type SideBySideLine

type SideBySideLine struct {
	OldNum     int    // 0 = blank/filler
	OldContent string // syntax-highlighted
	OldType    git.DiffLineType
	NewNum     int
	NewContent string
	NewType    git.DiffLineType
}

SideBySideLine holds a paired old/new line for side-by-side rendering.

type Styles

type Styles struct {
	AddedLine            lipgloss.Style
	RemovedLine          lipgloss.Style
	AddedLineBg          lipgloss.Style
	RemovedLineBg        lipgloss.Style
	ContextLine          lipgloss.Style
	HunkHeader           lipgloss.Style
	FileHeader           lipgloss.Style
	LineNumber           lipgloss.Style
	Border               lipgloss.Style
	FocusedBorder        lipgloss.Style
	Title                lipgloss.Style
	Empty                lipgloss.Style
	CursorLine           lipgloss.Style
	SearchMatch          lipgloss.Style
	SearchMatchCurrent   lipgloss.Style
	FileListItem         lipgloss.Style
	FileListItemAdded    lipgloss.Style
	FileListItemModified lipgloss.Style
	FileListItemDeleted  lipgloss.Style
	FileBorder           lipgloss.Style
	AddedPrefix          lipgloss.Style
	RemovedPrefix        lipgloss.Style
	Separator            lipgloss.Style
	BlankCell            lipgloss.Style
	ColumnFocus          lipgloss.Style
	CommentIndicator     lipgloss.Style
	CommentBorder        lipgloss.Style
	CommentText          lipgloss.Style
	CommentAuthor        lipgloss.Style
	Footer               lipgloss.Style
	FooterAccent         lipgloss.Style
	ScrollFilled         lipgloss.Style
	ScrollEmpty          lipgloss.Style
	ColumnDim            lipgloss.Style
	ChangeBarAdded       lipgloss.Style
	ChangeBarRemoved     lipgloss.Style
	HunkSeparator        lipgloss.Style
}

Styles holds all diff view styles.

func DefaultStyles

func DefaultStyles(p theme.ColorPalette) Styles

DefaultStyles returns the default diff view styles.

Jump to

Keyboard shortcuts

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