Documentation
¶
Overview ¶
Package diffviewer provides keybinding-to-command mapping for the diff viewer.
Package diffviewer provides a context-sensitive help overlay for the diff viewer.
Package diffviewer provides a TUI component for viewing git diffs.
Package diffviewer provides a TUI component for viewing git diffs.
Index ¶
- Constants
- func RenderScrollbar(cfg ScrollbarConfig) string
- type BranchesLoadedMsg
- type CacheMetrics
- type CommitFilesLoadedMsg
- type CommitPreviewLoadedMsg
- type CommitsForBranchLoadedMsg
- type CommitsLoadedMsg
- type DiffError
- type DiffFile
- type DiffHunk
- type DiffLine
- type ErrorCategory
- type FileTree
- type FileTreeNode
- type HideDiffViewerMsg
- type HunkCopiedMsg
- type LineType
- type Model
- func (m Model) Hide() Model
- func (m Model) Init() tea.Cmd
- func (m Model) LoadCommitFiles(hash string) tea.Cmd
- func (m Model) LoadCommitPreview(hash string) tea.Cmd
- func (m Model) LoadCommits() tea.Cmd
- func (m Model) LoadWorkingDirDiff() tea.Cmd
- func (m Model) Overlay(bg string) string
- func (m Model) SetClipboard(clipboard shared.Clipboard) Model
- func (m Model) SetClock(clock shared.Clock) Model
- func (m Model) SetGitExecutor(ge appgit.GitExecutor) Model
- func (m Model) SetSize(width, height int) Model
- func (m Model) Show() Model
- func (m Model) ShowAndLoad() (Model, tea.Cmd)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- func (m Model) Visible() bool
- type RenderCache
- func (c *RenderCache) ByteSize() int64
- func (c *RenderCache) Clear()
- func (c *RenderCache) Get(key RenderCacheKey) (string, bool)
- func (c *RenderCache) GetMetrics() CacheMetrics
- func (c *RenderCache) Put(key RenderCacheKey, value string)
- func (c *RenderCache) ResetMetrics()
- func (c *RenderCache) SetTheme(theme string) bool
- func (c *RenderCache) SetViewMode(mode ViewMode) bool
- func (c *RenderCache) Size() int
- func (c *RenderCache) Theme() string
- func (c *RenderCache) ViewMode() ViewMode
- type RenderCacheKey
- type ScrollbarConfig
- type ShowDiffViewerMsg
- type SideBySideLine
- type ViewMode
- type ViewModeConstrainedMsg
- type VirtualContent
- func (vc *VirtualContent) GetCacheHitRate() float64
- func (vc *VirtualContent) GetCacheMetrics() CacheMetrics
- func (vc *VirtualContent) InvalidateCache()
- func (vc *VirtualContent) RenderVisible() string
- func (vc *VirtualContent) SetTheme(theme string) bool
- func (vc *VirtualContent) SetViewMode(mode ViewMode) bool
- func (vc *VirtualContent) SetVisibleRange(scrollTop, viewportHeight int)
- func (vc *VirtualContent) SetWidth(width int)
- type VirtualContentConfig
- type VirtualLine
- type VirtualViewport
- func (vv *VirtualViewport) AtBottom() bool
- func (vv *VirtualViewport) AtTop() bool
- func (vv *VirtualViewport) EnsureVisible(lineIndex int) bool
- func (vv *VirtualViewport) GetCacheHitRate() float64
- func (vv *VirtualViewport) GetCacheMetrics() CacheMetrics
- func (vv *VirtualViewport) GotoBottom()
- func (vv *VirtualViewport) GotoTop()
- func (vv *VirtualViewport) HalfPageDown()
- func (vv *VirtualViewport) HalfPageUp()
- func (vv *VirtualViewport) Height() int
- func (vv *VirtualViewport) InvalidateCache()
- func (vv *VirtualViewport) LineRange() (start, end int)
- func (vv *VirtualViewport) PageDown()
- func (vv *VirtualViewport) PageUp()
- func (vv *VirtualViewport) PastEnd() bool
- func (vv *VirtualViewport) Render() string
- func (vv *VirtualViewport) ScrollDown(n int)
- func (vv *VirtualViewport) ScrollPercent() float64
- func (vv *VirtualViewport) ScrollToLine(lineIndex int)
- func (vv *VirtualViewport) ScrollToPercent(percent float64)
- func (vv *VirtualViewport) ScrollUp(n int)
- func (vv *VirtualViewport) SetSize(width, height int)
- func (vv *VirtualViewport) SetTheme(theme string) bool
- func (vv *VirtualViewport) SetViewMode(mode ViewMode) bool
- func (vv *VirtualViewport) SetYOffset(offset int)
- func (vv *VirtualViewport) TotalLines() int
- func (vv *VirtualViewport) VirtualContent() *VirtualContent
- func (vv *VirtualViewport) VisibleLineCount() int
- func (vv *VirtualViewport) Width() int
- func (vv *VirtualViewport) YOffset() int
- type WorkingDirDiffLoadedMsg
- type WorktreesLoadedMsg
Constants ¶
const ( // WordDiffMaxLineLength skips word diff for lines exceeding this length. WordDiffMaxLineLength = 500 // WordDiffMaxPairs limits word diff computation to first N pairs per hunk. WordDiffMaxPairs = 100 // WordDiffTimeout is the maximum time allowed for word diff per file. WordDiffTimeout = 50 * time.Millisecond )
Word diff constants for performance bounds.
const DefaultMaxCacheBytes = 10 * 1024 * 1024
DefaultMaxCacheBytes is the default memory limit for the cache (~10MB).
Variables ¶
This section is empty.
Functions ¶
func RenderScrollbar ¶
func RenderScrollbar(cfg ScrollbarConfig) string
RenderScrollbar renders the scrollbar as a string (height lines joined by \n). Returns empty string if config is invalid or content fits in viewport. Simple scrollbar: track (░) and thumb (█) to show scroll position.
Types ¶
type BranchesLoadedMsg ¶
type BranchesLoadedMsg struct {
Branches []domaingit.BranchInfo
Err error
}
BranchesLoadedMsg carries the list of available branches.
type CacheMetrics ¶
type CacheMetrics struct {
Hits uint64 // Number of cache hits
Misses uint64 // Number of cache misses
Evictions uint64 // Number of entries evicted
SizeEvicts uint64 // Number of evictions due to size limit
}
CacheMetrics tracks cache performance statistics.
func (CacheMetrics) HitRate ¶
func (m CacheMetrics) HitRate() float64
HitRate returns the cache hit rate as a percentage (0-100). Returns 0 if no requests have been made.
type CommitFilesLoadedMsg ¶
type CommitFilesLoadedMsg struct {
Hash string // Commit hash this load was for
Files []DiffFile
Err error
}
CommitFilesLoadedMsg carries parsed files for a specific commit.
type CommitPreviewLoadedMsg ¶
type CommitPreviewLoadedMsg struct {
Hash string // Commit hash this preview is for
Files []DiffFile // All files changed in the commit
Err error
}
CommitPreviewLoadedMsg carries parsed diff for commit preview in ListMode.
type CommitsForBranchLoadedMsg ¶
type CommitsForBranchLoadedMsg struct {
Commits []domaingit.CommitInfo
Branch string // Branch name the commits are from
Err error
}
CommitsForBranchLoadedMsg carries commits loaded for a specific branch.
type CommitsLoadedMsg ¶
type CommitsLoadedMsg struct {
Commits []domaingit.CommitInfo
Branch string
Err error
}
CommitsLoadedMsg carries parsed commit history back to the model.
type DiffError ¶
type DiffError struct {
Category ErrorCategory // Type of error for determining recovery actions
Message string // Human-readable error message
HelpText string // Additional guidance for the user
}
DiffError represents an error with recovery information for the diffviewer.
func NewDiffError ¶
func NewDiffError(category ErrorCategory, message string) DiffError
NewDiffError creates a new DiffError with the given category and message.
func (DiffError) WithHelpText ¶
WithHelpText sets additional help text for the error.
type DiffFile ¶
type DiffFile struct {
OldPath string // Path in old version (or /dev/null for new files)
NewPath string // Path in new version (or /dev/null for deleted files)
Additions int // Count of added lines
Deletions int // Count of deleted lines
IsBinary bool // True if file is binary
IsRenamed bool // True if file was renamed
IsNew bool // True if new file (OldPath = /dev/null)
IsDeleted bool // True if deleted file (NewPath = /dev/null)
IsUntracked bool // True if untracked file (not yet staged)
Similarity int // Rename similarity percentage (0-100)
Hunks []DiffHunk
}
DiffFile represents a single file's changes in a diff.
type DiffHunk ¶
type DiffHunk struct {
OldStart int // Starting line number in old file
OldCount int // Number of lines from old file
NewStart int // Starting line number in new file
NewCount int // Number of lines from new file
Header string // The @@ line text
Lines []DiffLine
}
DiffHunk represents a contiguous section of changes in a diff.
type DiffLine ¶
type DiffLine struct {
Type LineType // Addition, Deletion, Context, or HunkHeader
OldLineNum int // Line number in old file (0 if addition)
NewLineNum int // Line number in new file (0 if deletion)
Content string // Line content without +/- prefix
}
DiffLine represents a single line in a diff hunk.
type ErrorCategory ¶
type ErrorCategory int
ErrorCategory represents the category of a diff error for recovery actions.
const ( // ErrCategoryParse indicates a parse error - show raw diff option. ErrCategoryParse ErrorCategory = iota // ErrCategoryGitOp indicates a git operation error - retry button. ErrCategoryGitOp // ErrCategoryPermission indicates a permission error - explain & suggest. ErrCategoryPermission // ErrCategoryConflict indicates a conflict error - reload button. ErrCategoryConflict // ErrCategoryTimeout indicates a timeout error - retry with longer timeout. ErrCategoryTimeout )
func (ErrorCategory) String ¶
func (c ErrorCategory) String() string
String returns a human-readable name for the error category.
type FileTree ¶
type FileTree struct {
Root []*FileTreeNode // Top-level nodes
// contains filtered or unexported fields
}
FileTree manages the tree structure for displaying changed files.
func NewFileTree ¶
NewFileTree creates a new file tree from a list of diff files. All directories start expanded by default.
func (*FileTree) Toggle ¶
func (ft *FileTree) Toggle(node *FileTreeNode) bool
Toggle toggles the expanded state of a directory node. Returns true if state was changed.
func (*FileTree) VisibleNodes ¶
func (ft *FileTree) VisibleNodes() []*FileTreeNode
VisibleNodes returns a flattened list of currently visible nodes. Respects expanded/collapsed state of directories.
type FileTreeNode ¶
type FileTreeNode struct {
Name string // Just the filename/dirname component
Path string // Full path from root
IsDir bool // True if this is a directory
Expanded bool // True if directory is expanded (shows children)
Children []*FileTreeNode // Child nodes (sorted: dirs first, then files, alphabetically)
File *DiffFile // Reference to the DiffFile (nil for directories)
Depth int // Nesting depth (0 for root-level items)
}
FileTreeNode represents a node in the file tree (either a directory or file).
func (*FileTreeNode) CollectFiles ¶
func (node *FileTreeNode) CollectFiles() []*DiffFile
CollectFiles returns all DiffFiles under this node. For files, returns a slice with just the file. For directories, collects all descendant files.
func (*FileTreeNode) FileCount ¶
func (node *FileTreeNode) FileCount() int
FileCount returns the number of files under this node. For files, returns 1. For directories, counts all descendant files.
func (*FileTreeNode) TotalStats ¶
func (node *FileTreeNode) TotalStats() (additions, deletions int)
TotalStats calculates total additions and deletions for a node. For directories, this sums all descendant files.
type HideDiffViewerMsg ¶
type HideDiffViewerMsg struct{}
HideDiffViewerMsg requests hiding the diff viewer.
type HunkCopiedMsg ¶
type HunkCopiedMsg struct {
LineCount int // Number of lines copied
Err error // Error if copy failed
}
HunkCopiedMsg is returned when a hunk has been copied to the clipboard.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the diff viewer component state.
func NewWithGitExecutor ¶
func NewWithGitExecutor(ge appgit.GitExecutor) Model
NewWithGitExecutor creates a new diff viewer model with a git executor.
func NewWithGitExecutorFactory ¶
func NewWithGitExecutorFactory(factory func(string) appgit.GitExecutor, initialPath string) Model
NewWithGitExecutorFactory creates a diff viewer with a factory for git executors. This enables worktree switching by creating new executors for different paths. The factory function is called to create new git executors when switching worktrees. If factory is non-nil and initialPath is non-empty, creates an initial executor.
func (Model) LoadCommitFiles ¶
LoadCommitFiles creates a command to asynchronously fetch files changed in a specific commit.
func (Model) LoadCommitPreview ¶
LoadCommitPreview creates a command to asynchronously fetch the full diff for a commit preview. This is used when a commit is highlighted in ListMode to show the full diff in the diff pane. NOTE: Callers must set m.previewCommitHash and m.previewCommitLoading = true before calling, since this method uses a value receiver and cannot modify the caller's model.
func (Model) LoadCommits ¶
LoadCommits creates a command to asynchronously fetch commit history. Loads up to 50 commits and the current branch name. Handles ErrDetachedHead by using "HEAD" as the branch name.
func (Model) LoadWorkingDirDiff ¶
LoadWorkingDirDiff creates a command to asynchronously fetch working directory changes.
func (Model) SetClipboard ¶
SetClipboard sets the clipboard for copy operations.
func (Model) SetGitExecutor ¶
func (m Model) SetGitExecutor(ge appgit.GitExecutor) Model
SetGitExecutor sets the git executor for diff operations.
func (Model) SetSize ¶
SetSize updates the overlay's knowledge of viewport size. If the terminal is too narrow for side-by-side view and the user prefers it, the effective view mode is constrained to unified.
func (Model) Show ¶
Show makes the overlay visible and sets loading state. Resets both file and commit state.
func (Model) ShowAndLoad ¶
ShowAndLoad makes the overlay visible and returns commands to load both working directory diff and commit history concurrently. Also pre-loads branches and worktrees to avoid flash when switching tabs. This is the preferred way to show the diff viewer.
type RenderCache ¶
type RenderCache struct {
// Metrics
Metrics CacheMetrics
// contains filtered or unexported fields
}
RenderCache is an LRU cache for rendered line strings. It has both item count and memory size limits for bounded resource usage. Eviction occurs when either limit is exceeded (whichever is hit first).
func NewRenderCache ¶
func NewRenderCache(capacity int) *RenderCache
NewRenderCache creates a new LRU cache with the given item capacity. Uses DefaultMaxCacheBytes for memory limit.
func NewRenderCacheWithLimits ¶
func NewRenderCacheWithLimits(capacity int, maxBytes int64) *RenderCache
NewRenderCacheWithLimits creates a new LRU cache with both item and memory limits. Eviction occurs when either limit is exceeded.
func (*RenderCache) ByteSize ¶
func (c *RenderCache) ByteSize() int64
ByteSize returns the current estimated memory usage in bytes.
func (*RenderCache) Clear ¶
func (c *RenderCache) Clear()
Clear empties the cache but preserves metrics.
func (*RenderCache) Get ¶
func (c *RenderCache) Get(key RenderCacheKey) (string, bool)
Get retrieves a cached rendered line, returning ("", false) if not found. Updates metrics on each call.
func (*RenderCache) GetMetrics ¶
func (c *RenderCache) GetMetrics() CacheMetrics
GetMetrics returns a copy of the current cache metrics.
func (*RenderCache) Put ¶
func (c *RenderCache) Put(key RenderCacheKey, value string)
Put stores a rendered line in the cache. Evicts entries when either item count or memory limit is exceeded.
func (*RenderCache) ResetMetrics ¶
func (c *RenderCache) ResetMetrics()
ResetMetrics clears the performance metrics.
func (*RenderCache) SetTheme ¶
func (c *RenderCache) SetTheme(theme string) bool
SetTheme updates the theme and clears cache if it changed. Returns true if cache was cleared.
func (*RenderCache) SetViewMode ¶
func (c *RenderCache) SetViewMode(mode ViewMode) bool
SetViewMode updates the view mode and clears cache if it changed. Returns true if cache was cleared.
func (*RenderCache) Size ¶
func (c *RenderCache) Size() int
Size returns the current number of cached entries.
func (*RenderCache) Theme ¶
func (c *RenderCache) Theme() string
Theme returns the current theme identifier.
func (*RenderCache) ViewMode ¶
func (c *RenderCache) ViewMode() ViewMode
ViewMode returns the current view mode.
type RenderCacheKey ¶
type RenderCacheKey struct {
FileHash string // SHA of file content or path for identity
HunkIndex int // Index of hunk within the file (-1 for file headers)
LineIndex int // Index of line within visible content
Width int // Current render width
ViewMode ViewMode // Unified or side-by-side
Theme string // Current theme identifier
}
RenderCacheKey uniquely identifies a rendered content block. Using FileHash+HunkIndex+Width+ViewMode+Theme allows for: - Proper invalidation when file content changes (FileHash) - Per-hunk caching for virtual scrolling (HunkIndex) - Re-render on width changes (Width) - Different renders for unified vs side-by-side (ViewMode) - Theme-aware caching (Theme)
type ScrollbarConfig ¶
type ScrollbarConfig struct {
// Dimensions
TotalLines int // Total lines in content
ViewportHeight int // Visible lines in viewport
ScrollOffset int // Current scroll position (top line)
// Style configuration
TrackChar string // Track character (default: "░")
ThumbChar string // Thumb character (default: "█")
}
ScrollbarConfig configures scrollbar rendering.
func DefaultScrollbarConfig ¶
func DefaultScrollbarConfig() ScrollbarConfig
DefaultScrollbarConfig returns default configuration.
type ShowDiffViewerMsg ¶
type ShowDiffViewerMsg struct{}
ShowDiffViewerMsg requests showing the diff viewer.
type SideBySideLine ¶
type SideBySideLine struct {
Left *DiffLine // Line from old file (nil for insertion-only row)
Right *DiffLine // Line from new file (nil for deletion-only row)
IsHunkHeader bool // True if this is a hunk header row
HunkHeader string // Hunk header text (only set if IsHunkHeader)
IsFileHeader bool // True if this is a file header separator
FileHeader string // File header text (only set if IsFileHeader)
FileHash string // Hash/ID for the source file (for cache key)
HunkIndex int // Index of the hunk within the file (for cache key)
}
SideBySideLine represents a single row in side-by-side diff view. Each row contains aligned left (old) and right (new) content.
func (*SideBySideLine) PairType ¶
func (sbl *SideBySideLine) PairType() string
PairType returns the type of this side-by-side row for styling.
type ViewModeConstrainedMsg ¶
type ViewModeConstrainedMsg struct {
RequestedMode ViewMode // The mode the user tried to switch to
MinWidth int // Minimum width required
CurrentWidth int // Current terminal width
}
ViewModeConstrainedMsg is returned when user tries to switch to side-by-side view but the terminal is too narrow. The app should show a toast message.
type VirtualContent ¶
type VirtualContent struct {
// Lines is the source data - all diff lines across all hunks (unified view)
Lines []VirtualLine
// SideBySideLines is the pre-computed aligned pairs for side-by-side view
// This is computed once from Lines when the content is created
SideBySideLines []SideBySideLine
// TotalLines is the total number of lines for the current view mode
TotalLines int
// UnifiedTotalLines is the count for unified view (always stored)
UnifiedTotalLines int
// SideBySideTotalLines is the count for side-by-side view (always stored)
SideBySideTotalLines int
// VisibleStart is the first visible line index
VisibleStart int
// VisibleEnd is the last visible line index (exclusive)
VisibleEnd int
// RenderCache caches rendered line strings
RenderCache *RenderCache
// Width is the current render width
Width int
// BufferLines is the number of lines to pre-render above/below visible area
BufferLines int
// ViewMode is the current display mode (unified/side-by-side)
ViewMode ViewMode
// Theme is the current theme identifier
Theme string
}
VirtualContent manages virtual scrolling for large diffs. It only renders visible lines plus a buffer, using an LRU cache for efficiency.
func NewVirtualContent ¶
func NewVirtualContent(files []DiffFile, config VirtualContentConfig) *VirtualContent
NewVirtualContent creates a new VirtualContent from diff files. It pre-computes both unified and side-by-side line arrays for fast view switching.
func NewVirtualContentFromFile ¶
func NewVirtualContentFromFile(file DiffFile, config VirtualContentConfig) *VirtualContent
NewVirtualContentFromFile creates virtual content from a single file.
func (*VirtualContent) GetCacheHitRate ¶
func (vc *VirtualContent) GetCacheHitRate() float64
GetCacheHitRate returns the current cache hit rate as a percentage (0-100).
func (*VirtualContent) GetCacheMetrics ¶
func (vc *VirtualContent) GetCacheMetrics() CacheMetrics
GetCacheMetrics returns the current cache performance metrics.
func (*VirtualContent) InvalidateCache ¶
func (vc *VirtualContent) InvalidateCache()
InvalidateCache clears the render cache, forcing re-render. Call this when theme or other visual properties change.
func (*VirtualContent) RenderVisible ¶
func (vc *VirtualContent) RenderVisible() string
RenderVisible generates the content string for the visible range. Returns a string suitable for setting as viewport content.
func (*VirtualContent) SetTheme ¶
func (vc *VirtualContent) SetTheme(theme string) bool
SetTheme updates the theme identifier and clears cache if it changed. Returns true if cache was cleared.
func (*VirtualContent) SetViewMode ¶
func (vc *VirtualContent) SetViewMode(mode ViewMode) bool
SetViewMode updates the view mode and clears cache if it changed. Also updates TotalLines to reflect the appropriate count for the view mode. Returns true if cache was cleared.
func (*VirtualContent) SetVisibleRange ¶
func (vc *VirtualContent) SetVisibleRange(scrollTop, viewportHeight int)
SetVisibleRange updates the visible range based on viewport scroll position.
func (*VirtualContent) SetWidth ¶
func (vc *VirtualContent) SetWidth(width int)
SetWidth updates the render width and clears the cache if width changed.
type VirtualContentConfig ¶
type VirtualContentConfig struct {
// CacheCapacity is the max number of rendered lines to cache (default: 1000)
CacheCapacity int
// CacheMaxBytes is the max memory for cache in bytes (default: 10MB)
CacheMaxBytes int64
// BufferLines is the number of lines to pre-render above/below visible area (default: 50)
BufferLines int
}
VirtualContentConfig holds configuration for virtual content creation.
func DefaultVirtualContentConfig ¶
func DefaultVirtualContentConfig() VirtualContentConfig
DefaultVirtualContentConfig returns sensible defaults.
type VirtualLine ¶
type VirtualLine struct {
Type LineType
OldLineNum int
NewLineNum int
Content string
HunkHeader string // Only set for LineHunkHeader type
FileHeader string // Only set for file header lines (internal use)
IsFileHeader bool // True if this is a file header separator
FileHash string // Hash/ID for the source file (for cache key)
HunkIndex int // Index of the hunk within the file (for cache key)
}
VirtualLine represents a single renderable line in the virtual content. It stores the raw data needed to render the line on demand.
type VirtualViewport ¶
type VirtualViewport struct {
// contains filtered or unexported fields
}
VirtualViewport renders only visible lines without padding overhead. This component bypasses the bubbles/viewport SetContent() path which creates O(n) strings for n total lines. Instead, it renders O(visible) lines directly.
This eliminates the primary performance bottleneck identified in profiling: - Previously: 22K-element slice + 22K-line string per frame (1.6MB) - Now: ~50 visible lines per frame (~50KB)
func NewVirtualViewport ¶
func NewVirtualViewport(vc *VirtualContent) *VirtualViewport
NewVirtualViewport creates a new VirtualViewport from a VirtualContent. The VirtualContent holds all lines and handles individual line rendering.
func NewVirtualViewportFromFiles ¶
func NewVirtualViewportFromFiles(files []DiffFile, config VirtualContentConfig) *VirtualViewport
NewVirtualViewportFromFiles creates a VirtualViewport directly from diff files. This is a convenience constructor that creates the VirtualContent internally.
func (*VirtualViewport) AtBottom ¶
func (vv *VirtualViewport) AtBottom() bool
AtBottom returns true if scrolled to the bottom.
func (*VirtualViewport) AtTop ¶
func (vv *VirtualViewport) AtTop() bool
AtTop returns true if scrolled to the top.
func (*VirtualViewport) EnsureVisible ¶
func (vv *VirtualViewport) EnsureVisible(lineIndex int) bool
EnsureVisible scrolls the viewport to make the given line index visible. If the line is already visible, no scrolling occurs. Returns true if scrolling occurred.
func (*VirtualViewport) GetCacheHitRate ¶
func (vv *VirtualViewport) GetCacheHitRate() float64
GetCacheHitRate returns the cache hit rate as a percentage (0-100).
func (*VirtualViewport) GetCacheMetrics ¶
func (vv *VirtualViewport) GetCacheMetrics() CacheMetrics
GetCacheMetrics returns cache performance metrics.
func (*VirtualViewport) GotoBottom ¶
func (vv *VirtualViewport) GotoBottom()
GotoBottom scrolls to the bottom of the content.
func (*VirtualViewport) GotoTop ¶
func (vv *VirtualViewport) GotoTop()
GotoTop scrolls to the top of the content.
func (*VirtualViewport) HalfPageDown ¶
func (vv *VirtualViewport) HalfPageDown()
HalfPageDown scrolls down by half a page.
func (*VirtualViewport) HalfPageUp ¶
func (vv *VirtualViewport) HalfPageUp()
HalfPageUp scrolls up by half a page.
func (*VirtualViewport) Height ¶
func (vv *VirtualViewport) Height() int
Height returns the current viewport height.
func (*VirtualViewport) InvalidateCache ¶
func (vv *VirtualViewport) InvalidateCache()
InvalidateCache clears the render cache, forcing re-render of all lines. Call this when theme or other visual properties change.
func (*VirtualViewport) LineRange ¶
func (vv *VirtualViewport) LineRange() (start, end int)
LineRange returns the start and end indices of currently visible lines. End is exclusive (following Go slice convention).
func (*VirtualViewport) PageDown ¶
func (vv *VirtualViewport) PageDown()
PageDown scrolls down by one page.
func (*VirtualViewport) PastEnd ¶
func (vv *VirtualViewport) PastEnd() bool
PastEnd returns true if the content is shorter than the viewport. In this case, there's no scrolling needed.
func (*VirtualViewport) Render ¶
func (vv *VirtualViewport) Render() string
Render returns ONLY the visible lines as a single string. This is the key optimization: no padding strings, just visible content.
The method also pre-warms the cache for lines in the buffer zone above and below the visible area for smoother scrolling.
func (*VirtualViewport) ScrollDown ¶
func (vv *VirtualViewport) ScrollDown(n int)
ScrollDown scrolls down by n lines.
func (*VirtualViewport) ScrollPercent ¶
func (vv *VirtualViewport) ScrollPercent() float64
ScrollPercent returns the scroll position as a percentage (0.0 to 1.0). Returns 0.0 if content fits within viewport.
func (*VirtualViewport) ScrollToLine ¶
func (vv *VirtualViewport) ScrollToLine(lineIndex int)
ScrollToLine scrolls to put the given line at the top of the viewport.
func (*VirtualViewport) ScrollToPercent ¶
func (vv *VirtualViewport) ScrollToPercent(percent float64)
ScrollToPercent scrolls to a position given as a percentage (0.0 to 1.0).
func (*VirtualViewport) ScrollUp ¶
func (vv *VirtualViewport) ScrollUp(n int)
ScrollUp scrolls up by n lines.
func (*VirtualViewport) SetSize ¶
func (vv *VirtualViewport) SetSize(width, height int)
SetSize updates the viewport dimensions. Width changes invalidate the render cache since line rendering depends on width.
func (*VirtualViewport) SetTheme ¶
func (vv *VirtualViewport) SetTheme(theme string) bool
SetTheme updates the theme and invalidates cache if changed. Returns true if cache was cleared.
func (*VirtualViewport) SetViewMode ¶
func (vv *VirtualViewport) SetViewMode(mode ViewMode) bool
SetViewMode updates the view mode and invalidates cache if changed. Returns true if cache was cleared.
func (*VirtualViewport) SetYOffset ¶
func (vv *VirtualViewport) SetYOffset(offset int)
SetYOffset sets the scroll position to the given offset. The offset is clamped to valid range [0, totalLines - height].
func (*VirtualViewport) TotalLines ¶
func (vv *VirtualViewport) TotalLines() int
TotalLines returns the total number of lines in the content.
func (*VirtualViewport) VirtualContent ¶
func (vv *VirtualViewport) VirtualContent() *VirtualContent
VirtualContent returns the underlying VirtualContent for direct access. Use sparingly - prefer the VirtualViewport methods.
func (*VirtualViewport) VisibleLineCount ¶
func (vv *VirtualViewport) VisibleLineCount() int
VisibleLineCount returns the number of lines currently visible. This may be less than height if near the end of content.
func (*VirtualViewport) Width ¶
func (vv *VirtualViewport) Width() int
Width returns the current viewport width.
func (*VirtualViewport) YOffset ¶
func (vv *VirtualViewport) YOffset() int
YOffset returns the current scroll position (first visible line index).
type WorkingDirDiffLoadedMsg ¶
WorkingDirDiffLoadedMsg carries parsed working directory diff.
type WorktreesLoadedMsg ¶
type WorktreesLoadedMsg struct {
Worktrees []domaingit.WorktreeInfo
Err error
}
WorktreesLoadedMsg carries the list of available worktrees.