fzf

package
v0.0.0-...-6b10b41 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2021 License: MIT, MIT Imports: 32 Imported by: 0

Documentation

Overview

Package fzf implements fzf, a command-line fuzzy finder.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package fzf implements fzf, a command-line fuzzy finder.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	EvtReadNew util.EventType = iota
	EvtReadFin
	EvtSearchNew
	EvtSearchProgress
	EvtSearchFin
	EvtHeader
	EvtReady
	EvtQuit
)

fzf events

Variables

View Source
var EmptyMerger = NewMerger(nil, [][]Result{}, false, false)

EmptyMerger is a Merger with no data

Functions

func CountItems

func CountItems(cs []*Chunk) int

CountItems returns the total number of Items

func Fzf

func Fzf(choices []string, options []string) (chosen []string, err error)

Fzf is like Run but can be used in a go program

func Run

func Run(opts *Options, version string, revision string)

Run starts fzf

Types

type ByOrder

type ByOrder []Offset

ByOrder is for sorting substring offsets

func (ByOrder) Len

func (a ByOrder) Len() int

func (ByOrder) Less

func (a ByOrder) Less(i, j int) bool

func (ByOrder) Swap

func (a ByOrder) Swap(i, j int)

type ByRelevance

type ByRelevance []Result

ByRelevance is for sorting Items

func (ByRelevance) Len

func (a ByRelevance) Len() int

func (ByRelevance) Less

func (a ByRelevance) Less(i, j int) bool

func (ByRelevance) Swap

func (a ByRelevance) Swap(i, j int)

type ByRelevanceTac

type ByRelevanceTac []Result

ByRelevanceTac is for sorting Items

func (ByRelevanceTac) Len

func (a ByRelevanceTac) Len() int

func (ByRelevanceTac) Less

func (a ByRelevanceTac) Less(i, j int) bool

func (ByRelevanceTac) Swap

func (a ByRelevanceTac) Swap(i, j int)

type Case

type Case int

Case denotes case-sensitivity of search

const (
	CaseSmart Case = iota
	CaseIgnore
	CaseRespect
)

Case-sensitivities

type Chunk

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

Chunk is a list of Items whose size has the upper limit of chunkSize

func (*Chunk) IsFull

func (c *Chunk) IsFull() bool

IsFull returns true if the Chunk is full

type ChunkCache

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

ChunkCache associates Chunk and query string to lists of items

func NewChunkCache

func NewChunkCache() ChunkCache

NewChunkCache returns a new ChunkCache

func (*ChunkCache) Add

func (cc *ChunkCache) Add(chunk *Chunk, key string, list []Result)

Add adds the list to the cache

func (*ChunkCache) Lookup

func (cc *ChunkCache) Lookup(chunk *Chunk, key string) []Result

Lookup is called to lookup ChunkCache

func (*ChunkCache) Search

func (cc *ChunkCache) Search(chunk *Chunk, key string) []Result

type ChunkList

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

ChunkList is a list of Chunks

func NewChunkList

func NewChunkList(trans ItemBuilder) *ChunkList

NewChunkList returns a new ChunkList

func (*ChunkList) Clear

func (cl *ChunkList) Clear()

Clear clears the data

func (*ChunkList) Push

func (cl *ChunkList) Push(data []byte) bool

Push adds the item to the list

func (*ChunkList) Snapshot

func (cl *ChunkList) Snapshot() ([]*Chunk, int)

Snapshot returns immutable snapshot of the ChunkList

type Delimiter

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

Delimiter for tokenizing the input

func (Delimiter) String

func (d Delimiter) String() string

String returns the string representation of a Delimiter.

type History

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

History struct represents input history

func NewHistory

func NewHistory(path string, maxSize int) (*History, error)

NewHistory returns the pointer to a new History struct

type Item

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

Item represents each input line. 56 bytes.

func (*Item) AsString

func (item *Item) AsString(stripAnsi bool) string

AsString returns the original string

func (*Item) Colors

func (item *Item) Colors() []ansiOffset

Colors returns ansiOffsets of the Item

func (*Item) Index

func (item *Item) Index() int32

Index returns ordinal index of the Item

func (*Item) TrimLength

func (item *Item) TrimLength() uint16

type ItemBuilder

type ItemBuilder func(*Item, []byte) bool

ItemBuilder is a closure type that builds Item object from byte array

type MatchRequest

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

MatchRequest represents a search request

type Matcher

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

Matcher is responsible for performing search

func NewMatcher

func NewMatcher(patternBuilder func([]rune) *Pattern,
	sort bool, tac bool, eventBox *util.EventBox) *Matcher

NewMatcher returns a new Matcher

func (*Matcher) Loop

func (m *Matcher) Loop()

Loop puts Matcher in action

func (*Matcher) Reset

func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool, clearCache bool)

Reset is called to interrupt/signal the ongoing search

