Documentation
¶
Overview ¶
Package filebrowser implements the file browser plugin with tree navigation, file preview, quick open, search, git integration, and file operations.
Index ¶
- func FuzzySort(matches []QuickOpenMatch)
- func Highlight(content, extension, syntaxTheme string) (string, error)
- func LoadPreview(rootDir, path string, epoch uint64) tea.Cmd
- func RelativeTime(t time.Time) string
- func RunGitBlame(workDir, filePath string, epoch uint64) tea.Cmd
- func RunProjectSearch(workDir string, state *ProjectSearchState, epoch uint64) tea.Cmd
- type AttachToTmuxMsg
- type BlameLine
- type BlameLoadedMsg
- type BlameState
- type BuildSpec
- type ContentMatch
- type CreateSuccessMsg
- type DeleteSuccessMsg
- type FSEvent
- type FileCacheBuiltMsg
- type FileNode
- type FileOpErrorMsg
- type FileOpMode
- type FileOpSuccessMsg
- type FileTab
- type FileTree
- func (t *FileTree) Build() error
- func (t *FileTree) Collapse(node *FileNode)
- func (t *FileTree) Expand(node *FileNode) error
- func (t *FileTree) FindByPath(path string) *FileNode
- func (t *FileTree) FindParentDir(node *FileNode) *FileNode
- func (t *FileTree) Flatten() []*FileNode
- func (t *FileTree) GetExpandedPaths() map[string]bool
- func (t *FileTree) GetNode(index int) *FileNode
- func (t *FileTree) IndexOf(node *FileNode) int
- func (t *FileTree) IndexOfPath(path string) int
- func (t *FileTree) Len() int
- func (t *FileTree) RestoreExpandedPaths(paths map[string]bool)
- func (t *FileTree) SetExpandedPaths(paths map[string]bool)
- func (t *FileTree) SetSortMode(mode SortMode)
- func (t *FileTree) Toggle(node *FileNode) error
- type FocusPane
- type GitIgnore
- type GitInfoMsg
- type InlineEditExitedMsg
- type InlineEditStartedMsg
- type MatchRange
- type NavigateToFileMsg
- type PasteSuccessMsg
- type Plugin
- func (p *Plugin) Commands() []plugin.Command
- func (p *Plugin) ConsumesTextInput() bool
- func (p *Plugin) Cursor() *tea.Cursor
- func (p *Plugin) FocusContext() string
- func (p *Plugin) ID() string
- func (p *Plugin) Icon() string
- func (p *Plugin) Init(ctx *plugin.Context) error
- func (p *Plugin) IsFocused() bool
- func (p *Plugin) Name() string
- func (p *Plugin) PreferredMouseMode() tea.MouseMode
- func (p *Plugin) SetFocused(f bool)
- func (p *Plugin) Start() tea.Cmd
- func (p *Plugin) Stop()
- func (p *Plugin) Update(msg tea.Msg) (plugin.Plugin, tea.Cmd)
- func (p *Plugin) View(width, height int) string
- type PreviewLoadedMsg
- type PreviewResult
- type ProjectSearchResultsMsg
- type ProjectSearchState
- func (s *ProjectSearchState) FileCount() int
- func (s *ProjectSearchState) FirstMatchIndex() int
- func (s *ProjectSearchState) FlatItem(idx int) (fileIdx int, matchIdx int, isFile bool)
- func (s *ProjectSearchState) FlatLen() int
- func (s *ProjectSearchState) GetSelectedFile() (path string, lineNo int)
- func (s *ProjectSearchState) LastMatchIndex() int
- func (s *ProjectSearchState) NearestMatchIndex(fromIdx int) int
- func (s *ProjectSearchState) NextMatchIndex() int
- func (s *ProjectSearchState) PrevMatchIndex() int
- func (s *ProjectSearchState) ToggleFileCollapse()
- func (s *ProjectSearchState) TotalMatches() int
- type QuickOpenMatch
- type RevealErrorMsg
- type SearchFileResult
- type SearchMatch
- type SortMode
- type StateRestoredMsg
- type TabOpenMode
- type TreeBuiltMsg
- type TreeWatcher
- type WatchEventMsg
- type WatchStartedMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuzzySort ¶
func FuzzySort(matches []QuickOpenMatch)
FuzzySort sorts matches by score descending, then path length ascending.
func Highlight ¶
Highlight returns a syntax highlighted string. Pattern from knipferrc/fm code/code.go
func LoadPreview ¶
LoadPreview creates a command to load file content.
func RelativeTime ¶
RelativeTime formats a time as a relative duration string.
func RunGitBlame ¶
RunGitBlame runs git blame and returns the parsed output.
func RunProjectSearch ¶
func RunProjectSearch(workDir string, state *ProjectSearchState, epoch uint64) tea.Cmd
RunProjectSearch executes ripgrep and returns results.
Types ¶
type AttachToTmuxMsg ¶
type AttachToTmuxMsg struct {
SessionName string
}
AttachToTmuxMsg requests the app to suspend and attach to a tmux session.
type BlameLine ¶
type BlameLine struct {
CommitHash string
Author string
AuthorTime time.Time
LineNo int
Content string
}
BlameLine represents a single line in git blame output.
type BlameLoadedMsg ¶
type BlameLoadedMsg struct {
Epoch uint64 // Epoch when request was issued (for stale detection)
Lines []BlameLine
Error error
}
BlameLoadedMsg is sent when blame data is loaded.
func (BlameLoadedMsg) GetEpoch ¶
func (m BlameLoadedMsg) GetEpoch() uint64
GetEpoch implements plugin.EpochMessage.
type BlameState ¶
type BlameState struct {
Lines []BlameLine
Cursor int
ScrollOffset int
FilePath string
IsLoading bool
Error error
}
BlameState holds the state for blame view.
type BuildSpec ¶ added in v0.90.0
type BuildSpec struct {
RootDir string
SortMode SortMode
ShowIgnored bool
ExpandedPaths map[string]bool // Directories to re-expand after loading
}
BuildSpec fully describes a tree build. Every field is a value the caller owns outright, so a build can run on a background goroutine without touching the tree the UI is currently rendering.
type ContentMatch ¶
type ContentMatch struct {
LineNo int // 0-indexed line number
StartCol int // Start column (byte offset)
EndCol int // End column (byte offset)
}
ContentMatch represents a match position within file content.
type CreateSuccessMsg ¶
CreateSuccessMsg is sent when a file/directory is created.
type DeleteSuccessMsg ¶
type DeleteSuccessMsg struct {
Path string
}
DeleteSuccessMsg is sent when a file/directory is deleted.
type FSEvent ¶ added in v0.90.0
type FSEvent struct {
// TreeChanged is set when entries appeared, disappeared, or were renamed
// inside a watched directory - i.e. when the tree needs rebuilding.
TreeChanged bool
// PreviewChanged is set when the currently previewed file was touched.
PreviewChanged bool
// Dirs holds the absolute directories something changed in, deduplicated
// and capped at maxEventDirs. In-place writes count: consumers cache file
// contents, not just directory listings.
Dirs []string
}
FSEvent is a coalesced batch of filesystem changes.
type FileCacheBuiltMsg ¶ added in v0.90.0
type FileCacheBuiltMsg struct {
Dirs bool
Files []string // Paths relative to the working directory, sorted
ErrText string // Non-empty when the scan failed or hit a limit
Epoch uint64
}
FileCacheBuiltMsg carries the result of a background quick-open cache scan. Dirs distinguishes the path auto-complete scan from the file scan.
func (FileCacheBuiltMsg) GetEpoch ¶ added in v0.90.0
func (m FileCacheBuiltMsg) GetEpoch() uint64
GetEpoch implements plugin.EpochMessage for staleness detection.
type FileNode ¶
type FileNode struct {
Name string
Path string // Relative path from root
IsDir bool
IsExpanded bool
IsIgnored bool // Set by gitignore
Children []*FileNode
Parent *FileNode
Depth int
Size int64
ModTime time.Time
}
FileNode represents a file or directory in the tree.
type FileOpErrorMsg ¶
type FileOpErrorMsg struct {
Err error
}
FileOpErrorMsg is sent when a file operation fails.
type FileOpMode ¶
type FileOpMode int
FileOpMode represents the current file operation mode.
const ( FileOpNone FileOpMode = iota FileOpMove FileOpRename FileOpCreateFile FileOpCreateDir FileOpDelete )
type FileOpSuccessMsg ¶
FileOpSuccessMsg is sent when a file operation succeeds.
type FileTab ¶
type FileTab struct {
Path string
Scroll int
Loaded bool
Result PreviewResult
IsPreview bool // Ephemeral preview tab, replaced on next j/k navigation
// Edit state (persisted when switching away from inline editor)
EditSession string // Tmux session name (empty if not in edit mode)
EditOrigMtime time.Time // Original file mtime when editing started
EditEditor string // Editor command used (vim, nano, etc.)
}
type FileTree ¶
type FileTree struct {
Root *FileNode
RootDir string
FlatList []*FileNode // Flattened visible nodes for cursor navigation
SortMode SortMode // Current sort mode
ShowIgnored bool // Whether to include ignored files in FlatList
// contains filtered or unexported fields
}
FileTree manages the hierarchical file structure.
func BuildTree ¶ added in v0.90.0
BuildTree constructs a brand-new tree from spec. It shares no state with any existing FileTree, which is what makes it safe to call off the UI goroutine: the caller swaps the result in when the resulting message is handled.
func NewFileTree ¶
NewFileTree creates a new file tree rooted at the given directory.
func (*FileTree) Expand ¶
Expand opens a directory node, reloading its children from disk. Children loaded by an earlier expand are re-read rather than reused, so a directory that changed while it was collapsed opens with what is actually there. The expanded directories inside the subtree stay expanded.
On a read error the previously loaded children are kept, so a directory that briefly becomes unreadable does not blank out.
func (*FileTree) FindByPath ¶
FindByPath returns the node with the given relative path, or nil if not found.
func (*FileTree) FindParentDir ¶
FindParentDir returns the parent directory node, or nil if at root.
func (*FileTree) GetExpandedPaths ¶
GetExpandedPaths returns the paths of all expanded directories.
func (*FileTree) IndexOf ¶
IndexOf returns the index of a node in the flat list, or -1 if not found.
func (*FileTree) IndexOfPath ¶ added in v0.90.0
IndexOfPath returns the flat-list index of the node with the given relative path, or -1 if no visible node has that path.
func (*FileTree) RestoreExpandedPaths ¶
RestoreExpandedPaths expands directories that were previously expanded.
func (*FileTree) SetExpandedPaths ¶ added in v0.90.0
SetExpandedPaths makes the tree's expansion match paths exactly: directories named in the set are expanded (loading their children if needed) and every other visible directory is collapsed. Unlike RestoreExpandedPaths it can undo an expansion, which is what a rebuilt tree needs to pick up a collapse the user made while the build was running.
func (*FileTree) SetSortMode ¶
SetSortMode changes the sort mode and re-sorts the tree.
type GitIgnore ¶
type GitIgnore struct {
// contains filtered or unexported fields
}
GitIgnore manages .gitignore patterns for file filtering.
type GitInfoMsg ¶
GitInfoMsg contains git status for a file.
type InlineEditExitedMsg ¶
type InlineEditExitedMsg struct {
FilePath string
}
InlineEditExitedMsg is sent when inline edit mode exits.
type InlineEditStartedMsg ¶
type InlineEditStartedMsg struct {
SessionName string
FilePath string
OriginalMtime time.Time // File mtime before editing (to detect changes)
Editor string // Editor command used (vim, nano, emacs, etc.)
}
InlineEditStartedMsg is sent when inline edit mode starts successfully.
type MatchRange ¶
MatchRange represents a contiguous range of matched characters.
func FuzzyMatch ¶
func FuzzyMatch(query, target string) (int, []MatchRange)
FuzzyMatch scores how well query matches target string. Returns score (0 = no match) and ranges for highlighting. Scoring:
- Consecutive matches: bonus per consecutive char
- Word start matches (after /, _, -, .): large bonus
- Shorter targets: small bonus
type NavigateToFileMsg ¶
type NavigateToFileMsg struct {
}
NavigateToFileMsg requests navigation to a specific file (from other plugins).
type PasteSuccessMsg ¶
PasteSuccessMsg is sent when a file/directory is pasted.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements file browser functionality.
func (*Plugin) ConsumesTextInput ¶
ConsumesTextInput reports whether the file browser currently expects typed text input and should suppress app-level shortcut interception.
func (*Plugin) Cursor ¶ added in v0.88.0
Cursor exposes the inline editor's native cursor in plugin-local coordinates.
func (*Plugin) FocusContext ¶
FocusContext returns the current focus context.
func (*Plugin) PreferredMouseMode ¶ added in v0.88.0
PreferredMouseMode reduces idle hover traffic only while the inline terminal owns input. Modal and ordinary file-browser views retain all-motion hover.
type PreviewLoadedMsg ¶
type PreviewLoadedMsg struct {
Epoch uint64 // Epoch when request was issued (for stale detection)
Result PreviewResult
Path string
}
PreviewLoadedMsg signals that file preview content is ready.
func (PreviewLoadedMsg) GetEpoch ¶
func (m PreviewLoadedMsg) GetEpoch() uint64
GetEpoch implements plugin.EpochMessage.
type PreviewResult ¶
type PreviewResult struct {
Content string
Lines []string
HighlightedLines []string // Syntax highlighted lines
IsBinary bool
IsImage bool // True if file is a recognized image format
IsTruncated bool
TotalSize int64
ModTime time.Time // File modification time
Mode os.FileMode // File permissions
Error error
}
PreviewResult contains the loaded file content.
type ProjectSearchResultsMsg ¶
type ProjectSearchResultsMsg struct {
Epoch uint64 // Epoch when request was issued (for stale detection)
Results []SearchFileResult
Error error
}
ProjectSearchResultsMsg contains results from a search.
func (ProjectSearchResultsMsg) GetEpoch ¶
func (m ProjectSearchResultsMsg) GetEpoch() uint64
GetEpoch implements plugin.EpochMessage.
type ProjectSearchState ¶
type ProjectSearchState struct {
Query string
Results []SearchFileResult
// Search options (toggle with keyboard shortcuts)
UseRegex bool
CaseSensitive bool
WholeWord bool
// UI state
Cursor int // Index in flattened results (files + matches)
ScrollOffset int // For scrolling
IsSearching bool // True while ripgrep is running
Error string
ResultsFocused bool // When true, j/k/g/G navigate results instead of typing
// Debounce: only run search when version matches
DebounceVersion int
// For future: multiple search tabs
TabID int
}
ProjectSearchState holds the state for project-wide search.
func NewProjectSearchState ¶
func NewProjectSearchState() *ProjectSearchState
NewProjectSearchState creates a new search state.
func (*ProjectSearchState) FileCount ¶
func (s *ProjectSearchState) FileCount() int
FileCount returns the number of files with matches.
func (*ProjectSearchState) FirstMatchIndex ¶
func (s *ProjectSearchState) FirstMatchIndex() int
FirstMatchIndex returns the flat index of the first match (skipping file headers). Returns 0 if no matches exist.
func (*ProjectSearchState) FlatItem ¶
func (s *ProjectSearchState) FlatItem(idx int) (fileIdx int, matchIdx int, isFile bool)
FlatItem returns the item at the given flat index. Returns (fileIndex, matchIndex, isFile). matchIndex is -1 if this is a file header.
func (*ProjectSearchState) FlatLen ¶
func (s *ProjectSearchState) FlatLen() int
FlatLen returns the length of the flattened results list. Each file is 1 item, plus its matches if not collapsed.
func (*ProjectSearchState) GetSelectedFile ¶
func (s *ProjectSearchState) GetSelectedFile() (path string, lineNo int)
GetSelectedFile returns the currently selected file path and line number. If a match is selected, returns file path and line number. If a file header is selected, returns file path and line 0.
func (*ProjectSearchState) LastMatchIndex ¶ added in v0.84.0
func (s *ProjectSearchState) LastMatchIndex() int
LastMatchIndex returns the flat index of the last visible match. Skips file headers. Returns 0 if no matches are visible.
func (*ProjectSearchState) NearestMatchIndex ¶
func (s *ProjectSearchState) NearestMatchIndex(fromIdx int) int
NearestMatchIndex returns the flat index of the nearest match to the given index. Searches forward first, then backward. Returns 0 if no matches exist.
func (*ProjectSearchState) NextMatchIndex ¶
func (s *ProjectSearchState) NextMatchIndex() int
NextMatchIndex returns the flat index of the next match after current cursor. Skips file headers. Returns current cursor if no next match exists.
func (*ProjectSearchState) PrevMatchIndex ¶
func (s *ProjectSearchState) PrevMatchIndex() int
PrevMatchIndex returns the flat index of the previous match before current cursor. Skips file headers. Returns current cursor if no previous match exists.
func (*ProjectSearchState) ToggleFileCollapse ¶
func (s *ProjectSearchState) ToggleFileCollapse()
ToggleFileCollapse toggles the collapsed state of the file at cursor.
func (*ProjectSearchState) TotalMatches ¶
func (s *ProjectSearchState) TotalMatches() int
TotalMatches returns the total number of matches across all files.
type QuickOpenMatch ¶
type QuickOpenMatch struct {
Path string // Relative path from root
Name string // Base filename
Score int // Match score (higher = better)
MatchRanges []MatchRange // Ranges for highlighting matched chars
}
QuickOpenMatch represents a file matching the fuzzy query.
func FuzzyFilter ¶
func FuzzyFilter(files []string, query string, maxResults int) []QuickOpenMatch
FuzzyFilter filters and scores files against a query. Returns top maxResults matches sorted by score.
type RevealErrorMsg ¶
type RevealErrorMsg struct {
Err error
}
RevealErrorMsg is sent when reveal in file manager fails.
type SearchFileResult ¶
type SearchFileResult struct {
Path string
Matches []SearchMatch
Collapsed bool
}
SearchFileResult represents a file with search matches.
type SearchMatch ¶
type SearchMatch struct {
LineNo int // 1-indexed line number
LineText string // Full line content
ColStart int // Match start column (0-indexed)
ColEnd int // Match end column (0-indexed)
}
SearchMatch represents a single match within a file.
type SortMode ¶
type SortMode int
SortMode represents how files are sorted in the tree.
type TabOpenMode ¶
type TabOpenMode int
const ( TabOpenReplace TabOpenMode = iota TabOpenNew TabOpenPreview )
type TreeBuiltMsg ¶
type TreeBuiltMsg struct {
Tree *FileTree
Err error
Epoch uint64
Gen uint64 // Build generation; only the newest build is applied
CursorPath string // Path the cursor sat on when the build was requested
}
TreeBuiltMsg carries a tree built on a background goroutine. The plugin swaps Tree in wholesale rather than mutating the live tree in place.
func (TreeBuiltMsg) GetEpoch ¶ added in v0.90.0
func (m TreeBuiltMsg) GetEpoch() uint64
GetEpoch implements plugin.EpochMessage for staleness detection.
type TreeWatcher ¶ added in v0.90.0
type TreeWatcher struct {
// contains filtered or unexported fields
}
TreeWatcher watches the expanded directories of the file tree plus the directory holding the previewed file, coalescing bursts of filesystem activity into at most one pending event.
func NewTreeWatcher ¶ added in v0.90.0
func NewTreeWatcher() (*TreeWatcher, error)
NewTreeWatcher creates a watcher. Nothing is watched until SyncDirs or SetPreviewFile is called.
func (*TreeWatcher) Events ¶ added in v0.90.0
func (w *TreeWatcher) Events() <-chan FSEvent
Events returns the channel of coalesced filesystem events. It is closed once the watcher stops.
func (*TreeWatcher) SetPreviewFile ¶ added in v0.90.0
func (w *TreeWatcher) SetPreviewFile(path string) error
SetPreviewFile points the preview watch at path (absolute or relative to the working directory). Pass "" to stop watching a preview file.
func (*TreeWatcher) Stop ¶ added in v0.90.0
func (w *TreeWatcher) Stop()
Stop shuts the watcher down and blocks until the event channel is closed, so a caller that has stopped a watcher can never see another event from it.
func (*TreeWatcher) SyncDirs ¶ added in v0.90.0
func (w *TreeWatcher) SyncDirs(dirs []string)
SyncDirs makes the watched directory set match dirs, adding and removing only what actually changed. Order matters: dirs beyond maxWatchedDirs are dropped, so callers should pass the most interesting directories first.
type WatchEventMsg ¶
WatchEventMsg carries a coalesced batch of filesystem changes. Its fields mirror FSEvent exactly so the watcher event converts directly.