patchview

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(patches []*diferenco.Patch, opts ...Option) error

Run starts the interactive patch navigation view.

Types

type CursorSetter

type CursorSetter interface {
	SetCursor(idx int)
}

CursorSetter is an optional interface for StatusBar implementations that need to be notified when the cursor changes.

type DefaultStatusBar

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

DefaultStatusBar is the default status bar implementation. It displays: status + separator + path + stats + file count.

func NewDefaultStatusBar

func NewDefaultStatusBar() *DefaultStatusBar

NewDefaultStatusBar creates a new DefaultStatusBar.

func (*DefaultStatusBar) Height

func (s *DefaultStatusBar) Height() int

Height returns the height of the status bar (always 1).

func (*DefaultStatusBar) SetCursor

func (s *DefaultStatusBar) SetCursor(idx int)

SetCursor sets the current cursor position.

func (*DefaultStatusBar) SetPatches

func (s *DefaultStatusBar) SetPatches(patches []*diferenco.Patch)

SetPatches sets the patches data.

func (*DefaultStatusBar) SetStyle

func (s *DefaultStatusBar) SetStyle(style PatchViewStyle)

SetStyle sets the style for the status bar.

func (*DefaultStatusBar) View

func (s *DefaultStatusBar) View(width int) string

View renders the status bar.

type DiffViewStyle

type DiffViewStyle struct {
	DividerLine LineStyle      // Hunk divider line style (@@ -1,3 +1,4 @@)
	MissingLine LineStyle      // Missing line style (used in Split view)
	EqualLine   LineStyle      // Unchanged line style
	InsertLine  LineStyle      // Inserted line style
	DeleteLine  LineStyle      // Deleted line style
	FileName    lipgloss.Style // File name style
	FileMeta    lipgloss.Style // File metadata style
}

DiffViewStyle defines the complete style for DiffView.

func DefaultDarkDiffViewStyle

func DefaultDarkDiffViewStyle() DiffViewStyle

DefaultDarkDiffViewStyle returns the dark theme style.

func DefaultDiffViewStyle

func DefaultDiffViewStyle() DiffViewStyle

DefaultDiffViewStyle automatically selects theme based on terminal background.

func DefaultLightDiffViewStyle

func DefaultLightDiffViewStyle() DiffViewStyle

DefaultLightDiffViewStyle returns the light theme style. Color scheme based on One Light Pro (clear, bright, moderate contrast).

type LineStyle

type LineStyle struct {
	LineNumber lipgloss.Style // Line number style
	Code       lipgloss.Style // Code content style
}

LineStyle defines the style for a single line.

type Option

type Option func(*PatchView)

Option configures the patch view.

func WithListWidth

func WithListWidth(pct int) Option

WithListWidth sets the file list width percentage (default 20).

func WithStatusBar

func WithStatusBar(sb StatusBar) Option

WithStatusBar sets a custom status bar.

func WithStyle

func WithStyle(style PatchViewStyle) Option

WithStyle sets a custom style.

type PatchRenderer

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

PatchRenderer renders a diferenco.Patch for display. It handles line numbers, syntax highlighting, and horizontal scrolling.

func NewPatchRenderer

func NewPatchRenderer() *PatchRenderer

NewPatchRenderer creates a new PatchRenderer with default style.

func (*PatchRenderer) HunkOffsets

func (r *PatchRenderer) HunkOffsets() []int

HunkOffsets returns the starting line offset for each hunk. This is used for [ and ] navigation between hunks.

func (*PatchRenderer) Render

func (r *PatchRenderer) Render() string

Render renders the patch content for the current viewport.

func (*PatchRenderer) SetDarkBackground

func (r *PatchRenderer) SetDarkBackground(dark bool)

SetDarkBackground sets the terminal background mode.

func (*PatchRenderer) SetLineNumbers

func (r *PatchRenderer) SetLineNumbers(enabled bool)

SetLineNumbers sets whether to show line numbers.

func (*PatchRenderer) SetPatch

func (r *PatchRenderer) SetPatch(p *diferenco.Patch)

SetPatch sets the patch to render.

func (*PatchRenderer) SetSize

