fzf

package module
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 17 Imported by: 15

README

🔍 go-fzf

Go Reference GitHub release (latest by date) GitHub Workflow Status Maintainability Go Report Card LICENSE

Fuzzy Finder CLI and Library.

English | 日本語

Contents

Usage

Using as a CLI

If you want to know what you can do with go-fzf, try the gofzf CLI.
The gofzf CLI is built with go-fzf and can utilize most of go-fzf's features.

For more information, please refer to the documentation.

Using as a library

With go-fzf, you can easily create a highly customizable Fuzzy Finder.
For example, you can create a Fuzzy Finder like the one below with just this simple code:

package main

import (
	"fmt"
	"log"

	"github.com/koki-develop/go-fzf"
)

func main() {
	items := []string{"hello", "world", "foo", "bar"}

	f, err := fzf.New()
	if err != nil {
		log.Fatal(err)
	}

	idxs, err := f.Find(items, func(i int) string { return items[i] })
	if err != nil {
		log.Fatal(err)
	}

	for _, i := range idxs {
		fmt.Println(items[i])
	}
}

For more information, please refer to the documentation

Examples

Various examples of how to use go-fzf are available in the examples directory.

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAbort is returned when a Fuzzy Finder is aborted.
	ErrAbort = errors.New("abort")
)

Functions

This section is empty.

Types

type CountViewMeta added in v0.8.0

type CountViewMeta struct {
	ItemsCount    int
	MatchesCount  int
	SelectedCount int
	Width         int
	Limit         int
	NoLimit       bool
}

CountViewMeta provides information used in count view.

type FZF

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

Fuzzy Finder.

func New

func New(opts ...Option) (*FZF, error)

New returns a new Fuzzy Finder.

func (*FZF) Abort added in v0.7.0

func (fzf *FZF) Abort()

Abort aborts the Fuzzy Finder.

func (*FZF) Find

func (fzf *FZF) Find(items interface{}, itemFunc func(i int) string, opts ...FindOption) ([]int, error)

Find launches the Fuzzy Finder and returns a list of indexes of the selected items.

func (*FZF) ForceReload added in v0.7.0

func (fzf *FZF) ForceReload() error

ForceReload forces the reload of items. HotReload must be enabled.

func (*FZF) Quit added in v0.7.0

func (fzf *FZF) Quit()

Quit quits the Fuzzy Finder.

type FindOption added in v0.4.0

type FindOption func(o *findOption)

Option represents a option for the Find.

func WithItemPrefix added in v0.3.0

func WithItemPrefix(f func(i int) string) FindOption

WithItemPrefix sets the prefix function of the item.

func WithPreselect added in v0.15.0

func WithPreselect(idxs []int) FindOption

WithPreselect sets the preselected indexes.

func WithPreselectAll added in v0.14.0

func WithPreselectAll(preselect bool) FindOption

func WithPreviewWindow added in v0.13.0

func WithPreviewWindow(f func(i, width, height int) string) FindOption

WithPreviewWindow sets the preview window function of the item.

type InputPosition added in v0.11.0

type InputPosition string

InputPosition represents the position of input.

const (
	InputPositionTop    InputPosition = "top"
	InputPositionBottom InputPosition = "bottom"
)

func (InputPosition) Valid added in v0.11.0

func (p InputPosition) Valid() error

Valid validates the value of InputPosition.

type Items

type Items interface {
	// ItemString returns the string of the i-th item.
	ItemString(i int) string
	// Len returns the length of items.
	Len() int
}

Items represents a list of items to be searched.

type KeyMap

type KeyMap struct {
	Up     []string
	Down   []string
	Toggle []string
	Choose []string
	Abort  []string
}

KeyMap is the key mapping for the Fuzzy Finder.

type Match added in v0.8.0

type Match struct {
	Str            string
	Index          int
	MatchedIndexes []int
}

Match represents a matched string.

type Matches added in v0.8.0

