filetree

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package filetree is nook's left-side file-tree pane.

It wraps the glyph components/file-tree Model with the file-system walking and bordered surface nook needs. The walk uses the same ignore rules as the project picker (skip .git, node_modules, vendor, dist, target, and dotfiles) so the two surfaces stay consistent.

The pane emits an OpenMsg when the user presses Enter on a file leaf; the host turns that into a buffer-open command. Directory expand / collapse stays inside the pane.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTree

func BuildTree(root string) glyphtree.Node

BuildTree walks root and returns a single glyphtree.Node representing the project. Directories are sorted alphabetically with directories before files within each level. Errors during walk are silently skipped — the pane should never crash because a directory is unreadable.

func BuildTreeCmd added in v0.35.0

func BuildTreeCmd(root string) tea.Cmd

BuildTreeCmd walks root in a goroutine and returns a BuildTreeMsg the host model can hand to Pane.SetNode. Safe to fire multiple times — the handler ignores results whose Root no longer matches the pane's root.

Types

type BuildTreeMsg added in v0.35.0

type BuildTreeMsg struct {
	Root string
	Node glyphtree.Node
}

BuildTreeMsg carries the result of an async tree walk.

type OpenMsg

type OpenMsg struct{ Path string }

OpenMsg is emitted when the user opens a file leaf in the tree. Path is absolute (rooted at the pane's root).

type Pane

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

Pane is nook's file-tree side pane.

func New

func New(t theme.Theme, root string) Pane

New constructs a pane rooted at root. Construction is constant-time and does NOT walk the file system — that work happens asynchronously via BuildTreeCmd so first paint is never gated on the walk. View() renders a "Scanning…" placeholder until SetNode lands. This was the last sync FS call in nook's startup path; lightning-fast startup is a load-bearing property and must be preserved going forward.

func (*Pane) Blur

func (p *Pane) Blur()

Blur removes keyboard focus.

func (Pane) Built added in v0.35.0

func (p Pane) Built() bool

Built reports whether SetNode has landed at least once. Callers can use this to decide whether to show the pane's view or skip allocation.

func (*Pane) Focus

func (p *Pane) Focus()

Focus gives the pane keyboard focus.

func (Pane) Focused

func (p Pane) Focused() bool

Focused reports the pane's focus state.

func (*Pane) RefreshCmd added in v0.35.0

func (p *Pane) RefreshCmd() tea.Cmd

RefreshCmd returns a tea.Cmd that re-walks the file system off the UI thread and produces a BuildTreeMsg the host can hand back to SetNode. The previous synchronous Refresh blocked first paint on a home-directory launch (nook ~/.zshrc walks all of ~/repos and ~/Downloads); the async form preserves the snappy "Scanning…" placeholder behavior used at startup.

func (*Pane) Reveal

func (p *Pane) Reveal(absPath string)

Reveal expands the directories on the path to file and moves the cursor onto it. When the tree has not finished its initial walk yet, the reveal target is queued and replayed once SetNode lands. path must be slash-separated relative to root, or the function is a no-op.

func (Pane) Selected

func (p Pane) Selected() string

Selected returns the absolute path of the row under the cursor, or the empty string if the tree is empty.

func (*Pane) SetNode added in v0.35.0

func (p *Pane) SetNode(node glyphtree.Node)

SetNode replaces the pane's tree with a freshly walked node and replays any reveal target that came in while the walk was pending. Caller should match msg.Root against the pane's root before calling to discard stale walks (e.g. after a project-root change).

func (*Pane) SetSize

func (p *Pane) SetSize(w, h int)

SetSize sets the width and height the pane may draw within.

func (*Pane) SetTheme added in v0.38.0

func (p *Pane) SetTheme(t theme.Theme)

SetTheme swaps the palette used for borders, the file/folder glyphs, and the cursor row. The wrapped glyph file-tree model uses its own internal palette tied to lipgloss tokens, so visual changes are limited to the nook-side framing; deeper recolor is a follow-up.

func (Pane) Update

func (p Pane) Update(msg tea.Msg) (Pane, tea.Cmd)

Update routes a message through the underlying glyph tree model and rewrites its SelectMsg into a nook OpenMsg when the user opens a file leaf.

func (Pane) View

func (p Pane) View() string

View renders the pane inside a rounded border. When width or height is too small the function returns an empty string; the host should not allocate space for the pane in that case. Until the first BuildTreeMsg lands the pane renders a "Scanning…" placeholder so first paint is never gated on the file-system walk.

Jump to

Keyboard shortcuts

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