Documentation ¶
Index ¶
- Constants
- func IsTty(fd uintptr) bool
- func IsValidLayoutType(v LayoutType) bool
- func IsValidVerticalAnchor(anchor VerticalAnchor) bool
- func LocateRcfile() (string, error)
- func TtyReady() error
- func TtyTerm()
- type Action
- type ActionFunc
- type AnchorSettings
- type BasicLayout
- type BufferReader
- type CaretPosition
- 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) ExitStatus() int
- 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) RotateMatcher()
- func (c *Ctx) SelectedRange() Selection
- func (c *Ctx) SetCurrentMatcher(n string) bool
- func (c *Ctx) SetPrompt(p string)
- func (c *Ctx) SetQuery(q []rune)
- func (c *Ctx) WaitDone()
- type CtxOptions
- type CustomMatcher
- type DidMatch
- type Filter
- type FilterQuery
- 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 Layout
- type LayoutType
- type ListArea
- type Match
- type Matcher
- type NoMatch
- type PageInfo
- type PagingRequest
- type RegexpMatcher
- type Screen
- type Selection
- type StatusBar
- type Style
- type StyleSet
- func (s StyleSet) BasicBG() termbox.Attribute
- func (s StyleSet) BasicFG() termbox.Attribute
- func (s StyleSet) MatchedBG() termbox.Attribute
- func (s StyleSet) MatchedFG() termbox.Attribute
- func (s StyleSet) QueryBG() termbox.Attribute
- func (s StyleSet) QueryFG() termbox.Attribute
- func (s StyleSet) SavedSelectionBG() termbox.Attribute
- func (s StyleSet) SavedSelectionFG() termbox.Attribute
- func (s StyleSet) SelectedBG() termbox.Attribute
- func (s StyleSet) SelectedFG() termbox.Attribute
- type Termbox
- type UserPrompt
- type VerticalAnchor
- type View
Constants ¶
const ( // LayoutTypeTopDown is the default. All the items read from top to bottom LayoutTypeTopDown = "top-down" // LayoutTypeBottomUp changes the layout to read from bottom to up LayoutTypeBottomUp = "bottom-up" )
const ( IgnoreCaseMatch = "IgnoreCase" CaseSensitiveMatch = "CaseSensitive" RegexpMatch = "Regexp" )
These are used as keys in the config file
Variables ¶
This section is empty.
Functions ¶
func IsValidLayoutType ¶ added in v0.2.5
func IsValidLayoutType(v LayoutType) bool
IsValidLayoutType checks if a string is a supported layout type
func IsValidVerticalAnchor ¶ added in v0.2.6
func IsValidVerticalAnchor(anchor VerticalAnchor) bool
IsValidVerticalAnchor checks if the specified anchor is supported
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 AnchorSettings ¶ added in v0.2.5
type AnchorSettings struct {
// contains filtered or unexported fields
}
AnchorSettings groups items that are required to control where an anchored item is actually placed
func NewAnchorSettings ¶ added in v0.2.6
func NewAnchorSettings(anchor VerticalAnchor, offset int) *AnchorSettings
NewAnchorSettings creates a new AnchorSetting struct. Panics if an unknown VerticalAnchor is sent
func (AnchorSettings) AnchorPosition ¶ added in v0.2.5
func (as AnchorSettings) AnchorPosition() int
AnchorPosition returns the starting y-offset, based on the anchor type and offset
type BasicLayout ¶ added in v0.2.5
BasicLayout is... the basic layout :) At this point this is the only struct for layouts, which means that while the position of components may be configurable, the actual types of components that are used are set and static
func NewBottomUpLayout ¶ added in v0.2.5
func NewBottomUpLayout(ctx *Ctx) *BasicLayout
NewBottomUpLayout creates a new Layout in bottom-up format
func NewDefaultLayout ¶ added in v0.2.5
func NewDefaultLayout(ctx *Ctx) *BasicLayout
NewDefaultLayout creates a new Layout in the default format (top-down)
func (*BasicLayout) CalculatePage ¶ added in v0.2.5
func (l *BasicLayout) CalculatePage(targets []Match, perPage int) error
CalculatePage calculates which page we're displaying
func (*BasicLayout) DrawScreen ¶ added in v0.2.5
func (l *BasicLayout) DrawScreen(targets []Match)
DrawScreen draws the entire screen
func (*BasicLayout) MovePage ¶ added in v0.2.5
func (l *BasicLayout) MovePage(p PagingRequest)
MovePage moves the cursor
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 CaretPosition ¶ added in v0.2.6
type CaretPosition int
func (CaretPosition) CaretPos ¶ added in v0.2.6
func (p CaretPosition) CaretPos() CaretPosition
func (CaretPosition) Int ¶ added in v0.2.6
func (p CaretPosition) Int() int
func (*CaretPosition) MoveCaretPos ¶ added in v0.2.6
func (p *CaretPosition) MoveCaretPos(offset int)
func (*CaretPosition) SetCaretPos ¶ added in v0.2.6
func (p *CaretPosition) SetCaretPos(where int)
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"` // Deprecated. InitialMatcher string `json:"InitialMatcher"` // Use this instead of Matcher Style *StyleSet `json:"Style"` Prompt string `json:"Prompt"` Layout string `json:"Layout"` CustomMatcher map[string][]string }
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 CaretPosition FilterQuery Matchers []Matcher // 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) ExitStatus ¶
ExitStatus() returns the exit status that we think should be used
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) RotateMatcher ¶ added in v0.2.6
func (c *Ctx) RotateMatcher()
RotateMatcher rotates the matchers
func (*Ctx) SelectedRange ¶ added in v0.2.0
func (*Ctx) SetCurrentMatcher ¶ added in v0.1.2
type CtxOptions ¶ added in v0.2.0
type CtxOptions interface { // EnableNullSep should return if the null separator is // enabled (--null) EnableNullSep() bool // BufferSize should return the buffer size. By default (i.e. // when it returns 0), the buffer size is unlimited. // (--buffer-size) BufferSize() int // InitialIndex is the line number to put the cursor on // when peco starts InitialIndex() int // LayoutType returns the name of the layout to use LayoutType() string }
CtxOptions is the interface that defines that options can be passed in from the command line
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 FilterQuery ¶ added in v0.2.6
type FilterQuery []rune
func (*FilterQuery) AppendQuery ¶ added in v0.2.6
func (q *FilterQuery) AppendQuery(r rune)
func (*FilterQuery) InsertQueryAt ¶ added in v0.2.6
func (q *FilterQuery) InsertQueryAt(ch rune, where int)
func (FilterQuery) Query ¶ added in v0.2.6
func (q FilterQuery) Query() FilterQuery
func (FilterQuery) QueryLen ¶ added in v0.2.6
func (q FilterQuery) QueryLen() int
func (FilterQuery) String ¶ added in v0.2.6
func (q FilterQuery) String() string
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 Layout ¶ added in v0.2.5
type Layout interface { ClearStatus(time.Duration) PrintStatus(string) DrawScreen([]Match) MovePage(PagingRequest) }
Layout represents the component that controls where elements are placed on screen
type LayoutType ¶ added in v0.2.5
type LayoutType string
LayoutType describes the types of layout that peco can take
type ListArea ¶ added in v0.2.5
type ListArea struct { *Ctx *AnchorSettings // contains filtered or unexported fields }
ListArea represents the area where the actual line buffer is displayed in the screen
func NewListArea ¶ added in v0.2.5
func NewListArea(ctx *Ctx, anchor VerticalAnchor, anchorOffset int, sortTopDown bool) *ListArea
NewListArea creates a new ListArea struct
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 ( // ToLineAbove moves the selection to the line above ToLineAbove PagingRequest = iota // ToScrollPageDown moves the selection to the next page ToScrollPageDown // ToLineBelow moves the selection to the line below ToLineBelow // ToScrollPageUp moves the selection to the previous page ToScrollPageUp )
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 Screen ¶ added in v0.2.6
type Screen interface { Clear(termbox.Attribute, termbox.Attribute) error Flush() error PollEvent() chan termbox.Event SetCell(int, int, rune, termbox.Attribute, termbox.Attribute) Size() (int, int) }
Screen hides termbox from tne consuming code so that it can be swapped out for testing
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 StatusBar ¶ added in v0.2.5
type StatusBar struct { *Ctx *AnchorSettings // contains filtered or unexported fields }
StatusBar draws the status message bar
func NewStatusBar ¶ added in v0.2.5
func NewStatusBar(ctx *Ctx, anchor VerticalAnchor, anchorOffset int) *StatusBar
NewStatusBar creates a new StatusBar struct
func (*StatusBar) ClearStatus ¶ added in v0.2.5
ClearStatus clears the string displayed in the status bar area after `d time.Duration`.
func (*StatusBar) PrintStatus ¶ added in v0.2.5
PrintStatus prints a new status message. This also resets the timer created by ClearStatus()
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
func (StyleSet) SavedSelectionBG ¶ added in v0.2.5
func (s StyleSet) SavedSelectionBG() termbox.Attribute
func (StyleSet) SavedSelectionFG ¶ added in v0.2.5
func (s StyleSet) SavedSelectionFG() termbox.Attribute
func (StyleSet) SelectedBG ¶ added in v0.2.5
func (s StyleSet) SelectedBG() termbox.Attribute
func (StyleSet) SelectedFG ¶ added in v0.2.5
func (s StyleSet) SelectedFG() termbox.Attribute
type Termbox ¶ added in v0.2.6
type Termbox struct{}
Termbox just hands out the processing to the termbox library
type UserPrompt ¶ added in v0.2.5
type UserPrompt struct { *Ctx *AnchorSettings // contains filtered or unexported fields }
UserPrompt draws the prompt line
func NewUserPrompt ¶ added in v0.2.5
func NewUserPrompt(ctx *Ctx, anchor VerticalAnchor, anchorOffset int) *UserPrompt
NewUserPrompt creates a new UserPrompt struct
type VerticalAnchor ¶ added in v0.2.5
type VerticalAnchor int
VerticalAnchor describes the direction to which elements in the layout are anchored to
const ( // AnchorTop anchors elements towards the top of the screen AnchorTop VerticalAnchor = iota + 1 // AnchorBottom anchors elements towards the bottom of the screen AnchorBottom )