Documentation ¶
Index ¶
- Constants
- func IsTty(fd uintptr) bool
- func LocateRcfile() (string, error)
- func TtyReady() error
- func TtyTerm()
- type Action
- type ActionFunc
- type BufferReader
- type CaseSensitiveMatcher
- type Config
- type Ctx
- func (c *Ctx) AddMatcher(m Matcher) error
- func (c *Ctx) AddWaitGroup(v int)
- func (c *Ctx) Buffer() []Match
- func (c *Ctx) DrawMatches(m []Match)
- func (c *Ctx) ExecQuery() bool
- func (c *Ctx) ExitWith(i int)
- func (c *Ctx) IsBufferOverflowing() bool
- func (c *Ctx) IsRangeMode() bool
- func (c *Ctx) LoadCustomMatcher() error
- func (c *Ctx) Matcher() Matcher
- func (c *Ctx) NewBufferReader(r io.ReadCloser) *BufferReader
- func (c *Ctx) NewFilter() *Filter
- func (c *Ctx) NewInput() *Input
- func (c *Ctx) NewSignalHandler() *SignalHandler
- func (c *Ctx) NewView() *View
- func (c *Ctx) ReadConfig(file string) error
- func (c *Ctx) Refresh()
- func (c *Ctx) ReleaseWaitGroup()
- func (c *Ctx) Result() []Match
- func (c *Ctx) SelectedRange() Selection
- func (c *Ctx) SetCurrentMatcher(n string) bool
- func (c *Ctx) SetPrompt(p []rune)
- func (c *Ctx) SetQuery(q []rune)
- func (c *Ctx) WaitDone()
- type CtxOptions
- type CustomMatcher
- type DidMatch
- type Filter
- type Hub
- func (h *Hub) Batch(f func())
- func (h *Hub) ClearStatusCh() chan HubReq
- func (h *Hub) DrawCh() chan HubReq
- func (h *Hub) LoopCh() chan struct{}
- func (h *Hub) PagingCh() chan HubReq
- func (h *Hub) QueryCh() chan HubReq
- func (h *Hub) SendClearStatus(d time.Duration)
- func (h *Hub) SendDraw(matches []Match)
- func (h *Hub) SendPaging(x PagingRequest)
- func (h *Hub) SendQuery(q string)
- func (h *Hub) SendStatusMsg(q string)
- func (h *Hub) StatusMsgCh() chan HubReq
- func (h *Hub) Stop()
- type HubReq
- type IgnoreCaseMatcher
- type Input
- type Keymap
- type Match
- type Matcher
- type NoMatch
- type PageInfo
- type PagingRequest
- type RegexpMatcher
- type Selection
- type SignalHandler
- type Style
- type StyleSet
- type View
Constants ¶
const ( IgnoreCaseMatch = "IgnoreCase" CaseSensitiveMatch = "CaseSensitive" RegexpMatch = "Regexp" )
These are used as keys in the config file
const NoSelectionRange = -1
Variables ¶
This section is empty.
Functions ¶
func LocateRcfile ¶ added in v0.1.3
LocateRcfile attempts to find the config file in various locations
Types ¶
type Action ¶ added in v0.2.0
type Action interface { Register(string, ...termbox.Key) RegisterKeySequence(keyseq.KeyList) Execute(*Input, termbox.Event) }
Action describes an action that can be executed upon receiving user input. It's an interface so you can create any kind of Action you need, but most everything is implemented in terms of ActionFunc, which is callback based Action
type ActionFunc ¶ added in v0.2.0
type ActionFunc func(*Input, termbox.Event)
ActionFunc is a type of Action that is basically just a callback.
func (ActionFunc) Execute ¶ added in v0.2.0
func (a ActionFunc) Execute(i *Input, e termbox.Event)
Execute fulfills the Action interface for AfterFunc
func (ActionFunc) Register ¶ added in v0.2.0
func (a ActionFunc) Register(name string, defaultKeys ...termbox.Key)
Register fulfills the Actin interface for AfterFunc. Registers `a` into the global action registry by the name `name`, and maps to default keys via `defaultKeys`
func (ActionFunc) RegisterKeySequence ¶ added in v0.2.0
func (a ActionFunc) RegisterKeySequence(k keyseq.KeyList)
RegisterKeySequence satisfies the Action interface for AfterFun. Registers the action to be mapped against a key sequence
type BufferReader ¶ added in v0.1.12
type BufferReader struct { *Ctx // contains filtered or unexported fields }
BufferReader reads lines from the input, either Stdin or a file. If the incoming data is endless, it keeps reading and adding to the search buffer, as long as it can.
If you would like to limit the number of lines to keep in the buffer, you should set --buffer-size to a number > 0
func (*BufferReader) InputReadyCh ¶ added in v0.2.0
func (b *BufferReader) InputReadyCh() <-chan struct{}
InputReadyCh returns a channel which, when the input starts coming in, sends a struct{}{}
func (*BufferReader) Loop ¶ added in v0.1.12
func (b *BufferReader) Loop()
Loop keeps reading from the input
type CaseSensitiveMatcher ¶ added in v0.1.1
type CaseSensitiveMatcher struct {
*RegexpMatcher
}
CaseSensitiveMatcher extends the RegxpMatcher, but always turns off the ignore-case flag in the regexp
func NewCaseSensitiveMatcher ¶ added in v0.1.2
func NewCaseSensitiveMatcher(enableSep bool) *CaseSensitiveMatcher
NewCaseSensitiveMatcher creates a new CaseSensitiveMatcher
func (*CaseSensitiveMatcher) String ¶ added in v0.1.1
func (m *CaseSensitiveMatcher) String() string
type Config ¶
type Config struct { Action map[string][]string `json:"Action"` // Keymap used to be directly responsible for dispatching // events against user input, but since then this has changed // into something that just records the user's config input Keymap map[string]string `json:"Keymap"` Matcher string `json:"Matcher"` Style StyleSet `json:"Style"` CustomMatcher map[string][]string Prompt string `json:"Prompt"` }
Config holds all the data that can be configured in the external configuran file
func (*Config) ReadFilename ¶
ReadFilename reads the config from the given file, and does the appropriate processing, if any
type Ctx ¶
type Ctx struct { *Hub Matchers []Matcher CurrentMatcher int ExitStatus int // contains filtered or unexported fields }
Ctx contains all the important data. while you can easily access data in this struct from anwyehre, only do so via channels
func NewCtx ¶
func NewCtx(o CtxOptions) *Ctx
func (*Ctx) AddMatcher ¶ added in v0.1.2
func (*Ctx) AddWaitGroup ¶
func (*Ctx) DrawMatches ¶
func (*Ctx) IsBufferOverflowing ¶ added in v0.2.0
func (*Ctx) IsRangeMode ¶ added in v0.2.0
func (*Ctx) LoadCustomMatcher ¶ added in v0.1.3
func (*Ctx) NewBufferReader ¶ added in v0.1.12
func (c *Ctx) NewBufferReader(r io.ReadCloser) *BufferReader
func (*Ctx) NewSignalHandler ¶ added in v0.2.0
func (c *Ctx) NewSignalHandler() *SignalHandler
func (*Ctx) ReadConfig ¶
func (*Ctx) ReleaseWaitGroup ¶
func (c *Ctx) ReleaseWaitGroup()
func (*Ctx) SelectedRange ¶ added in v0.2.0
func (*Ctx) SetCurrentMatcher ¶ added in v0.1.2
type CtxOptions ¶ added in v0.2.0
type CustomMatcher ¶ added in v0.1.3
type CustomMatcher struct {
// contains filtered or unexported fields
}
CustomMatcher spawns a new process to filter the buffer in peco, and uses the output in its Stdout to figure out what to display
func NewCustomMatcher ¶ added in v0.1.3
func NewCustomMatcher(enableSep bool, name string, args []string) *CustomMatcher
NewCustomMatcher creates a new CustomMatcher
func (*CustomMatcher) Match ¶ added in v0.1.3
func (m *CustomMatcher) Match(quit chan struct{}, q string, buffer []Match) []Match
Match matches `q` aginst `buffer`
func (*CustomMatcher) String ¶ added in v0.1.3
func (m *CustomMatcher) String() string
func (*CustomMatcher) Verify ¶ added in v0.1.11
func (m *CustomMatcher) Verify() error
Verify checks to see that the executable given to CustomMatcher is actual found and is executable via exec.LookPath
type DidMatch ¶ added in v0.1.3
type DidMatch struct {
// contains filtered or unexported fields
}
DidMatch contains the actual match, and the indices to the matches in the line
func NewDidMatch ¶ added in v0.1.5
NewDidMatch creates a new DidMatch struct
type Filter ¶
type Filter struct { *Ctx // contains filtered or unexported fields }
Filter is responsible for the actual "grep" part of peco
type Hub ¶ added in v0.2.1
type Hub struct {
// contains filtered or unexported fields
}
Hub acts as the messaging hub between components -- that is, it controls how the communication that goes through channels are handled.
func (*Hub) Batch ¶ added in v0.2.1
func (h *Hub) Batch(f func())
Batch allows you to synchronously send messages during the scope of f() being executed.
func (*Hub) ClearStatusCh ¶ added in v0.2.1
func (*Hub) LoopCh ¶ added in v0.2.1
func (h *Hub) LoopCh() chan struct{}
LoopCh returns the channel to control the main execution loop. Nothing should ever be sent through this channel. The only way the channel communicates anything to its receivers is when it is closed -- which is when peco is done.
func (*Hub) SendClearStatus ¶ added in v0.2.1
SendClearStatus sends a request to clear the status message in `d` duration. If a new status message is sent before the clear request is executed, the clear instruction will be canceled
func (*Hub) SendPaging ¶ added in v0.2.1
func (h *Hub) SendPaging(x PagingRequest)
SendPaging sends a request to move the cursor around
func (*Hub) SendQuery ¶ added in v0.2.1
SendQuery sends the query string to be processed by the Filter
func (*Hub) SendStatusMsg ¶ added in v0.2.1
SendStatusMsg sends a string to be displayed in the status message
func (*Hub) StatusMsgCh ¶ added in v0.2.1
StatusMsgCh returns the channel to update the status message
type HubReq ¶ added in v0.2.1
type HubReq struct {
// contains filtered or unexported fields
}
HubReq is a wrapper around the actual requst value that needs to be passed. It contains an optional channel field which can be filled to force synchronous communication between the sender and receiver
func (HubReq) DataInterface ¶ added in v0.2.1
func (hr HubReq) DataInterface() interface{}
DataInterface returns the underlying data as interface{}
func (HubReq) DataString ¶ added in v0.2.1
DataString returns the underlying data as a string. Panics if type conversion fails.
type IgnoreCaseMatcher ¶ added in v0.1.1
type IgnoreCaseMatcher struct {
*RegexpMatcher
}
IgnoreCaseMatcher extends the RegexpMatcher, and always turns ON the ignore-case flag in the regexp
func NewIgnoreCaseMatcher ¶ added in v0.1.2
func NewIgnoreCaseMatcher(enableSep bool) *IgnoreCaseMatcher
NewIgnoreCaseMatcher creates a new IgnoreCaseMatcher
func (*IgnoreCaseMatcher) String ¶ added in v0.1.1
func (m *IgnoreCaseMatcher) String() string
type Input ¶
type Input struct { *Ctx // contains filtered or unexported fields }
Input handles input events from termbox.
type Keymap ¶
type Keymap struct { Config map[string]string Action map[string][]string // custom actions Keyseq *keyseq.Keyseq }
Keymap holds all the key sequence to action map
func (Keymap) ApplyKeybinding ¶ added in v0.2.0
func (km Keymap) ApplyKeybinding()
ApplyKeybinding applies all of the custom key bindings on top of the default key bindings
type Match ¶
type Match interface { Buffer() string // Raw buffer, may contain null Line() string // Line to be displayed Output() string // Output string to be displayed after peco is done Indices() [][]int }
Match defines the interface for matches. Note that to make drawing easier, we have a DidMatch and NoMatch types instead of using []Match and []string.
type Matcher ¶ added in v0.1.1
type Matcher interface { // Match takes in three parameters. // // The first chan is the channel where cancel requests are sent. // If you receive a request here, you should stop running your query. // // The second is the query. Do what you want with it // // The third is the buffer in which to match the query against. Match(chan struct{}, string, []Match) []Match String() string // This is fugly. We just added a method only for CustomMatcner. // Must think about this again Verify() error }
Matcher interface defines the API for things that want to match against the buffer
type NoMatch ¶ added in v0.1.3
type NoMatch struct {
// contains filtered or unexported fields
}
NoMatch is actually an alias to a regular string. It implements the Match interface, but just returns the underlying string with no matches
func NewNoMatch ¶ added in v0.1.5
NewNoMatch creates a NoMatch struct
type PagingRequest ¶
type PagingRequest int
PagingRequest can be sent to move the selection cursor
const ( // ToNextLine moves the selection to the next line ToNextLine PagingRequest = iota // ToNextPage moves the selection to the next page ToNextPage // ToPrevLine moves the selection to the previous line ToPrevLine // ToPrevPage moves the selection to the previous page ToPrevPage )
type RegexpMatcher ¶ added in v0.1.2
type RegexpMatcher struct {
// contains filtered or unexported fields
}
RegexpMatcher is the most basic matcher
func NewRegexpMatcher ¶ added in v0.1.2
func NewRegexpMatcher(enableSep bool) *RegexpMatcher
NewRegexpMatcher creates a new RegexpMatcher
func (*RegexpMatcher) Match ¶ added in v0.1.2
func (m *RegexpMatcher) Match(quit chan struct{}, q string, buffer []Match) []Match
Match does the heavy lifting, and matches `q` against `buffer`. While it is doing the match, it also listens for messages via `quit`. If anything is received via `quit`, the match is halted.
func (*RegexpMatcher) MatchAllRegexps ¶ added in v0.1.2
func (m *RegexpMatcher) MatchAllRegexps(regexps []*regexp.Regexp, line string) [][]int
MatchAllRegexps matches all the regexps in `regexps` against line
func (*RegexpMatcher) String ¶ added in v0.1.2
func (m *RegexpMatcher) String() string
func (*RegexpMatcher) Verify ¶ added in v0.1.11
func (m *RegexpMatcher) Verify() error
Verify always returns nil
type Selection ¶ added in v0.1.3
type Selection []int
Selection stores the line numbers that were selected by the user. The contents of the Selection is always sorted from smallest to largest line number
func (*Selection) Add ¶ added in v0.1.3
Add adds a new line number to the selection. If the line already exists in the selection, it is silently ignored
func (Selection) Len ¶ added in v0.1.3
Len returns the number of elements in the selection. Satisfies sort.Interface
func (Selection) Less ¶ added in v0.1.3
Less returns true if element at index i is less than the element at index j. Satisfies sort.Interface
type SignalHandler ¶ added in v0.2.0
type SignalHandler struct { *Ctx // contains filtered or unexported fields }
func (*SignalHandler) Loop ¶ added in v0.2.0
func (s *SignalHandler) Loop()
type Style ¶ added in v0.1.2
type Style struct {
// contains filtered or unexported fields
}
Style describes termbox styles
func (*Style) UnmarshalJSON ¶ added in v0.1.2
UnmarshalJSON satisfies json.RawMessage.
type StyleSet ¶ added in v0.1.2
type StyleSet struct { Basic Style `json:"Basic"` SavedSelection Style `json:"SavedSelection"` Selected Style `json:"Selected"` Query Style `json:"Query"` Matched Style `json:"Matched"` }
StyleSet holds styles for various sections
func NewStyleSet ¶ added in v0.1.2
func NewStyleSet() StyleSet
NewStyleSet creates a new StyleSet struct