filter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirsFilter

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

DirsFilter filters *Entry by its type and allows directories only.

func (*DirsFilter) Filter

func (df *DirsFilter) Filter(e *structure.Entry) bool

func (*DirsFilter) ID

func (df *DirsFilter) ID() ID

func (*DirsFilter) Reset

func (df *DirsFilter) Reset()

func (*DirsFilter) Toggle

func (df *DirsFilter) Toggle()

type EmptyDirFilter added in v0.1.2

type EmptyDirFilter struct{}

EmptyDirFilter filters empty directories. It checks the total number of files, including those in subdirectories, and discards it if it does not have any.

The filter does not affect file *Entry instances.

func (*EmptyDirFilter) Filter added in v0.1.2

func (edf *EmptyDirFilter) Filter(e *structure.Entry) bool

func (*EmptyDirFilter) ID added in v0.1.2

func (edf *EmptyDirFilter) ID() ID

type EntryFilter

type EntryFilter interface {
	// ID returns a filter identifier allowing to uniquely identify the filter.
	ID() ID

	// Filter contains the filtering logic and returns a bool value on whether
	// the *Entry instance passed the filtration.
	Filter(e *structure.Entry) bool
}

EntryFilter defines a contract for filtering a single *structure.Entry instance.

type FilesFilter

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

FilesFilter filters *Entry by its type and allows files only.

func (*FilesFilter) Filter

func (df *FilesFilter) Filter(e *structure.Entry) bool

func (*FilesFilter) ID

func (df *FilesFilter) ID() ID

func (*FilesFilter) Reset

func (df *FilesFilter) Reset()

func (*FilesFilter) Toggle

func (df *FilesFilter) Toggle()

type FiltersList

type FiltersList map[ID]EntryFilter

FiltersList aggregates a list of multiple filters.

func NewFiltersList

func NewFiltersList(ef ...EntryFilter) FiltersList

NewFiltersList creates a new list of filters based on the provided argument. All filters should be disabled/inactive by default.

func (*FiltersList) Reset

func (fl *FiltersList) Reset()

Reset traverses all filters in the list and calls EntryFilter.Reset method for each of them.

func (*FiltersList) ToggleFilter

func (fl *FiltersList) ToggleFilter(id ID)

ToggleFilter enables or disables the provided filter by the provided unique filter name. Unknown filters that were not added to the list will be ignored.

func (*FiltersList) Update

func (fl *FiltersList) Update(msg tea.Msg)

Update traverses all filters implementing the Updater interface in order to update the filters' state based on incoming input.

func (*FiltersList) Valid

func (fl *FiltersList) Valid(e *structure.Entry) bool

Valid checks the provided *Entry instance against all filters and returns a bool value. The "true" value will be returned if the entry passes all defined filters.

type ID

type ID string

ID defines a custom type for the filter identifier.

const (
	DirsOnlyFilterID  ID = "DirsOnly"
	FilesOnlyFilterID ID = "FilesOnly"
	NameFilterID      ID = "NameFilter"
	EmptyDirFilterID  ID = "EmptyDirFilter"
)

type NameFilter

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

NameFilter filters a single instance of the *structure.Entry by its path value. If the entry's path value does not contain the user's input, it will not be filtered/discarded.

The user's input is handled by the textinput.Model instance, therefore the filter must update internal state by providing the corresponding Updater implementation.

func NewNameFilter

func NewNameFilter(textColor string) *NameFilter

func (*NameFilter) Filter

func (nf *NameFilter) Filter(e *structure.Entry) bool

Filter filters an instance of *structure.Entry by checking if its path value contains the current filter input.

func (*NameFilter) ID

func (nf *NameFilter) ID() ID

func (*NameFilter) Reset

func (nf *NameFilter) Reset()

func (*NameFilter) Toggle

func (nf *NameFilter) Toggle()

func (*NameFilter) Update

func (nf *NameFilter) Update(msg tea.Msg)

func (*NameFilter) View

func (nf *NameFilter) View() string

type NameFilterType added in v0.11.0

type NameFilterType int

NameFilterType represents a filter type that will be applied during the filtering process.

const (
	// RegularNameFilter represents a default filter type where the filter value
	// must be a substring of the original text.
	RegularNameFilter NameFilterType = iota

	// NegativeNameFilter represents a filter type with the behavior opposite to
	// RegularNameFilter. It's enabled by the "\" backslash prefix at the beginning
	// of the filter input.
	NegativeNameFilter

	// RegexNameFilter represents a regular expression filter type where the
	// filter input will be treated as a valid regular expression. It's enabled
	// by the ":" colon prefix at the beginning of the filter input.
	RegexNameFilter
)

type Reset added in v0.1.2

type Reset interface {
	Reset()
}

Reset resets the filter's state and disables it.

type Toggler added in v0.1.2

type Toggler interface {
	Toggle()
}

Toggler enables or disables the filter.

type Updater

type Updater interface {
	Update(msg tea.Msg)
}

Updater defines an interface for filters that require their state to be updated during application rendering, e.g., a name filter.

type Viewer

type Viewer interface {
	View() string
}

Viewer defines an interface for filters that can be rendered or require the user's input to interact.

Jump to

Keyboard shortcuts

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