filebrowser

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 7 Imported by: 1 module, 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 provides the filesystem side of the in-app file and folder picker: listing, filtering, path input parsing and the sidebar places.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by Resolve when the path does not name an item of the requested kind.

Functions

func DirText

func DirText(dir string) string

DirText returns dir formatted for the path field: cleaned, with a single trailing separator so typing continues inside it.

func HomeDir

func HomeDir() string

HomeDir returns the user's home directory, or the filesystem root of the working directory when it cannot be determined.

func Parent

func Parent(dir string) (string, bool)

Parent returns the parent of dir, or false when dir is a filesystem or drive root.

func Resolve

func Resolve(text string, mode Mode) (string, error)

Resolve checks that text is an absolute path naming an existing item of the kind the mode picks and returns it cleaned.

func SplitInput

func SplitInput(text string) (dir, filter string)

SplitInput splits path field text at the last separator into the directory part (including the separator) and the filter text after it. Text with no separator is all filter.

Types

type Entry

type Entry struct {
	Name  string
	Path  string
	IsDir bool
}

Entry is a single item in a directory listing.

func Filter

func Filter(entries []Entry, text string) []Entry

Filter returns the entries whose name contains text, case-insensitively. An empty text returns entries unchanged.

func ReadDir

func ReadDir(dir string, mode Mode) ([]Entry, error)

ReadDir lists dir for the given mode. Dot entries are skipped. Symlinks are followed so a link to a directory lists as a directory; broken links are skipped. Directories sort before files, each case-insensitively.

type Mode

type Mode int

Mode selects what the picker returns.

const (
	// ModeFolder picks a directory. Only directories are listed.
	ModeFolder Mode = iota
	// ModeFile picks a regular file. Directories and files are listed.
	ModeFile
)

type Place

type Place struct {
	Label string
	Path  string
	Kind  PlaceKind
}

Place is one sidebar entry. Label is for display only; Path is the real filesystem path.

func Places

func Places() []Place

Places returns the sidebar entries: Home, the standard folders that exist, then the platform's roots and volumes.

type PlaceKind

type PlaceKind int

PlaceKind groups sidebar places.

const (
	// PlaceFolder is a standard user folder (Home, Desktop, ...).
	PlaceFolder PlaceKind = iota
	// PlaceVolume is a filesystem root, drive or mounted volume.
	PlaceVolume
)

Jump to

Keyboard shortcuts

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