fuzzy

package module
v0.0.0-...-c65180b Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: MIT Imports: 9 Imported by: 0

README

fuzzy

Fuzzy finder tool and library

❯ fuzzy --help
Usage:
        fuzzy [options] [query] - output selected line from stdin (fuzzy search)
  -v    verbose. print out scores with text

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(query string, content *Content) (string, error)

Find takes each line from provided content, computes the smith waterman score orders the content and provides a user-interface to select an option

func FindWithScreen

func FindWithScreen(screen tcell.Screen, query string, content *Content) (string, error)

FindWithScreen is the same as Find, but you provide the Screen

Types

type Content

type Content struct {
	tview.TableContentReadOnly
	// contains filtered or unexported fields
}

Content holds the data for the fuzzy finder

func ReadNewContent

func ReadNewContent(input io.Reader) *Content

ReadNewContent creates a new Content from new line separated input

func SupplyNewContent

func SupplyNewContent(input EnumerableValueStringer) *Content

SupplyNewContent creates a new Content from a slice of ValueStringer types

func (*Content) Filter

func (c *Content) Filter(query string)

Filter processes InputItems, scores them with SmithWaterman Any items with score less than 1 are not shown Items are sorted by their score

func (*Content) GetCell

func (c *Content) GetCell(row, column int) *tview.TableCell

func (*Content) GetColumnCount

func (c *Content) GetColumnCount() int

func (*Content) GetRowCount

func (c *Content) GetRowCount() int

func (*Content) SetHideLessThan

func (c *Content) SetHideLessThan(score float64)

SetHideLessThan remove item from output with a lower score

func (*Content) SetReturnOneResult

func (c *Content) SetReturnOneResult()

SetReturnOneResult returns the one result immediatly if a passed in query only matches one item

func (*Content) SetTextScorer

func (c *Content) SetTextScorer(textScorer algo.TextScorer)

SetTextScorer sets the algorithm for scoring the query against the line

func (*Content) SetVerbose

func (c *Content) SetVerbose()

SetVerbose outputs the scores along with the line. useful for debugging

type EnumerableValueStringer

type EnumerableValueStringer interface {
	Each(handler func(ValueStringer))
}

EnumerableValueStringer is iterable

type InputItem

type InputItem struct {
	Score float64
	// contains filtered or unexported fields
}

InputItem is an item of ValueStringer with a Score

func NewInputItem

func NewInputItem(item ValueStringer) InputItem

type NopScorer

type NopScorer struct{}

func (NopScorer) Compare

func (NopScorer) Compare(a, b string) float64

type SortableInputItems

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

SortableInputItems can be Sorted by their Score and difference in length of query

func (SortableInputItems) Len

func (i SortableInputItems) Len() int

func (SortableInputItems) Less

func (i SortableInputItems) Less(x, y int) bool

func (SortableInputItems) Swap

func (i SortableInputItems) Swap(x, y int)

type Str

type Str string

Str is a simple string type

func NewStr

func NewStr(content string) Str

NewStr returns a ValueStringer type from a string

func (Str) String

func (s Str) String() string

func (Str) Value

func (s Str) Value() string

type StrList

type StrList []string

StrList is a simple string slice

func NewStrList

func NewStrList(s []string) StrList

NewStrList is a utility fuction to convert a string slice

func (StrList) Each

func (l StrList) Each(f func(ValueStringer))

Each allows iteration over the string slice

type StrMap

type StrMap map[string]string

StrMap uses the key as Value and value as String

func NewStrMap

func NewStrMap(m map[string]string) StrMap

NewStrMap is a utility function to convert a string map

func (StrMap) Each

func (m StrMap) Each(f func(ValueStringer))

Each allows iteration over the string map

type StrMapEntry

type StrMapEntry struct {
	Val string
	Str string
}

StrMapEntry implements ValueStringer

func (StrMapEntry) String

func (s StrMapEntry) String() string

func (StrMapEntry) Value

func (s StrMapEntry) Value() string

type ValueStringer

type ValueStringer interface {
	// String used for searching
	String() string
	// Value returned to user via stdout
	Value() string
}

ValueStringer has a value and a string output, potentially different

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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