source

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package source ships the concrete FileSource implementations that are generically useful — a local-filesystem lister and a zero-IO in-memory tree — plus a conformance harness any adapter (including an app's own SFTP source) can run. This is the one place stdlib os enters the shipped module; the kernel stays os-free. A transport that legitimately diverges per app — ssherpa's SFTP over a multiplexed SSH socket — lives in that app's shim, the divergent-transport analogue of an app's builtin palette.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conformance

func Conformance(t *testing.T, s termnav.FileSource, start string)

Conformance is a table-driven harness that asserts a FileSource honors the contract every transport must keep, so a new source (an app's SFTP lister, say) verifies itself with one call. It resolves start, lists the result, and checks the structural invariants the reducer relies on. It performs real IO, so point it at a fixture directory the test controls.

func ExpandLocalPath

func ExpandLocalPath(path string) (string, error)

ExpandLocalPath expands a leading ~, makes the path absolute, and Cleans it — the shared normalization both apps' local pickers performed.

Types

type LocalOptions

type LocalOptions struct {
	SkipHidden  bool // omit dotfiles
	DirsOnly    bool // omit files entirely (a folder picker)
	SelectFiles bool // files are selectable leaves (file picker) vs dimmed reference rows
	UseRow      bool // inject a "Use this folder" row that commits the current dir

	// Cosmetic + app-Kind fields. Empty leaves the corresponding Row field empty.
	DirSuffix                              string // appended to a directory's Title (e.g. "/"); default "/"
	UseTitle                               string // default "Use this folder"
	DirGroup, FileGroup, UseGroup, UpGroup string
	DirBadge, FileBadge, UseBadge, UpBadge string
	DirKind, FileKind, UseKind, UpKind     string

	// Describe builds a file row's Description (size, mtime). nil leaves it empty.
	Describe func(os.FileInfo) string
	// Decorate is a final per-row hook to set any remaining app cosmetics; it
	// receives the built row and the entry it came from. nil is a no-op.
	Decorate func(termnav.Row, os.DirEntry, os.FileInfo) termnav.Row
}

LocalOptions configures a LocalSource. The zero value lists a directory's children with files selectable and no synthetic rows — a plain file browser.

type LocalSource

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

LocalSource lists the local filesystem with os.ReadDir. It implements FileSource and SyncLister (local reads are instant, so the adapter skips the Loading flash).

func NewLocal

func NewLocal(opt LocalOptions) *LocalSource

NewLocal returns a LocalSource with the given options.

func (*LocalSource) List

func (s *LocalSource) List(ctx context.Context, dir string) (termnav.Listing, error)

List reads one directory's children. It honors the context for cancelation by checking it up front (a local read is fast, but a slow network mount is not).

func (*LocalSource) ListSync

func (s *LocalSource) ListSync(dir string) (termnav.Listing, error)

ListSync is the synchronous read used by SyncLister-aware adapters.

func (*LocalSource) Resolve

func (s *LocalSource) Resolve(_ context.Context, path string) (string, error)

Resolve canonicalizes a start path: it expands a leading ~, makes it absolute, Cleans it, and steps to the containing directory if it is a file — the exact normalization ssherpa's expandLocalPath performed.

type StaticSource

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

StaticSource serves a single pre-built listing and never navigates. It adapts the existing "caller assembled a []Row already" path (a flat picker over a fixed set) onto the FileSource seam, so the same browse model and rendering drive a non-navigable list. List ignores its dir argument.

func NewStatic

func NewStatic(dir string, rows []termnav.Row) *StaticSource

NewStatic wraps a fixed set of rows as a FileSource. dir labels the location.

func (*StaticSource) List

func (*StaticSource) ListSync

func (s *StaticSource) ListSync(_ string) (termnav.Listing, error)

func (*StaticSource) Resolve

func (s *StaticSource) Resolve(_ context.Context, _ string) (string, error)

type TreeOptions

type TreeOptions struct {
	FolderSuffix                               string // appended to a folder's Title; default "/"
	UseRow                                     bool   // inject a "Use this folder" row
	UseTitle                                   string
	FolderGroup, EntryGroup, UseGroup, UpGroup string
	FolderBadge, EntryBadge, UseBadge, UpBadge string
	FolderKind, EntryKind, UseKind, UpKind     string
}

TreeOptions configures the cosmetics of a TreeSource's rows.

type TreeSource

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

TreeSource is a zero-IO FileSource over an in-memory navigation Index built from a flat snapshot of entry paths (passage's implicit pass-store tree). It implements FileSource, SyncLister, and Indexer — the last proving that path-completion and directory-browse are two renderings of one navigation index: the same snapshot that drives the composer's TAB completion also backs a full browser. Listing a node never blocks, so navigation is instant.

func NewTree

func NewTree(entryPaths []string, opt TreeOptions) *TreeSource

NewTree builds a TreeSource from a flat list of entry paths.

func (*TreeSource) Index

func (s *TreeSource) Index() *termnav.Index

Index exposes the underlying navigation index for breadcrumb / TAB completion.

func (*TreeSource) List

func (s *TreeSource) List(_ context.Context, dir string) (termnav.Listing, error)

List returns the children of the folder at dir (no trailing slash; "" root).

func (*TreeSource) ListSync

func (s *TreeSource) ListSync(dir string) (termnav.Listing, error)

ListSync is the synchronous (instant) listing.

func (*TreeSource) Resolve

func (s *TreeSource) Resolve(_ context.Context, path string) (string, error)

Resolve normalizes a pass folder path: trims surrounding slashes; the root is the empty string.

Jump to

Keyboard shortcuts

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