filechooser

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: BSD-2-Clause Imports: 9 Imported by: 0

README

mellium.im/filechooser

GoDoc Issue Tracker Chat License CI

The filechooser module contains widgets for the tview terminal user interface toolkit that deal with selecting files. The following widgets are currently available:

Widgets

Path Input

The path input field is a widget that lets the user begin typing a path and provides autocomplete. It supports patterns, multi-file selection, and other options.

Tree View

A tree view with the root and /etc folders expanded.

The tree view field is a widget that shows files and folders as a tree and supports showing files, directories, both, and various other options.

List

A list of files including a double-dot navigation element.

The list view shows a single directories files and has optional navigation between directories.

License

The package may be used under the terms of the BSD 2-Clause License a copy of which may be found in the file "LICENSE".

Unless you explicitly state otherwise, any contribution submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.

Documentation

Overview

Package filechooser contains tview TUI widgets for selecting files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List added in v0.0.3

type List struct {
	*tview.List

	// ShowHidden will show files starting with a '.' in the tree.
	ShowHidden bool

	// HideFiles causes the view to skip showing any non-directory files.
	HideFiles bool

	// HideDirectories causes the view to skip showing any directories (other than
	// the top level one).
	HideDirectories bool

	// Pattern is a shell file name pattern to match.
	// Directories will still be shown, but files that do not match this pattern
	// will be filtered from autocomplete.
	Pattern string

	// EnableNavigation adds the special ".." menu item to each non-root directory
	// and enables navigating to a child directory by selecting it.
	EnableNavigation bool
	// contains filtered or unexported fields
}

List is a selectable list that can show traversable directories and files.

func NewList added in v0.0.3

func NewList(fsys fs.FS) *List

NewFileList creates a list, but does not initialize it to avoid having to deal with filesystem related errors while setting up the UI. To initialize the view choose a directory to display with Select.

func (*List) GetName added in v0.0.3

func (l *List) GetName(idx int) (string, error)

GetName returns the name of the item at the given index. It strips out all tview styling directives from the text. To get the name with any styling directives included use "*tview.List".GetItemText.

func (*List) Select added in v0.0.3

func (l *List) Select(p string) error

Select opens the given path in the list view.

func (*List) SetChangedFunc added in v0.0.3

func (l *List) SetChangedFunc(handler func(path string, entry fs.DirEntry) error)

SetChangedFunc sets the function which is called when the currently selected directory or file changes, for example when the user navigates to a new directory without hitting Enter. If an error is returned from the handler the entry color will change to the one provided by SetErrorColor.

func (*List) SetDirColor added in v0.0.3

func (l *List) SetDirColor(c tcell.Color)

SetDirColor sets the color of directories in the list. This does not affect links to directories, which are still files.

func (*List) SetErrorColor added in v0.0.3

func (l *List) SetErrorColor(c tcell.Color)

SetErrorColor sets the color that directories or files change to when an error is encountered. Normally this happens when you try to enter directories but you do not have permission to read them.

func (*List) SetFileColor added in v0.0.3

func (l *List) SetFileColor(c tcell.Color)

SetFileColor sets the color of files in the list. This includes links.

type PathInputField

type PathInputField struct {
	*tview.InputField

	// ShowHidden will show files starting with a '.' in the autocomplete list.
	ShowHidden bool

	// Pattern is a shell file name pattern to match.
	// Directories will still be shown, but files that do not match this pattern
	// will be filtered from autocomplete.
	Pattern string

	// MultiSelect allows you to type an os.PathListSeparator to create a list of
	// files.
	MultiSelect bool

	// Root is the root filesystem for use when selecting files.
	// If no filesystem is provided, os.DirFS("/") is used.
	Root fs.FS
	// contains filtered or unexported fields
}

PathInputField is a tview primitive that lets you enter one or more file or directory paths and provides niceties like validation and autocomplete.