func (r *PatchRenderer) SetSize(width, height int)

SetSize sets the rendering area size.

func (*PatchRenderer) SetStyle

func (r *PatchRenderer) SetStyle(style PatchViewStyle)

SetStyle sets the style for rendering.

func (*PatchRenderer) SetSyntaxHighlight

func (r *PatchRenderer) SetSyntaxHighlight(enabled bool)

SetSyntaxHighlight sets whether to enable syntax highlighting.

func (*PatchRenderer) SetXOffset

func (r *PatchRenderer) SetXOffset(offset int)

SetXOffset sets the horizontal scroll offset. Note: Unlike SetYOffset, there's no upper bound because line widths vary and may contain ANSI escape sequences. The render function handles out-of-bounds offsets gracefully by showing empty content.

func (*PatchRenderer) SetYOffset

func (r *PatchRenderer) SetYOffset(offset int)

SetYOffset sets the vertical scroll offset.

func (*PatchRenderer) TotalLines

func (r *PatchRenderer) TotalLines() int

TotalLines returns the total number of lines in the patch.

func (*PatchRenderer) XOffset

func (r *PatchRenderer) XOffset() int

XOffset returns the current horizontal offset.

func (*PatchRenderer) YOffset

func (r *PatchRenderer) YOffset() int

YOffset returns the current vertical offset.

type PatchView

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

PatchView is an interactive patch navigation view.

func NewPatchView

func NewPatchView(patches []*diferenco.Patch, opts ...Option) *PatchView

NewPatchView creates a new PatchView.

func (*PatchView) Init

func (pv *PatchView) Init() tea.Cmd

func (*PatchView) Update

func (pv *PatchView) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*PatchView) View

func (pv *PatchView) View() tea.View

type PatchViewStyle

type PatchViewStyle struct {
	// File list styles
	Addition lipgloss.Style
	Deletion lipgloss.Style
	Selected lipgloss.Style

	// Diff view styles (using LineStyle for background fill)
	DiffStyle DiffViewStyle

	// UI styles
	HeaderBg    lipgloss.Style
	FileCount   lipgloss.Style
	Separator   lipgloss.Style
	PathDisplay lipgloss.Style
	FilesTitle  lipgloss.Style
	FooterBg    lipgloss.Style

	// Status styles for header
	StatusAdded    lipgloss.Style
	StatusDeleted  lipgloss.Style
	StatusRenamed  lipgloss.Style
	StatusModified lipgloss.Style
}

PatchViewStyle defines the visual style for the patch view.

func DefaultDarkStyle

func DefaultDarkStyle() PatchViewStyle

DefaultDarkStyle returns the dark theme style.

func DefaultLightStyle

func DefaultLightStyle() PatchViewStyle

DefaultLightStyle returns the light theme style.

func DefaultStyle

func DefaultStyle() PatchViewStyle

DefaultStyle returns the default style with auto-detected theme.

type PatchesSetter

type PatchesSetter interface {
	SetPatches(patches []*diferenco.Patch)
}

PatchesSetter is an optional interface for StatusBar implementations that need access to the patches data.

type StatusBar

type StatusBar interface {
	View(width int) string
	Height() int
}

StatusBar is the interface for rendering a status bar in the patch view.

type SyntaxHighlighter

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

SyntaxHighlighter is a syntax highlighter.

func NewSyntaxHighlighter

func NewSyntaxHighlighter(filename string, isDark bool) *SyntaxHighlighter

NewSyntaxHighlighter creates a syntax highlighter. filename: used for language detection isDark: whether the background is dark

func (*SyntaxHighlighter) ClearCache

func (h *SyntaxHighlighter) ClearCache()

ClearCache clears the cache.

func (*SyntaxHighlighter) Enabled

func (h *SyntaxHighlighter) Enabled() bool

Enabled returns whether the highlighter is enabled.

func (*SyntaxHighlighter) Highlight

func (h *SyntaxHighlighter) Highlight(source, bgColor string) string

Highlight highlights code. source: original code bgColor: background color (hex format, e.g. "#303a30")

Jump to

Keyboard shortcuts

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