type Matches []Match

Matches is a slice of Match.

func Search(items Items, search string, opts ...SearchOption) Matches

Search performs a fuzzy search for items.

type Option

type Option func(o *option)

Option represents a option for the Fuzzy Finder.

func WithCaseSensitive added in v0.7.0

func WithCaseSensitive(s bool) Option

WithCaseSensitive sets the case sensitivity.

func WithCountView added in v0.5.0

func WithCountView(f func(meta CountViewMeta) string) Option

WithCountView sets the function to create the count view.

func WithCountViewEnabled added in v0.5.0

func WithCountViewEnabled(b bool) Option

WithCountViewEnabled enables or disables count view.

func WithCursor

func WithCursor(c string) Option

WithCursor sets the cursor.

func WithHotReload added in v0.7.0

func WithHotReload(locker sync.Locker) Option

WithHotReload sets the locker for read items.

func WithInputPlaceholder

func WithInputPlaceholder(p string) Option

WithInputPlaceholder sets the placeholder for input.

func WithInputPosition added in v0.11.0

func WithInputPosition(p InputPosition) Option

WithInputPosition sets the position of input.

func WithKeyMap

func WithKeyMap(km KeyMap) Option

WithKeyMap sets the key mapping.

func WithLimit

func WithLimit(l int) Option

WithLimit sets the number of items that can be selected.

func WithNoLimit

func WithNoLimit(n bool) Option

WithNoLimit can be set to `true` to allow unlimited item selection.

func WithPrompt

func WithPrompt(p string) Option

WithPrompt sets the prompt text.

func WithSelectedPrefix

func WithSelectedPrefix(p string) Option

WithSelectedPrefix sets the prefix of the selected item.

func WithStyles

func WithStyles(opts ...StylesOption) Option

WithStyles sets the various styles.

func WithUnselectedPrefix

func WithUnselectedPrefix(p string) Option

WithUnselectedPrefix sets the prefix of the unselected item.

type SearchOption added in v0.8.0

type SearchOption func(o *searchOption)

SearchOption represents a option for a search.

func WithSearchCaseSensitive added in v0.8.0

func WithSearchCaseSensitive(c bool) SearchOption

type Style

type Style struct {
	ForegroundColor string
	BackgroundColor string
	Bold            bool
	Blink           bool
	Italic          bool
	Strikethrough   bool
	Underline       bool
	Faint           bool
}

Style represents a style.

type Styles

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

Styles is the styles for each component.

func NewStyles

func NewStyles(opts ...StylesOption) *Styles

NewStyles returns a new styles.

type StylesOption

type StylesOption func(o *stylesOption)

Option represents a option for the styles.

func WithStyleCursor

func WithStyleCursor(s Style) StylesOption

WithStyleCursor sets the style of cursor.

func WithStyleCursorLine

func WithStyleCursorLine(s Style) StylesOption

WithStyleCursorLine sets the style of cursor line.

func WithStyleInputPlaceholder added in v0.10.0

func WithStyleInputPlaceholder(s Style) StylesOption

WithInputPlaceholder sets the style of placeholder for input.

func WithStyleInputText added in v0.10.0

func WithStyleInputText(s Style) StylesOption

WithStyleInputText sets the style of input text.

func WithStyleMatches

func WithStyleMatches(s Style) StylesOption

WithStyleMatches sets the style of the matched characters.

func WithStylePrompt added in v0.10.0

func WithStylePrompt(s Style) StylesOption

WithStylePrompt sets the style of prompt.

func WithStyleSelectedPrefix

func WithStyleSelectedPrefix(s Style) StylesOption

WithStyleSelectedPrefix sets the style of prefix of the selected item.

func WithStyleUnselectedPrefix

func WithStyleUnselectedPrefix(s Style) StylesOption

WithStyleUnselectedPrefix sets the style of prefix of the unselected item.

Jump to

Keyboard shortcuts

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