Paths entered by the user may use shell pattern syntax to narrow down the autocomplete list, see filepath.Match for more information.

func NewPathInputField

func NewPathInputField() *PathInputField

NewPathInputField creates a new input field with autocomplete and other niceties configured.

func (*PathInputField) Error

func (i *PathInputField) Error() error

Error returns any errors that were encountered while parsing the current text input.

func (*PathInputField) Files

func (i *PathInputField) Files() []string

Files returns a slice of all files selected

type TreeView added in v0.0.2

type TreeView struct {
	*tview.TreeView

	// ShowHidden will show files starting with a '.' in the tree.
	ShowHidden bool

	// HideFiles causes the view to skip showing any non-directory files.
	HideFiles bool

	// HideDirectories causes the view to skip showing any directories (other than
	// the top level one).
	HideDirectories bool

	// Pattern is a shell file name pattern to match.
	// Directories will still be shown, but files that do not match this pattern
	// will be filtered from autocomplete.
	Pattern string
	// contains filtered or unexported fields
}

TreeView is is like a tview.TreeView but it shows directories and files in a filesystem.

func NewTreeView added in v0.0.2

func NewTreeView() *TreeView

NewTreeView creates a tree view, but does not initialize it to avoid having to deal with filesystem related errors while setting up the UI. To initialize the view see SetRoot.

func (*TreeView) Error added in v0.0.2

func (t *TreeView) Error() error

Error returns any errors that were encountered during the last operation.

func (*TreeView) Select added in v0.0.2

func (t *TreeView) Select(p string) error

Select iterates through the nodes of the tree, opening and reading directories until the current path is reached or an error is encountered. After expanding the tree it selects the path.

func (*TreeView) SetChangedFunc added in v0.0.2

func (t *TreeView) SetChangedFunc(handler func(path string, entry fs.DirEntry) error)

SetChangedFunc sets the function which is called when the currently selected directory or file changes, for example when the user navigates to a new directory without hitting Enter. If an error is returned from the handler the entry color will change to the one provided by SetErrorColor.

func (*TreeView) SetDirColor added in v0.0.2

func (t *TreeView) SetDirColor(c tcell.Color)

SetDirColor sets the color of directories in the tree. This does not affect links to directories, which are still files.

func (*TreeView) SetErrorColor added in v0.0.2

func (t *TreeView) SetErrorColor(c tcell.Color)

SetErrorColor sets the color that directories or files change to when an error is encountered. Normally this happens when you try to expand directories but you do not have permission to read them.

func (*TreeView) SetFileColor added in v0.0.2

func (t *TreeView) SetFileColor(c tcell.Color)

SetFileColro sets the color of files in the tree. This includes links.

func (*TreeView) SetRoot added in v0.0.2

func (t *TreeView) SetRoot(fsys fs.FS, root string) error

SetRoot is used to recycle a tree view for use with a new filesystem. If fsys is nil, os.DirFS("/") will be used.

func (*TreeView) SetSelectedFunc added in v0.0.2

func (t *TreeView) SetSelectedFunc(handler func(path string, entry fs.DirEntry) error)

SetSelectedFunc sets the function which is called when the user selects a node by pressing Enter on the current selection. If an error is returned from the handler other actions (such as expanding or collapsing the directory) are canceled and the entry color will change to the one provided by SetErrorColor.

func (*TreeView) Walk added in v0.0.2

func (t *TreeView) Walk(callback func(path string, entry fs.DirEntry) bool)

Walk traverses every node that has been loaded into the tree in depth-first, pre-order (NLR) order and calls the provided callback on each traversed node (including the root node). If a directory has never been expanded, it has not yet been loaded and will not be walked. The callback returns whether traversal should continue with the traversed nodes child nodes or skip this branch.

Directories

Path Synopsis
cmd
internal
escape
Package escape contains a transformers relating to tview styles.
Package escape contains a transformers relating to tview styles.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