Documentation
¶
Overview ¶
Package filechooser contains tview TUI widgets for selecting files.
Index ¶
- type List
- type PathInputField
- type TreeView
- func (t *TreeView) Error() error
- func (t *TreeView) Select(p string) error
- func (t *TreeView) SetChangedFunc(handler func(path string, entry fs.DirEntry) error)
- func (t *TreeView) SetDirColor(c tcell.Color)
- func (t *TreeView) SetErrorColor(c tcell.Color)
- func (t *TreeView) SetFileColor(c tcell.Color)
- func (t *TreeView) SetRoot(fsys fs.FS, root string) error
- func (t *TreeView) SetSelectedFunc(handler func(path string, entry fs.DirEntry) error)
- func (t *TreeView) Walk(callback func(path string, entry fs.DirEntry) bool)
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 // 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
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
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) SetChangedFunc ¶ added in v0.0.3
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
Error returns any errors that were encountered during the last operation.
func (*TreeView) Select ¶ added in v0.0.2
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
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
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
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
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.