Documentation
¶
Overview ¶
Package filebrowser implements the file browser plugin with tree navigation, file preview, quick open, search, git integration, and file operations.
Index ¶
- func Highlight(content, extension, syntaxTheme string) (string, error)
- func LoadPreview(rootDir, path string, epoch uint64) tea.Cmd
- func LoadPreviewFile(file *os.File, path string, epoch uint64) tea.Cmd
- func RelativeTime(t time.Time) string
- func RunGitBlame(workDir, filePath string, epoch uint64) tea.Cmd
- type AttachToTmuxMsg
- type BlameLine
- type BlameLoadedMsg
- type BlameState
- type BuildSpec
- type ContentMatch
- type CreateSuccessMsg
- type DeleteSuccessMsg
- type DragMoveResultMsg
- type DragSpringLoadMsg
- 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 GitInfoMsg
- type InlineEditExitedMsg
- type InlineEditStartedMsg
- type NavigateToFileMsg
- type PasteSuccessMsg
- type Plugin
- func (p *Plugin) AtFocusCycleEnd(reverse bool) bool
- func (p *Plugin) BlocksGlobalKeys() bool
- func (p *Plugin) Commands() []plugin.Command
- func (p *Plugin) ConsumesTextInput() bool
- func (p *Plugin) ContentLinkSurfaces() []contentlink.Surface
- func (p *Plugin) Cursor() *tea.Cursor
- func (p *Plugin) EditorOrigin() (x, y int, ok bool)
- func (p *Plugin) EditorViewport() (width, height int)
- func (p *Plugin) FocusContext() string
- func (p *Plugin) FocusCycleStart(reverse bool) tea.Cmd
- 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) PaneFocus() string
- func (p *Plugin) PaneFocusStops() []plugin.PaneFocusStop
- func (p *Plugin) PreferredMouseMode() tea.MouseMode
- func (p *Plugin) SetFocused(f bool)
- func (p *Plugin) SetPaneFocus(id string) tea.Cmd
- func (p *Plugin) SetPaneFocusActive(active 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
- func (p *Plugin) WheelAtBoundary(msg tea.MouseWheelMsg) bool
- type PreviewLoadedMsg
- type PreviewResult
- type RevealErrorMsg
- 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 LoadPreviewFile ¶ added in v0.98.0
func RelativeTime ¶
RelativeTime formats a time as a relative duration string.
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 DragMoveResultMsg ¶ added in v0.91.0
type DragMoveResultMsg struct {
Name string // Basename that was moved, for the toast
Dir string // Destination directory, relative to the project root
Err error
}
DragMoveResultMsg reports the outcome of a move started by a drag-drop. It is deliberately a distinct type from FileOpSuccessMsg/FileOpErrorMsg: a drag move has no file-op bar to render an error into, and a bare "pending" flag on the plugin would let a concurrent rename's result be reported as the drag's (and vice versa).
type DragSpringLoadMsg ¶ added in v0.91.0
type DragSpringLoadMsg struct {
Gen uint64
}
DragSpringLoadMsg fires once the cursor has rested long enough over a collapsed directory during a drag, asking for it to auto-expand. Gen identifies the hover it was scheduled for: the cursor has usually moved on by the time it lands, and a stale tick must not expand a directory the user is no longer pointing at.
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 = filefind.ScannedMsg
FileCacheBuiltMsg carries the result of a background quick-open cache scan. Dirs distinguishes the path auto-complete scan from the file scan.
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 InlineEditExitedMsg ¶
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.)
Activation uint64
Epoch uint64
}
InlineEditStartedMsg is sent when inline edit mode starts successfully.
type NavigateToFileMsg ¶
type NavigateToFileMsg = app.NavigateToFileMsg
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) AtFocusCycleEnd ¶ added in v1.2.0
AtFocusCycleEnd reports the wrap point of the ring, and only in the two contexts that have one. Every sub-mode of this surface — search, quick open, the file-operation modal, blame, info, the inline editor — is either typing or is a modal with its own `tab`, and a shell stop must not take the key from one of them. FocusContext is the surface's own answer to "what mode am I in", so the ring is offered against that rather than against a second list of booleans that could drift from it.
func (*Plugin) BlocksGlobalKeys ¶ added in v0.96.0
BlocksGlobalKeys reports whether a plugin-owned modal has keyboard focus.
func (*Plugin) ConsumesTextInput ¶
ConsumesTextInput reports whether the file browser currently expects typed text input and should suppress app-level shortcut interception.
func (*Plugin) ContentLinkSurfaces ¶ added in v1.2.0
func (p *Plugin) ContentLinkSurfaces() []contentlink.Surface
ContentLinkSurfaces exposes only a loaded source preview whose rows can be mapped exactly to the rendered frame. Interactive modes and placeholder states deliberately opt out for the frame.
func (*Plugin) Cursor ¶ added in v0.88.0
Cursor exposes the inline editor's native cursor in plugin-local coordinates.
func (*Plugin) EditorOrigin ¶ added in v1.2.0
EditorOrigin implements inlineedit.Host: the top-left content cell in plugin-local coordinates.
func (*Plugin) EditorViewport ¶ added in v1.2.0
EditorViewport implements inlineedit.Host: the PTY's content box.
func (*Plugin) FocusContext ¶
FocusContext returns the current focus context.
func (*Plugin) FocusCycleStart ¶ added in v1.2.0
FocusCycleStart puts focus back on the window the toggle resumes at.
func (*Plugin) PaneFocus ¶ added in v1.2.0
PaneFocus returns the stable ID for the browser's existing pane focus.
func (*Plugin) PaneFocusStops ¶ added in v1.2.0
func (p *Plugin) PaneFocusStops() []plugin.PaneFocusStop
PaneFocusStops projects the browser's visible panes in their rendered order.
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.
func (*Plugin) SetPaneFocus ¶ added in v1.2.0
SetPaneFocus directly selects a visible browser pane.
func (*Plugin) SetPaneFocusActive ¶ added in v1.2.0
SetPaneFocusActive lets the outer deck mute Files' inner active border while a passive leaf owns focus. The managed bit preserves the browser's historical behavior until a host opts into this capability.
func (*Plugin) Update ¶
Update handles messages. A tree refresh deferred while a modal, search, or the inline editor was open is flushed here, once the message that closed it has been handled.
func (*Plugin) WheelAtBoundary ¶ added in v1.0.0
func (p *Plugin) WheelAtBoundary(msg tea.MouseWheelMsg) bool
WheelAtBoundary implements plugin.WheelBoundaryConsumer. It mirrors the routing in handleMouseScroll without opening files, updating selection, or rendering. Open overlays are answered by the overlay that owns mouse input, in the same precedence handleMouse uses, and never by the panes underneath. The inline editor stays unknown: its wheel belongs to the embedded application. The file-operation bar does not intercept the wheel, so the ordinary panes answer while it is open.
type PreviewLoadedMsg ¶
type PreviewLoadedMsg = filepreview.PreviewLoadedMsg
type PreviewResult ¶
type PreviewResult = filepreview.PreviewResult
type RevealErrorMsg ¶
type RevealErrorMsg = docview.RevealErrorMsg
RevealErrorMsg is sent when reveal in file manager fails.
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.