type Merger

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

Merger holds a set of locally sorted lists of items and provides the view of a single, globally-sorted list

func NewMerger

func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool) *Merger

NewMerger returns a new Merger

func PassMerger

func PassMerger(chunks *[]*Chunk, tac bool) *Merger

PassMerger returns a new Merger that simply returns the items in the original order

func (*Merger) Get

func (mg *Merger) Get(idx int) Result

Get returns the pointer to the Result object indexed by the given integer

func (*Merger) Length

func (mg *Merger) Length() int

Length returns the number of items

type Offset

type Offset [2]int32

Offset holds two 32-bit integers denoting the offsets of a matched substring

type Options

type Options struct {
	Fuzzy       bool
	FuzzyAlgo   algo.Algo
	Extended    bool
	Phony       bool
	Case        Case
	Normalize   bool
	Nth         []Range
	WithNth     []Range
	Delimiter   Delimiter
	Sort        int
	Tac         bool
	Criteria    []criterion
	Multi       int
	Ansi        bool
	Mouse       bool
	Theme       *tui.ColorTheme
	Black       bool
	Bold        bool
	Height      sizeSpec
	MinHeight   int
	Layout      layoutType
	Cycle       bool
	KeepRight   bool
	Hscroll     bool
	HscrollOff  int
	FileWord    bool
	InfoStyle   infoStyle
	JumpLabels  string
	Prompt      string
	Pointer     string
	Marker      string
	Query       string
	Select1     bool
	Exit0       bool
	Filter      *string
	ToggleSort  bool
	Expect      map[tui.Event]string
	Keymap      map[tui.Event][]action
	Preview     previewOpts
	PrintQuery  bool
	ReadZero    bool
	Printer     func(string)
	PrintSep    string
	Sync        bool
	History     *History
	Header      []string
	HeaderLines int
	Margin      [4]sizeSpec
	Padding     [4]sizeSpec
	BorderShape tui.BorderShape
	Unicode     bool
	Tabstop     int
	ClearOnExit bool
	Version     bool
}

Options stores the values of command-line options

func ParseOptions

func ParseOptions() *Options

ParseOptions parses command-line options

type Pattern

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

Pattern represents search pattern

func BuildPattern

func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
	cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern

BuildPattern builds Pattern object from the given arguments

func (*Pattern) AsString

func (p *Pattern) AsString() string

AsString returns the search query in string type

func (*Pattern) CacheKey

func (p *Pattern) CacheKey() string

CacheKey is used to build string to be used as the key of result cache

func (*Pattern) IsEmpty

func (p *Pattern) IsEmpty() bool

IsEmpty returns true if the pattern is effectively empty

func (*Pattern) Match

func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []Result

Match returns the list of matches Items in the given Chunk

func (*Pattern) MatchItem

func (p *Pattern) MatchItem(item *Item, withPos bool, slab *util.Slab) (*Result, []Offset, *[]int)

MatchItem returns true if the Item is a match

type Range

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

Range represents nth-expression

func ParseRange

func ParseRange(str *string) (Range, bool)

ParseRange parses nth-expression and returns the corresponding Range object

type Reader

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

Reader reads from command or standard input

func NewReader

func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, delimNil bool, wait bool) *Reader

NewReader returns new Reader object

func (*Reader) ReadSource

func (r *Reader) ReadSource()

ReadSource reads data from the default command or from standard input

func (*Reader) ReadStrings

func (r *Reader) ReadStrings(strings []string)

type Result

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

func (*Result) Index

func (result *Result) Index() int32

Index returns ordinal index of the Item

type Terminal

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

Terminal represents terminal input/output

func NewTerminal

func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal

NewTerminal returns new Terminal object

func (*Terminal) Input

func (t *Terminal) Input() (bool, []rune)

Input returns current query string

func (*Terminal) Loop

func (t *Terminal) Loop()

Loop is called to start Terminal I/O

func (*Terminal) UpdateCount

func (t *Terminal) UpdateCount(cnt int, final bool, failedCommand *string)

UpdateCount updates the count information

func (*Terminal) UpdateHeader

func (t *Terminal) UpdateHeader(header []string)

UpdateHeader updates the header

func (*Terminal) UpdateList

func (t *Terminal) UpdateList(merger *Merger, reset bool)

UpdateList updates Merger to display the list

func (*Terminal) UpdateProgress

func (t *Terminal) UpdateProgress(progress float32)

UpdateProgress updates the search progress

type Token

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

Token contains the tokenized part of the strings and its prefix length

func Tokenize

func Tokenize(text string, delimiter Delimiter) []Token

Tokenize tokenizes the given string with the delimiter

func Transform

func Transform(tokens []Token, withNth []Range) []Token

Transform is used to transform the input when --with-nth option is given

func (Token) String

func (t Token) String() string

String returns the string representation of a Token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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