filterer

package
v0.0.0-...-40291e4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package filter provides a fuzzy searching text input to allow filtering a list of options to select one option.

By default it will list all the files (recursively) in the current directory for the user to choose one, but the script (or user) can provide different new-line separated options to choose from.

I.e. let's pick from a list of gum flavors:

$ cat flavors.text | gum filter

Index

Constants

View Source
const StatusAborted = 130

Variables

View Source
var ErrAborted = fmt.Errorf("aborted")

ErrAborted is the error to return when a gum command is aborted by Ctrl + C.

Functions

func IsEmpty

func IsEmpty() bool

IsEmpty returns whether stdin is empty.

func List

func List() []string

List returns a list of all files in the current directory. It ignores the .git directory.

func Read

func Read() (string, error)

func Strip

func Strip(text string) string

Strip strips a string of any of it's ansi sequences.

Types

type Options

type Options struct {
	Indicator             string       `help:"Character for selection" default:"•" env:"GUM_FILTER_INDICATOR"`
	IndicatorStyle        style.Styles `embed:"" prefix:"indicator." set:"defaultForeground=212" envprefix:"GUM_FILTER_INDICATOR_"`
	Limit                 int          `help:"Maximum number of options to pick" default:"1" group:"Selection"`
	NoLimit               bool         `help:"Pick unlimited number of options (ignores limit)" group:"Selection"`
	Strict                bool         `help:"Only returns if anything matched. Otherwise return Filter" negatable:"true" default:"true" group:"Selection"`
	SelectedPrefix        string       `help:"Character to indicate selected items (hidden if limit is 1)" default:" ◉ " env:"GUM_FILTER_SELECTED_PREFIX"`
	SelectedPrefixStyle   style.Styles `embed:"" prefix:"selected-indicator." set:"defaultForeground=212" envprefix:"GUM_FILTER_SELECTED_PREFIX_"`
	UnselectedPrefix      string       `help:"Character to indicate unselected items (hidden if limit is 1)" default:" ○ " env:"GUM_FILTER_UNSELECTED_PREFIX"`
	UnselectedPrefixStyle style.Styles `embed:"" prefix:"unselected-prefix." set:"defaultForeground=240" envprefix:"GUM_FILTER_UNSELECTED_PREFIX_"`
	HeaderStyle           style.Styles `embed:"" prefix:"header." set:"defaultForeground=240" envprefix:"GUM_FILTER_HEADER_"`
	Header                string       `help:"Header value" default:"" env:"GUM_FILTER_HEADER"`
	TextStyle             style.Styles `embed:"" prefix:"text." envprefix:"GUM_FILTER_TEXT_"`
	MatchStyle            style.Styles `embed:"" prefix:"match." set:"defaultForeground=212" envprefix:"GUM_FILTER_MATCH_"`
	Placeholder           string       `help:"Placeholder value" default:"Filter..." env:"GUM_FILTER_PLACEHOLDER"`
	Prompt                string       `help:"Prompt to display" default:"> " env:"GUM_FILTER_PROMPT"`
	PromptStyle           style.Styles `embed:"" prefix:"prompt." set:"defaultForeground=240" envprefix:"GUM_FILTER_PROMPT_"`
	Width                 int          `help:"Input width" default:"20" env:"GUM_FILTER_WIDTH"`
	Height                int          `help:"Input height" default:"0" env:"GUM_FILTER_HEIGHT"`
	Value                 string       `help:"Initial filter value" default:"" env:"GUM_FILTER_VALUE"`
	Reverse               bool         `help:"Display from the bottom of the screen" env:"GUM_FILTER_REVERSE"`
	Fuzzy                 bool         `help:"Enable fuzzy matching" default:"true" env:"GUM_FILTER_FUZZY" negatable:""`
}

Options is the customization options for the filter command.

func (Options) BeforeReset

func (o Options) BeforeReset(ctx *kong.Context) error

BeforeReset hook. Used to unclutter style flags.

func (Options) Run

func (o Options) Run(element *parser.Element) (*parser.Element, error)

Run provides a shell script interface for filtering through options, powered by the textinput bubble.

Jump to

Keyboard shortcuts

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