Documentation
¶
Index ¶
- type Selector
- func (s *Selector[T]) From(data []T, keyFunc func(elem T) string) *Selector[T]
- func (s *Selector[T]) Select() (int, T, error)
- func (s *Selector[T]) WithFatalOnAbort(msg string) *Selector[T]
- func (s *Selector[T]) WithFatalOnError(msg string) *Selector[T]
- func (s *Selector[T]) WithFuzzyArgs(args ...fuzzy.Option) *Selector[T]
- func (s *Selector[T]) WithPreview(previewFunc func(elem T, width, height int) string) *Selector[T]
- func (s *Selector[T]) WithPrompt(prompt string) *Selector[T]
- func (s *Selector[T]) WithQuery(query string) *Selector[T]
- func (s *Selector[T]) WithYamlPreview() *Selector[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Selector ¶
type Selector[T any] struct { // contains filtered or unexported fields }
func (*Selector[T]) From ¶
From sets the slice from which to select and the function that computes the key (which is displayed) of a given item. The keyFunc should return a string that represents the passed in entry. Duplicate keys are allowed, but may be indistinguishable if not further distinguished by a preview function.
func (*Selector[T]) Select ¶
Select launches the fuzzy finder for the actual selection. It returns the index and the selected item. Note that the function will not return an error and exit instead if the 'WithFatalOn...' method was called for the respective error case.
func (*Selector[T]) WithFatalOnAbort ¶
WithFatalOnAbort sets the message that is displayed when the user aborts the selection or does not select a valid entry. If this is not empty, the Select method will fatal with this message when the user aborts the selection.
func (*Selector[T]) WithFatalOnError ¶
WithFatalOnError sets the message that is displayed when an error occurs during selection. If this is not empty, the Select method will fatal with this message when an error occurs. The message is expected to be a format string with a single %w verb for the error.
func (*Selector[T]) WithFuzzyArgs ¶
WithFuzzyArgs adds arbitrary fuzzy finder options to the selector. It is recommended to only use this option if the other functions do not cover the desired functionality.
func (*Selector[T]) WithPreview ¶
WithPreview sets the preview window function for the fuzzy finder. The preview function is called with the selected element and the width and height of the preview window.
func (*Selector[T]) WithPrompt ¶
WithPrompt sets the prompt string for the fuzzy finder.
func (*Selector[T]) WithYamlPreview ¶
WithYamlPreview is an alternative to WithPreview and simply renders the complete selected item as YAML in the preview window.