filebrowser

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 40 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package filebrowser implements the file browser plugin with tree navigation, file preview, quick open, search, git integration, and file operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Highlight

func Highlight(content, extension, syntaxTheme string) (string, error)

func LoadPreview

func LoadPreview(rootDir, path string, epoch uint64) tea.Cmd

func LoadPreviewFile added in v0.98.0

func LoadPreviewFile(file *os.File, path string, epoch uint64) tea.Cmd

func RelativeTime

func RelativeTime(t time.Time) string

RelativeTime formats a time as a relative duration string.

func RunGitBlame

func RunGitBlame(workDir, filePath string, epoch uint64) tea.Cmd

RunGitBlame runs git blame and returns the parsed output.

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

type CreateSuccessMsg struct {
	Path  string
	IsDir bool
}

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

type FileOpSuccessMsg struct {
	Src string
	Dst string
}

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

func BuildTree(spec BuildSpec) (*FileTree, error)

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

func NewFileTree(rootDir string) *FileTree

NewFileTree creates a new file tree rooted at the given directory.

func (*FileTree) Build

func (t *FileTree) Build() error

Build initializes the tree by loading the root directory's children.

func (*FileTree) Collapse

func (t *FileTree) Collapse(node *FileNode)

Collapse closes a directory node.

func (*FileTree) Expand

func (t *FileTree) Expand(node *FileNode) error

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

func (t *FileTree) FindByPath(path string) *FileNode

FindByPath returns the node with the given relative path, or nil if not found.

func (*FileTree) FindParentDir

func (t *FileTree) FindParentDir(node *FileNode) *FileNode

FindParentDir returns the parent directory node, or nil if at root.

func (*FileTree) Flatten

func (t *FileTree) Flatten() []*FileNode

Flatten rebuilds the FlatList from visible nodes.

func (*FileTree) GetExpandedPaths

func (t *FileTree) GetExpandedPaths() map[string]bool

GetExpandedPaths returns the paths of all expanded directories.

func (*FileTree) GetNode

func (t *FileTree) GetNode(index int) *FileNode

GetNode returns the node at the given index, or nil if out of bounds.

func (*FileTree) IndexOf

func (t *FileTree) IndexOf(node *FileNode) int

IndexOf returns the index of a node in the flat list, or -1 if not found.

func (*FileTree) IndexOfPath added in v0.90.0

func (t *FileTree) IndexOfPath(path string) int

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) Len

func (t *FileTree) Len() int

Len returns the number of visible nodes.

func (*FileTree) RestoreExpandedPaths

func (t *FileTree) RestoreExpandedPaths(paths map[string]bool)

RestoreExpandedPaths expands directories that were previously expanded.

func (*FileTree) SetExpandedPaths added in v0.90.0

func (t *FileTree) SetExpandedPaths(paths map[string]bool)

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

func (t *FileTree) SetSortMode(mode SortMode)

SetSortMode changes the sort mode and re-sorts the tree.

func (*FileTree) Toggle

func (t *FileTree) Toggle(node *FileNode) error

Toggle expands or collapses a directory node.

type FocusPane

type FocusPane int

FocusPane represents which pane is active.

const (
	PaneTree FocusPane = iota
	PanePreview
)

type GitInfoMsg

type GitInfoMsg = docview.GitInfoMsg

GitInfoMsg contains git status for a file.

type InlineEditExitedMsg

type InlineEditExitedMsg struct {
	FilePath   string
	Activation uint64
	Epoch      uint64
}

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 = app.NavigateToFileMsg

NavigateToFileMsg requests navigation to a specific file (from other plugins).

type PasteSuccessMsg

type PasteSuccessMsg struct {
	Src string
	Dst string
}

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 New

func New() *Plugin

New creates a new File Browser plugin.

func (*Plugin) BlocksGlobalKeys added in v0.96.0

func (p *Plugin) BlocksGlobalKeys() bool

BlocksGlobalKeys reports whether a plugin-owned modal has keyboard focus.

func (*Plugin) Commands

func (p *Plugin) Commands() []plugin.Command

Commands returns the available commands.

func (*Plugin) ConsumesTextInput

func (p *Plugin) ConsumesTextInput() bool

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

func (p *Plugin) Cursor() *tea.Cursor

Cursor exposes the inline editor's native cursor in plugin-local coordinates.

func (*Plugin) FocusContext

func (p *Plugin) FocusContext() string

FocusContext returns the current focus context.

func (*Plugin) ID

func (p *Plugin) ID() string

ID returns the plugin identifier.

func (*Plugin) Icon

func (p *Plugin) Icon() string

Icon returns the plugin icon character.

func (*Plugin) Init

func (p *Plugin) Init(ctx *plugin.Context) error

Init initializes the plugin with context.

func (*Plugin) IsFocused

func (p *Plugin) IsFocused() bool

IsFocused returns whether the plugin is focused.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the plugin display name.

func (*Plugin) PreferredMouseMode added in v0.88.0

func (p *Plugin) PreferredMouseMode() tea.MouseMode

PreferredMouseMode reduces idle hover traffic only while the inline terminal owns input. Modal and ordinary file-browser views retain all-motion hover.

func (*Plugin) SetFocused

func (p *Plugin) SetFocused(f bool)

SetFocused sets the focus state.

func (*Plugin) Start

func (p *Plugin) Start() tea.Cmd

Start begins plugin operation.

func (*Plugin) Stop

func (p *Plugin) Stop()

Stop cleans up plugin resources.

func (*Plugin) Update

func (p *Plugin) Update(msg tea.Msg) (plugin.Plugin, tea.Cmd)

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) View

func (p *Plugin) View(width, height int) string

View renders the plugin.

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.

const (
	SortByName SortMode = iota
	SortBySize
	SortByTime
	SortByType
)

func (SortMode) Label

func (s SortMode) Label() string

SortModeLabel returns a short label for display.

func (SortMode) Next

func (s SortMode) Next() SortMode

NextSortMode cycles to the next sort mode.

type StateRestoredMsg

type StateRestoredMsg struct {
	State state.FileBrowserState
}

Message types

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

type WatchEventMsg struct {
	TreeChanged    bool
	PreviewChanged bool
	Dirs           []string
}

WatchEventMsg carries a coalesced batch of filesystem changes. Its fields mirror FSEvent exactly so the watcher event converts directly.

type WatchStartedMsg

type WatchStartedMsg struct{ Watcher *TreeWatcher }

Message types

Jump to

Keyboard shortcuts

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