peco

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2015 License: MIT Imports: 26 Imported by: 0

README

peco

Simplistic interactive filtering tool

Description

peco (pronounced peh-koh) is based on a python tool, percol. percol was darn useful, but I wanted a tool that was a single binary, and forget about python. peco is written in Go, and therefore you can just grab the binary releases and drop it in your $PATH.

peco can be a great tool to filter stuff like logs, process stats, find files, because unlike grep, you can type as you think and look through the current results.

For basic usage, continue down below. For more cool elaborate usage samples, please see the wiki, and if you have any other tricks you want to share, please add to it!

Demo

Demos speak more than a thousand words! Here's me looking for a process on my mac. As you can see, you can page through your results, and you can keep changing the query:

optimized

Here's me trying to figure out which file to open:

optimized

When you combine tools like zsh, peco, and ghq, you can make managing/moving around your huge dev area a piece of cake! (this example doesn't use zsh functions so you can see what I'm doing)

optimized

Features

Search results are filtered as you type. This is great to drill down to the line you are looking for

Multiple terms turn the query into an "AND" query:

optimized

When you find that line that you want, press enter, and the resulting line is printed to stdout, which allows you to pipe it to other tools

Select Multiple Lines

You can select multiple lines!

optimized

Select Range Of Lines

Not only can you select multiple lines one by one, you can select a range of lines (Note: The ToggleRangeMode action is not enabled by default. You need to put a custom key binding in your config file)

optimized

Select Filters

Different types of filters are available. Default is case-insensitive filter, so lines with any case will match. You can toggle between IgnoreCase, CaseSensitive, SmartCase and RegExp filters.

The SmartCase filter uses case-insensitive matching when all of the queries are lower case, and case-sensitive matching otherwise.

The RegExp filter allows you to use any valid regular expression to match lines

optimized

Selectable Layout

As of v0.2.5, if you would rather not move your eyes off of the bottom of the screen, you can change the screen layout by either providing the --layout=bottom-up command line option, or set the Layout variable in your configuration file

optmized

Works on Windows!

I have been told that peco even works on windows :) Look ma! I'm not lying!

optimized

Installation

Just want the binary?

Go to the releases page, find the version you want, and download the zip file. Unpack the zip file, and put the binary to somewhere you want (on UNIX-y systems, /usr/local/bin or the like). Make sure it has execution bits turned on. Yes, it is a single binary! You can put it anywhere you want :)

THIS IS THE RECOMMENDED WAY (except for OS X homebrew users)

Mac OS X / Homebrew

If you're on OS X and want to use homebrew:

brew install peco

The above homebrew formula is maintained by the folks working on Homebrew. There is a custom tap maintained by the authors of peco, just in case something goes wrong in the homebrew formula. In general you DO NOT need to use this custom tap:

brew tap peco/peco
brew install peco
Windows (Chocolatey NuGet Users)

There's a third-party peco package available for Chocolatey NuGet.

C:\> choco install peco
go get

If you want to go the Go way (install in GOPATH/bin) and just want the command:

go get github.com/peco/peco/cmd/peco

Command Line Options

-h, --help

Display a help message

--version

Display the version of peco

--query

Specifies the default query to be used upon startup. This is useful for scripts and functions where you can figure out before hand what the most likely query string is.

--rcfile

Pass peco a configuration file, which currently must be a JSON file. If unspecified it will try a series of files by default. See Configuration File for the actual locations searched.

-b, --buffer-size

Limits the buffer size to num. This is an important feature when you are using peco against a possibly infinite stream, as it limits the number of lines that peco holds at any given time, preventing it from exhausting all the memory. By default the buffer size is unlimited.

--null

WARNING: EXPERIMENTAL. This feature will probably stay, but the option name may change in the future.

Changes how peco interprets incoming data. When this flag is set, you may insert NUL ('\0') characters in your input. Anything before the NUL character is treated as the string to be displayed by peco and is used for matching against user query. Anything after the NUL character is used as the "result": i.e., when peco is about to exit, it displays this string instead of the original string displayed.

Here's a simple example of how to use this feature

--initial-index

Specifies the initial line position upon start up. E.g. If you want to start out with the second line selected, set it to "1" (because the index is 0 based)

--initial-filter IgnoreCase|CaseSensitive|SmartCase|Regexp

Specifies the initial filter to use upon start up. You should specify the name of the filter like IgnoreCase, CaseSensitive, SmartCase and Regexp. Default is IgnoreCase.

--prompt

Specifies the query line's prompt string. When specified, takes precedence over the configuration file's Prompt section. The default value is QUERY>

--layout top-down|bottom-up

Specifies the display layout. Default is top-down, where query prompt is at the top, followed by the list, then the system status message line. bottom-up changes this to the list first (displayed in reverse order), the query prompt, and then the system status message line.

For percol users, --layout=bottom-up is almost equivalent of --prompt-bottom --result-bottom-up.

--select-1

When specified and the input contains exactly 1 line, peco skips prompting you for a choice, and selects the only line in the input and immediately exits.

If there are multiple lines in the input, the usual selection view is displayed.

Configuration File

peco by default consults a few locations for the config files.

  1. Location specified in --rcfile. If this doesn't exist, peco complains and exits
  2. $XDG_CONFIG_HOME/peco/config.json
  3. $HOME/.config/peco/config.json
  4. for each directories listed in $XDG_CONFIG_DIRS, $DIR/peco/config.json
  5. If all else fails, $HOME/.peco/config.json

Below are configuration sections that you may specify in your config file:

Global

Global configurations that change the global behavior.

Prompt

You can change the query line's prompt, which is QUERY> by default.

{
    "Prompt": "[peco]"
}
InitialMatcher

InitialMatcher has been deprecated. Please use InitialFilter instead.

InitialFilter

Specifies the filter name to start peco with. You should specify the name of the filter, such as IgnoreCase, CaseSensitive, SmartCase and Regexp

StickySelection
{
    "StickySelection": true
}

StickySelection allows selections to persist even between changes to the query. For example, when you set this to true you can select a few lines, type in a new query, select those lines, and then delete the query. The result is all the lines that you selected before and after the modification to the query are left in tact.

Default value for StickySelection is false.

Keymaps

Example:

{
    "Keymap": {
        "M-v": "peco.ScrollPageUp",
        "C-v": "peco.ScrollPageDown",
        "C-x,C-c": "peco.Cancel"
    }
}
Key sequences

As of v0.2.0, you can use a list of keys (separated by comma) to register an action that is associated with a key sequence (instead of a single key). Please note that if there is a conflict in the key map, the longest sequence always wins. So In the above example, if you add another sequence, say, C-x,C-c,C-c, then the above peco.Cancel will never be invoked.

Combined actions

As of v0.2.1, you can create custom combined actions. For example, if you find yourself repeatedly needing to select 4 lines out of the list, you may want to define your own action like this:

{
    "Action": {
        "foo.SelectFour": [
            "peco.ToggleRangeMode",
            "peco.SelectDown",
            "peco.SelectDown",
            "peco.SelectDown",
            "peco.ToggleRangeMode"
        ]
    },
    "Keymap": {
        "M-f": "foo.SelectFour"
    }
}

This creates a new combined action foo.SelectFour (the format of the name is totally arbitrary, I just like to put namespaces), and assigns that action to M-f. When it's fired, it toggles the range selection mode and highlights 4 lines, and then goes back to waiting for your input.

As a similar example, a common idiom in emacs is that C-c C-c means "take the contents of this buffer and accept it", whatever that means. This adds exactly that keybinding:

{
    "Action": {
        "selectAllAndFinish": [
            "peco.SelectAll",
            "peco.Finish"
        ]
    },
    "Keymap": {
        "C-c,C-c": "selectAllAndFinish"
    }
}
Available keys

Since v0.1.8, in addition to values below, you may put a M- prefix on any key item to use Alt/Option key as a mask.

Name Notes
C-a ... C-z Control + whatever character
C-2 ... C-8 Control + 2..8
C-[
C-]
C-~
C-_
C-\\ Note that you need to escape the backslash
C-/
C-Space
F1 ... F12
Esc
Tab
Enter
Insert
Delete
BS
BS2
Home
End
Pgup
Pgdn
ArrowUp
ArrowDown
ArrowLeft
ArrowRight
MouseLeft
MouseMiddle
MouseRight
Key workarounds

Some keys just... don't map correctly / too easily for various reasons. Here, we'll list possible workarounds for key sequences that are often asked for:

You want this Use this instead Notes
Shift+Tab M-[,Z Verified on OS X
Available actions
Name Notes
peco.ForwardChar Move caret forward 1 character
peco.BackwardChar Move caret backward 1 character
peco.ForwardWord Move caret forward 1 word
peco.BackwardWord Move caret backward 1 word
peco.BackToInitialFilter Switch to first filter in the list
peco.BeginningOfLine Move caret to the beginning of line
peco.EndOfLine Move caret to the end of line
peco.EndOfFile Delete one character forward, otherwise exit from peco with failure status
peco.DeleteForwardChar Delete one character forward
peco.DeleteBackwardChar Delete one character backward
peco.DeleteForwardWord Delete one word forward
peco.DeleteBackwardWord Delete one word backward
peco.InvertSelection Inverts the selected lines
peco.KillBeginningOfLine Delete the characters under the cursor backward until the beginning of the line
peco.KillEndOfLine Delete the characters under the cursor until the end of the line
peco.DeleteAll Delete all entered characters
peco.RefreshScreen Redraws the screen. Note that this effectively re-runs your query
peco.SelectPreviousPage (DEPRECATED) Alias to ScrollPageUp
peco.SelectNextPage (DEPRECATED) Alias to ScrollPageDown
peco.ScrollPageDown Moves the selected line cursor for an entire page, downwards
peco.ScrollPageUp Moves the selected line cursor for an entire page, upwards
peco.SelectUp Moves the selected line cursor to one line above
peco.SelectDown Moves the selected line cursor to one line below
peco.SelectPrevious (DEPRECATED) Alias to SelectUp
peco.SelectNext (DEPRECATED) Alias to SelectDown
peco.ScrollLeft Scrolls the screen to the left
peco.ScrollRight Scrolls the screen to the right
peco.ToggleSelection Selects the current line, and saves it
peco.ToggleSelectionAndSelectNext Selects the current line, saves it, and proceeds to the next line
peco.ToggleSingleKeyJump Enables SingleKeyJump mode a.k.a. "hit-a-hint"
peco.SelectNone Remove all saved selections
peco.SelectAll Selects the all line, and save it
peco.SelectVisible Selects the all visible line, and save it
peco.ToggleSelectMode (DEPRECATED) Alias to ToggleRangeMode
peco.CancelSelectMode (DEPRECATED) Alias to CancelRangeMode
peco.ToggleQuery Toggle list between filterd by query and not filterd.
peco.ToggleRangeMode Start selecting by range, or append selecting range to selections
peco.CancelRangeMode Finish selecting by range and cancel range selection
peco.RotateMatcher (DEPRECATED) Use peco.RotateFilter
peco.RotateFilter Rotate between filters (by default, ignore-case/no-ignore-case)
peco.Finish Exits from peco with success status
peco.Cancel Exits from peco with failure status, or cancel select mode
Default Keymap

Note: If in case below keymap seems wrong, check the source code in keymap.go (look for NewKeymap).

Key Action
Esc peco.Cancel
C-c peco.Cancel
Enter peco.Finish
C-f peco.ForwardChar
C-a peco.BeginningOfLine
C-b peco.BackwardChar
C-d peco.DeleteForwardChar
C-e peco.EndOfLine
C-k peco.KillEndOfLine
C-u peco.KillBeginningOfLine
BS peco.DeleteBackwardChar
C-8 peco.DeleteBackwardChar
C-w peco.DeleteBackwardWord
C-g peco.SelectNone
C-n peco.SelectDown
C-p peco.SelectUp
C-r peco.RotateMatcher
C-t peco.ToggleQuery
C-Space peco.ToggleSelectionAndSelectNext
ArrowUp peco.SelectUp
ArrowDown peco.SelectDown
ArrowLeft peco.ScrollPageUp
ArrowRight peco.ScrollPageDown

Styles

For now, styles of following 5 items can be customized in config.json.

{
    "Style": {
        "Basic": ["on_default", "default"],
        "SavedSelection": ["bold", "on_yellow", "white"],
        "Selected": ["underline", "on_cyan", "black"],
        "Query": ["yellow", "bold"],
        "Matched": ["red", "on_blue"]
    }
}
  • Basic for not selected lines
  • SavedSelection for lines of saved selection
  • Selected for a currently selecting line
  • Query for a query line
  • Matched for a query matched word
Foreground Colors
  • "black" for termbox.ColorBlack
  • "red" for termbox.ColorRed
  • "green" for termbox.ColorGreen
  • "yellow" for termbox.ColorYellow
  • "blue" for termbox.ColorBlue
  • "magenta" for termbox.ColorMagenta
  • "cyan" for termbox.ColorCyan
  • "white" for termbox.ColorWhite
Background Colors
  • "on_black" for termbox.ColorBlack
  • "on_red" for termbox.ColorRed
  • "on_green" for termbox.ColorGreen
  • "on_yellow" for termbox.ColorYellow
  • "on_blue" for termbox.ColorBlue
  • "on_magenta" for termbox.ColorMagenta
  • "on_cyan" for termbox.ColorCyan
  • "on_white" for termbox.ColorWhite
Attributes
  • "bold" for fg: termbox.AttrBold
  • "underline" for fg: termbox.AttrUnderline
  • "reverse" for fg: termbox.AttrReverse
  • "on_bold" for bg: termbox.AttrBold (this attribute actually makes the background blink on some platforms/environments, e.g. linux console, xterm...)

CustomFilter

This is an experimental feature. Please note that some details of this specification may change

By default peco comes with IgnoreCase, CaseSensitive, SmartCase and Regexp filters, but since v0.1.3, it is possible to create your own custom filter.

The filter will be executed via Command.Run() as an external process, and it will be passed the query values in the command line, and the original unaltered buffer is passed via os.Stdin. Your filter must perform the matching, and print out to os.Stdout matched lines. You filter MAY be called multiple times if the buffer given to peco is big enough. See BufferThreshold below.

Note that currently there is no way for the custom filter to specify where in the line the match occurred, so matched portions in the string WILL NOT BE HIGHLIGHTED.

The filter does not need to be a go program. It can be a perl/ruby/python/bash script, or anything else that is executable.

Once you have a filter, you must specify how the matcher is spawned:

{
    "CustomFilter": {
        "MyFilter": {
            "Cmd": "/path/to/my-matcher",
            "Args": [ "$QUERY" ],
            "BufferThreshold": 100
        }
    }
}

Cmd specifies the command name. This must be searcheable via exec.LookPath.

Elements in the Args section are string keys to array of program arguments. The special token $QUERY will be replaced with the unaltered query as the user typed in (i.e. multiple-word queries will be passed as a single string). You may pass in any other arguments in this array. If you omit this in your config, a default value of []string{"$QUERY"} will be used

BufferThreshold specifies that the filter command should be invoked when peco has this many lines to process in the buffer. For example, if you are using peco against a 1000-line input, and your BufferThreshold is 100 (which is the default), then your filter will be invoked 10 times. For obvious reasons, the larger this threshold is, the faster the overall performance will be, but the longer you will have to wait to see the filter results.

You may specify as many filters as you like in the CustomFilter section.

Examples

Layout

See --layout.

SingleKeyJump

{
  "SingleKeyJump": {
    "ShowPrefix": true
  }
}

Hacking

First, fork this repo, and get your clone locally.

  1. Make sure you have go 1.x, with GOPATH appropriately set
  2. Run go get github.com/jessevdk/go-flags
  3. Run go get github.com/mattn/go-runewidth
  4. Run go get github.com/nsf/termbox-go

Then from the root of this repository run:

go build cmd/peco/peco.go

This will create a peco binary in the local directory.

TODO

Test it. In doing so, we may change the repo structure

Implement all(?) of the original percol options

AUTHORS

  • Daisuke Maki (lestrrat)
  • mattn
  • syohex

CONTRIBUTORS

  • HIROSE Masaaki
  • Joel Segerlind
  • Lukas Lueg
  • Mitsuoka Mimura
  • Ryota Arai
  • Shinya Ohyanagi
  • Takashi Kokubun
  • Yuya Takeyama
  • cho45
  • cubicdaiya
  • kei_q
  • negipo
  • sona_tar
  • sugyan
  • swdyh
  • MURAOKA Taro (kaoriya/koron), for aho-corasick search
  • taichi, for the gif working on Windows
  • uobikiemukot
  • Samuel Lemaitre
  • Yousuke Ushiki
  • Linda_pp
  • Tomohiro Nishimura (Sixeight)

Notes

Obviously, kudos to the original percol: https://github.com/mooz/percol Much code stolen from https://github.com/mattn/gof

Documentation

Index

Constants

View Source
const (
	IgnoreCaseMatch    = "IgnoreCase"
	CaseSensitiveMatch = "CaseSensitive"
	SmartCaseMatch     = "SmartCase"
	RegexpMatch        = "Regexp"
)

These are used as keys in the config file

View Source
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"
)
View Source
const DefaultCustomFilterBufferThreshold = 100

DefaultCustomFilterBufferThreshold is the default value for BufferThreshold setting on CustomFilters.

Variables

View Source
var ErrBufferOutOfRange = errors.New("error: Specified index is out of range")

ErrBufferOutOfRange is returned when the index within the buffer that was queried was out of the containing buffer's range

View Source
var ErrFilterDidNotMatch = errors.New("error: filter did not match against given line")
View Source
var ErrFilterNotFound = errors.New("specified filter was not found")
View Source
var ErrSignalReceived = errors.New("received signal")
View Source
var ErrUserCanceled = errors.New("canceled")

ErrUserCanceled is used to signal that the user deliberately canceled using peco

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

func LocateRcfile() (string, error)

LocateRcfile attempts to find the config file in various locations

func NewSignalHandler added in v0.3.4

func NewSignalHandler(loopCh chan struct{}, onEnd, onSignalReceived func()) *signalHandler

Types

type Action added in v0.2.0

type Action interface {
	Register(string, ...termbox.Key)
	RegisterKeySequence(string, 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 Action 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(name string, k keyseq.KeyList)

RegisterKeySequence satisfies the Action interface for AfterFunc. 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

type BasicLayout struct {
	*Ctx
	*StatusBar
	// contains filtered or unexported fields
}

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(perPage int) error

CalculatePage calculates which page we're displaying

func (*BasicLayout) DrawPrompt added in v0.2.9

func (l *BasicLayout) DrawPrompt()

DrawPrompt draws the prompt to the terminal

func (*BasicLayout) DrawScreen added in v0.2.5

func (l *BasicLayout) DrawScreen(runningQuery bool)

DrawScreen draws the entire screen

func (*BasicLayout) MovePage added in v0.2.5

func (l *BasicLayout) MovePage(p PagingRequest) (moved bool)

MovePage scrolls the screen

func (*BasicLayout) PurgeDisplayCache added in v0.3.4

func (l *BasicLayout) PurgeDisplayCache()

type BufferReader added in v0.1.12

type BufferReader struct {
	*Ctx
	// contains filtered or unexported fields
}

BufferReader reads from either stdin or a file. In case of stdin, it also handles possible infinite source.

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 CLI added in v0.3.0

type CLI struct {
}

func (*CLI) Run added in v0.3.0

func (cli *CLI) Run() error

type CLIOptions added in v0.3.0

type CLIOptions struct {
	OptHelp           bool   `short:"h" long:"help" description:"show this help message and exit"`
	OptTTY            string `long:"tty" description:"path to the TTY (usually, the value of $TTY)"`
	OptQuery          string `long:"query" description:"initial value for query"`
	OptRcfile         string `long:"rcfile" description:"path to the settings file"`
	OptVersion        bool   `long:"version" description:"print the version and exit"`
	OptBufferSize     int    `long:"buffer-size" short:"b" description:"number of lines to keep in search buffer"`
	OptEnableNullSep  bool   `long:"null" description:"expect NUL (\\0) as separator for target/output"`
	OptInitialIndex   int    `long:"initial-index" description:"position of the initial index of the selection (0 base)"`
	OptInitialMatcher string `long:"initial-matcher" description:"specify the default matcher (deprecated)"`
	OptInitialFilter  string `long:"initial-filter" description:"specify the default filter"`
	OptPrompt         string `long:"prompt" description:"specify the prompt string"`
	OptLayout         string `long:"layout" description:"layout to be used 'top-down' (default) or 'bottom-up'" default:"top-down"`
	OptSelect1        bool   `long:"select-1" description:"select first item and immediately exit if the input contains only 1 item"`
}

func (CLIOptions) BufferSize added in v0.3.0

func (o CLIOptions) BufferSize() int

BufferSize returns the specified buffer size. Fulfills CtxOptions

func (CLIOptions) EnableNullSep added in v0.3.0

func (o CLIOptions) EnableNullSep() bool

EnableNullSep returns true if --null was specified. Fulfills CtxOptions

func (CLIOptions) InitialIndex added in v0.3.0

func (o CLIOptions) InitialIndex() int

func (CLIOptions) LayoutType added in v0.3.0

func (o CLIOptions) LayoutType() 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
	InitialFilter       string            `json:"InitialFilter"`
	Style               *StyleSet         `json:"Style"`
	Prompt              string            `json:"Prompt"`
	Layout              string            `json:"Layout"`
	CustomMatcher       map[string][]string
	CustomFilter        map[string]CustomFilterConfig
	QueryExecutionDelay int
	StickySelection     bool

	// If this is true, then the prefix for single key jump mode
	// is displayed by default.
	SingleKeyJump SingleKeyJumpConfig `json:"SingleKeyJump"`
}

Config holds all the data that can be configured in the external configuran file

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config

func (*Config) ReadFilename

func (c *Config) ReadFilename(filename string) error

ReadFilename reads the config from the given file, and does the appropriate processing, if any

type Ctx

type Ctx struct {
	*Hub
	*FilterQuery
	// contains filtered or unexported fields
}

Ctx contains all the important data. while you can easily access data in this struct from anywhere, only do so via channels

func NewCtx

func NewCtx(o CtxOptions) *Ctx

func (*Ctx) AddRawLine added in v0.3.0

func (c *Ctx) AddRawLine(l *RawLine)

func (*Ctx) AddWaitGroup

func (c *Ctx) AddWaitGroup(v int)

func (*Ctx) CaretPos added in v0.2.11

func (c *Ctx) CaretPos() int

func (*Ctx) DrawPrompt added in v0.2.9

func (c *Ctx) DrawPrompt()

func (*Ctx) Error added in v0.3.0

func (c *Ctx) Error() error

func (*Ctx) ExecQuery

func (c *Ctx) ExecQuery() bool

func (*Ctx) ExitWith added in v0.1.11

func (c *Ctx) ExitWith(err error)

func (*Ctx) Filter added in v0.3.0

func (c *Ctx) Filter() QueryFilterer

func (Ctx) GetCurrentLineBuffer added in v0.3.0

func (c Ctx) GetCurrentLineBuffer() LineBuffer

func (Ctx) GetRawLineBufferSize added in v0.3.0

func (c Ctx) GetRawLineBufferSize() int

func (*Ctx) IsRangeMode added in v0.2.0

func (c *Ctx) IsRangeMode() bool

func (*Ctx) IsSingleKeyJumpMode added in v0.3.4

func (c *Ctx) IsSingleKeyJumpMode() bool

func (*Ctx) LoadCustomFilter added in v0.3.0

func (c *Ctx) LoadCustomFilter() error

func (*Ctx) MoveCaretPos added in v0.2.11

func (c *Ctx) MoveCaretPos(offset int)

func (*Ctx) NewBufferReader added in v0.1.12

func (c *Ctx) NewBufferReader(r io.ReadCloser) *BufferReader

func (*Ctx) NewFilter

func (c *Ctx) NewFilter() *Filter

func (*Ctx) NewInput

func (c *Ctx) NewInput() *Input

func (*Ctx) NewView

func (c *Ctx) NewView() *View

func (*Ctx) ReadConfig

func (c *Ctx) ReadConfig(file string) error

func (*Ctx) ReleaseWaitGroup

func (c *Ctx) ReleaseWaitGroup()

func (*Ctx) ResetActiveLineBuffer added in v0.3.0

func (c *Ctx) ResetActiveLineBuffer()

func (*Ctx) ResetSelectedFilter added in v0.3.3

func (c *Ctx) ResetSelectedFilter()

func (*Ctx) ResultCh added in v0.2.11

func (c *Ctx) ResultCh() <-chan Line

func (*Ctx) RotateFilter added in v0.3.0

func (c *Ctx) RotateFilter()

func (*Ctx) SelectionAdd added in v0.2.11

func (c *Ctx) SelectionAdd(x int)

func (*Ctx) SelectionClear added in v0.2.11

func (c *Ctx) SelectionClear()

func (*Ctx) SelectionContains added in v0.2.11

func (c *Ctx) SelectionContains(n int) bool

func (*Ctx) SelectionLen added in v0.2.11

func (c *Ctx) SelectionLen() int

func (*Ctx) SelectionRemove added in v0.2.11

func (c *Ctx) SelectionRemove(x int)

func (*Ctx) SetActiveLineBuffer added in v0.3.0

func (c *Ctx) SetActiveLineBuffer(l *RawLineBuffer, runningQuery bool)

func (*Ctx) SetCaretPos added in v0.2.11

func (c *Ctx) SetCaretPos(where int)

func (*Ctx) SetCurrentFilterByName added in v0.3.0

func (c *Ctx) SetCurrentFilterByName(name string) error

func (*Ctx) SetPrompt added in v0.2.0

func (c *Ctx) SetPrompt(p string)

func (*Ctx) SetQuery

func (c *Ctx) SetQuery(q []rune)

func (*Ctx) SetSavedQuery added in v0.2.11

func (c *Ctx) SetSavedQuery(q []rune)

func (*Ctx) ToggleSingleKeyJumpMode added in v0.3.4

func (c *Ctx) ToggleSingleKeyJumpMode()

func (*Ctx) WaitDone

func (c *Ctx) WaitDone()

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 CustomFilterConfig added in v0.3.0

type CustomFilterConfig struct {
	// Cmd is the name of the command to invoke
	Cmd string

	// TODO: need to check if how we use this is correct
	Args []string

	// BufferThreshold defines how many lines peco buffers before
	// invoking the external command. If this value is big, we
	// will execute the external command fewer times, but the
	// results will not be generated for longer periods of time.
	// If this value is small, we will execute the external command
	// more often, but you pay the penalty of invoking that command
	// more times.
	BufferThreshold int
}

CustomFilterConfig is used to specify configuration parameters to CustomFilters

type ExternalCmdFilter added in v0.3.0

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

func NewExternalCmdFilter added in v0.3.0

func NewExternalCmdFilter(name, cmd string, args []string, threshold int, enableSep bool) *ExternalCmdFilter

func (*ExternalCmdFilter) Accept added in v0.3.0

func (ecf *ExternalCmdFilter) Accept(p Pipeliner)

func (ExternalCmdFilter) Cancel added in v0.3.0

func (sp ExternalCmdFilter) Cancel()

func (ExternalCmdFilter) CancelCh added in v0.3.0

func (sp ExternalCmdFilter) CancelCh() chan struct{}

func (ExternalCmdFilter) Clone added in v0.3.0

func (ecf ExternalCmdFilter) Clone() QueryFilterer

func (ExternalCmdFilter) OutputCh added in v0.3.0

func (sp ExternalCmdFilter) OutputCh() chan Line

func (ExternalCmdFilter) Pipeline added in v0.3.0

func (sp ExternalCmdFilter) Pipeline() (chan struct{}, chan Line)

func (*ExternalCmdFilter) SetQuery added in v0.3.0

func (ecf *ExternalCmdFilter) SetQuery(q string)

func (ExternalCmdFilter) String added in v0.3.0

func (ecf ExternalCmdFilter) String() string

func (*ExternalCmdFilter) Verify added in v0.3.0

func (ecf *ExternalCmdFilter) Verify() error

type Filter

type Filter struct {
	*Ctx
}

Filter is responsible for the actual "grep" part of peco

func (*Filter) Loop

func (f *Filter) Loop()

Loop keeps watching for incoming queries, and upon receiving a query, spawns a goroutine to do the heavy work. It also checks for previously running queries, so we can avoid running many goroutines doing the grep at the same time

func (*Filter) Work added in v0.1.3

func (f *Filter) Work(cancel chan struct{}, q HubReq)

Work is the actual work horse that that does the matching in a goroutine of its own. It wraps Matcher.Match().

type FilterQuery added in v0.2.6

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

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() []rune

func (FilterQuery) QueryLen added in v0.2.6

func (q FilterQuery) QueryLen() int

func (FilterQuery) QueryString added in v0.2.9

func (q FilterQuery) QueryString() string

func (FilterQuery) SavedQuery added in v0.2.11

func (q FilterQuery) SavedQuery() []rune

type FilterSet added in v0.3.0

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

func (*FilterSet) Add added in v0.3.0

func (fs *FilterSet) Add(qf QueryFilterer) error

func (*FilterSet) GetCurrent added in v0.3.0

func (fs *FilterSet) GetCurrent() QueryFilterer

func (*FilterSet) Reset added in v0.3.3

func (fx *FilterSet) Reset()

func (*FilterSet) Rotate added in v0.3.0

func (fs *FilterSet) Rotate()

func (*FilterSet) SetCurrentByName added in v0.3.0

func (fs *FilterSet) SetCurrentByName(name string) error

func (*FilterSet) Size added in v0.3.0

func (fs *FilterSet) Size() int

type FilteredLineBuffer added in v0.3.0

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

FilteredLineBuffer holds a "filtered" buffer. It holds a reference to the source buffer (note: should be immutable) and a list of indices into the source buffer

func NewFilteredLineBuffer added in v0.3.0

func NewFilteredLineBuffer(src LineBuffer) *FilteredLineBuffer

func (*FilteredLineBuffer) Accept added in v0.3.0

func (flb *FilteredLineBuffer) Accept(p Pipeliner)

func (*FilteredLineBuffer) Append added in v0.3.0

func (flb *FilteredLineBuffer) Append(l Line) (Line, error)

func (FilteredLineBuffer) Cancel added in v0.3.0

func (sp FilteredLineBuffer) Cancel()

func (FilteredLineBuffer) CancelCh added in v0.3.0

func (sp FilteredLineBuffer) CancelCh() chan struct{}

func (*FilteredLineBuffer) InvalidateUpTo added in v0.3.0

func (flb *FilteredLineBuffer) InvalidateUpTo(x int)

func (FilteredLineBuffer) LineAt added in v0.3.0

func (flb FilteredLineBuffer) LineAt(i int) (Line, error)

LineAt returns the line at index `i`. Note that the i-th element in this filtered buffer may actually correspond to a totally different line number in the source buffer.

func (FilteredLineBuffer) OutputCh added in v0.3.0

func (sp FilteredLineBuffer) OutputCh() chan Line

func (FilteredLineBuffer) Pipeline added in v0.3.0

func (sp FilteredLineBuffer) Pipeline() (chan struct{}, chan Line)

func (*FilteredLineBuffer) Register added in v0.3.0

func (flb *FilteredLineBuffer) Register(lb LineBuffer)

func (*FilteredLineBuffer) SelectSourceLineAt added in v0.3.0

func (flb *FilteredLineBuffer) SelectSourceLineAt(i int)

func (FilteredLineBuffer) Size added in v0.3.0

func (flb FilteredLineBuffer) Size() int

Size returns the number of lines in the buffer

func (*FilteredLineBuffer) Unregister added in v0.3.0

func (flb *FilteredLineBuffer) Unregister(lb LineBuffer)

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 NewHub added in v0.2.1

func NewHub(bufsiz int) *Hub

NewHub creates a new Hub struct

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) DrawCh added in v0.2.1

func (h *Hub) DrawCh() chan HubReq

DrawCh returns the channel to redraw the terminal display

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) PagingCh added in v0.2.1

func (h *Hub) PagingCh() chan HubReq

PagingCh returns the channel to page through the results

func (*Hub) QueryCh added in v0.2.1

func (h *Hub) QueryCh() chan HubReq

QueryCh returns the underlying channel for queries

func (*Hub) SendDraw added in v0.2.1

func (h *Hub) SendDraw(runningQuery bool)

SendDraw sends a request to redraw the terminal display

func (*Hub) SendDrawPrompt added in v0.2.9

func (h *Hub) SendDrawPrompt()

SendDrawPrompt sends a request to redraw the prompt only

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) SendPurgeDisplayCache added in v0.3.4

func (h *Hub) SendPurgeDisplayCache()

func (*Hub) SendQuery added in v0.2.1

func (h *Hub) SendQuery(q string)

SendQuery sends the query string to be processed by the Filter

func (*Hub) SendStatusMsg added in v0.2.1

func (h *Hub) SendStatusMsg(q string)

SendStatusMsg sends a string to be displayed in the status message

func (*Hub) SendStatusMsgAndClear added in v0.2.10

func (h *Hub) SendStatusMsgAndClear(q string, clearDelay time.Duration)

SendStatusMsgAndClear sends a string to be displayed in the status message, as well as a delay until the message should be cleared

func (*Hub) StatusMsgCh added in v0.2.1

func (h *Hub) StatusMsgCh() chan HubReq

StatusMsgCh returns the channel to update the status message

func (*Hub) Stop added in v0.2.1

func (h *Hub) Stop()

Stop closes the LoopCh so that peco shutdown

type HubReq added in v0.2.1

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

HubReq is a wrapper around the actual request 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

func (hr HubReq) DataString() string

DataString returns the underlying data as a string. Panics if type conversion fails.

func (HubReq) Done added in v0.2.1

func (hr HubReq) Done()

Done marks the request as done. If Hub is operating in asynchronous mode (default), it's a no op. Otherwise it sends a message back the reply channel to finish up the synchronous communication

type Input

type Input struct {
	*Ctx
	// contains filtered or unexported fields
}

Input handles input events from termbox.

func (*Input) Loop

func (i *Input) Loop()

Loop watches for incoming events from termbox, and pass them to the appropriate handler when something arrives.

type JumpToLineRequest added in v0.3.4

type JumpToLineRequest uint

func (JumpToLineRequest) Line added in v0.3.4

func (jlr JumpToLineRequest) Line() int

func (JumpToLineRequest) Type added in v0.3.4

type Keymap

type Keymap struct {
	Config map[string]string
	Action map[string][]string // custom actions
	// contains filtered or unexported fields
}

Keymap holds all the key sequence to action map

func NewKeymap

func NewKeymap(config map[string]string, actions map[string][]string) Keymap

NewKeymap creates a new Keymap struct

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

func (Keymap) LookupAction added in v0.3.4

func (km Keymap) LookupAction(ev termbox.Event) Action

LookupAction returns the appropriate action for the given termbox event

type Keyseq added in v0.3.4

type Keyseq interface {
	Add(keyseq.KeyList, interface{})
	AcceptKey(keyseq.Key) (interface{}, error)
	CancelChain()
	Clear()
	Compile() error
	InMiddleOfChain() bool
}

type Layout added in v0.2.5

type Layout interface {
	PrintStatus(string, time.Duration)
	DrawPrompt()
	DrawScreen(bool)
	MovePage(PagingRequest) (moved bool)
	PurgeDisplayCache()
}

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 Line added in v0.2.11

type Line interface {
	btree.Item

	ID() uint64

	// Buffer returns the raw buffer
	Buffer() string

	// DisplayString returns the string to be displayed. This means if you have
	// a null separator, the contents after the separator are not included
	// in this string
	DisplayString() string

	// Indices return the matched portion(s) of a string after filtering.
	// Note that while Indices may return nil, that just means that there are
	// no substrings to be highlighted. It doesn't mean there were no matches
	Indices() [][]int

	// Output returns the string to be display as peco finishes up doing its
	// thing. This means if you have null separator, the contents before the
	// separator are not included in this string
	Output() string

	// IsDirty returns true if this line should be forcefully redrawn
	IsDirty() bool

	// SetDirty sets the dirty flag on or off
	SetDirty(bool)
}

Line represents each of the line that peco uses to display and match against queries.

type LineBuffer added in v0.3.0

type LineBuffer interface {
	Pipeliner

	LineAt(int) (Line, error)
	Size() int

	// Register registers another LineBuffer that is dependent on
	// this buffer.
	Register(LineBuffer)
	Unregister(LineBuffer)

	// InvalidateUpTo is called when a source buffer invalidates
	// some lines. The argument is the largest line number that
	// should be invalidated (so anything up to that line is no
	// longer valid in the source)
	InvalidateUpTo(int)
}

LineBuffer represents a set of lines. This could be the raw data read in, or filtered data, such as result of running a match, or applying a selection by the user

Buffers should be immutable.

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

func (*ListArea) Draw added in v0.2.5

func (l *ListArea) Draw(parent Layout, perPage int, runningQuery bool)

Draw displays the ListArea on the screen

func (*ListArea) IsDirty added in v0.3.3

func (l *ListArea) IsDirty() bool

func (*ListArea) SetDirty added in v0.3.3

func (l *ListArea) SetDirty(dirty bool)

type MatchedLine added in v0.2.11

type MatchedLine struct {
	Line
	// contains filtered or unexported fields
}

MatchedLine contains the indices to the matches

func NewMatchedLine added in v0.2.11

func NewMatchedLine(rl Line, matches [][]int) *MatchedLine

NewMatchedLine creates a new MatchedLine

func (MatchedLine) Indices added in v0.2.11

func (ml MatchedLine) Indices() [][]int

Indices returns the indices in the buffer that matched

type PageCrop added in v0.3.0

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

PageCrop filters out a new LineBuffer based on entries per page and the page number

func (PageCrop) Crop added in v0.3.0

func (pf PageCrop) Crop(in LineBuffer) LineBuffer

Crop returns a new LineBuffer whose contents are bound within the given range

type PageInfo added in v0.2.1

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

type PagingRequest

type PagingRequest interface {
	Type() PagingRequestType
}

type PagingRequestType added in v0.3.4

type PagingRequestType int

PagingRequest can be sent to move the selection cursor

const (
	// ToLineAbove moves the selection to the line above
	ToLineAbove PagingRequestType = 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
	// ToScrollLeft scrolls screen to the left
	ToScrollLeft
	// ToScrollRight scrolls screen to the right
	ToScrollRight
	// ToLineInPage jumps to a particular line on the page
	ToLineInPage
)

func (PagingRequestType) Type added in v0.3.4

type Pipeliner added in v0.3.0

type Pipeliner interface {
	Pipeline() (chan struct{}, chan Line)
}

type QueryFilterer added in v0.3.0

type QueryFilterer interface {
	Pipeliner
	Cancel()
	Clone() QueryFilterer
	Accept(Pipeliner)
	SetQuery(string)
	String() string
}

type RawLine added in v0.2.11

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

RawLine is the input line as sent to peco, before filtering and what not.

func NewRawLine added in v0.2.11

func NewRawLine(v string, enableSep bool) *RawLine

NewRawLine creates a new RawLine. The `enableSep` flag tells it if we should search for a null character to split the string to display and the string to emit upon selection of of said line

func (RawLine) Buffer added in v0.2.11

func (rl RawLine) Buffer() string

Buffer returns the raw buffer. May contain null

func (RawLine) DisplayString added in v0.2.11

func (rl RawLine) DisplayString() string

DisplayString returns the string to be displayed

func (*RawLine) ID added in v0.3.0

func (rl *RawLine) ID() uint64

ID returns the unique ID of this line

func (RawLine) Indices added in v0.2.11

func (rl RawLine) Indices() [][]int

Indices fulfills the Line interface, but for RawLine it always returns nil

func (RawLine) IsDirty added in v0.3.0

func (rl RawLine) IsDirty() bool

IsDirty returns true if this line must be redrawn on the terminal

func (*RawLine) Less added in v0.3.0

func (rl *RawLine) Less(b btree.Item) bool

Less implements the btree.Item interface

func (RawLine) Output added in v0.2.11

func (rl RawLine) Output() string

Output returns the string to be displayed *after peco is done

func (*RawLine) SetDirty added in v0.3.0

func (rl *RawLine) SetDirty(b bool)

SetDirty sets the dirty flag

type RawLineBuffer added in v0.3.0

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

RawLineBuffer holds the raw set of lines as read into peco.

func NewRawLineBuffer added in v0.3.0

func NewRawLineBuffer() *RawLineBuffer

func (*RawLineBuffer) Accept added in v0.3.0

func (rlb *RawLineBuffer) Accept(p Pipeliner)

func (*RawLineBuffer) Append added in v0.3.0

func (rlb *RawLineBuffer) Append(l Line) (Line, error)

func (*RawLineBuffer) AppendLine added in v0.3.0

func (rlb *RawLineBuffer) AppendLine(l Line) (Line, error)

func (RawLineBuffer) Cancel added in v0.3.0

func (sp RawLineBuffer) Cancel()

func (RawLineBuffer) CancelCh added in v0.3.0

func (sp RawLineBuffer) CancelCh() chan struct{}

func (RawLineBuffer) InvalidateUpTo added in v0.3.0

func (rlb RawLineBuffer) InvalidateUpTo(_ int)

func (RawLineBuffer) LineAt added in v0.3.0

func (rlb RawLineBuffer) LineAt(i int) (Line, error)

LineAt returns the line at index `i`

func (RawLineBuffer) OutputCh added in v0.3.0

func (sp RawLineBuffer) OutputCh() chan Line

func (RawLineBuffer) Pipeline added in v0.3.0

func (sp RawLineBuffer) Pipeline() (chan struct{}, chan Line)

func (*RawLineBuffer) Register added in v0.3.0

func (rlb *RawLineBuffer) Register(lb LineBuffer)

func (*RawLineBuffer) Replay added in v0.3.0

func (rlb *RawLineBuffer) Replay() error

func (*RawLineBuffer) SetCapacity added in v0.3.0

func (rlb *RawLineBuffer) SetCapacity(capacity int)

func (RawLineBuffer) Size added in v0.3.0

func (rlb RawLineBuffer) Size() int

Size returns the number of lines in the buffer

func (*RawLineBuffer) Unregister added in v0.3.0

func (rlb *RawLineBuffer) Unregister(lb LineBuffer)

type RegexpFilter added in v0.3.0

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

func NewCaseSensitiveFilter added in v0.3.0

func NewCaseSensitiveFilter() *RegexpFilter

func NewIgnoreCaseFilter added in v0.3.0

func NewIgnoreCaseFilter() *RegexpFilter

func NewRegexpFilter added in v0.3.0

func NewRegexpFilter() *RegexpFilter

func NewSmartCaseFilter added in v0.3.0

func NewSmartCaseFilter() *RegexpFilter

SmartCaseFilter turns ON the ignore-case flag in the regexp if the query contains a upper-case character

func (*RegexpFilter) Accept added in v0.3.0

func (rf *RegexpFilter) Accept(p Pipeliner)

func (RegexpFilter) Cancel added in v0.3.0

func (sp RegexpFilter) Cancel()

func (RegexpFilter) CancelCh added in v0.3.0

func (sp RegexpFilter) CancelCh() chan struct{}

func (RegexpFilter) Clone added in v0.3.0

func (rf RegexpFilter) Clone() QueryFilterer

func (RegexpFilter) OutputCh added in v0.3.0

func (sp RegexpFilter) OutputCh() chan Line

func (RegexpFilter) Pipeline added in v0.3.0

func (sp RegexpFilter) Pipeline() (chan struct{}, chan Line)

func (*RegexpFilter) SetQuery added in v0.3.0

func (rf *RegexpFilter) SetQuery(q string)

func (RegexpFilter) String added in v0.3.0

func (rf RegexpFilter) String() string

type Screen added in v0.2.6

type Screen interface {
	Init() error
	Close() error
	Flush() error
	PollEvent() chan termbox.Event
	SetCell(int, int, rune, termbox.Attribute, termbox.Attribute)
	Size() (int, int)
	SendEvent(termbox.Event)
}

Screen hides termbox from the consuming code so that it can be swapped out for testing

type Selection added in v0.1.3

type Selection struct{ *btree.BTree }

Selection stores the line ids that were selected by the user. The contents of the Selection is always sorted from smallest to largest line ID

func NewSelection added in v0.2.11

func NewSelection() *Selection

NewSelection creates a new empty Selection

func (*Selection) Add added in v0.1.3

func (s *Selection) Add(l Line)

Add adds a new line to the selection. If the line already exists in the selection, it is silently ignored

func (*Selection) Remove added in v0.1.3

func (s *Selection) Remove(l Line)

Remove removes the specified line from the selection

type SelectionFilter added in v0.3.0

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

func (SelectionFilter) Name added in v0.3.0

func (sf SelectionFilter) Name() string

type SingleKeyJumpConfig added in v0.3.4

type SingleKeyJumpConfig struct {
	ShowPrefix bool          `json:"ShowPrefix"`
	PrefixList []rune        `json:"-"`
	PrefixMap  map[rune]uint `json:"-"`
}

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) PrintStatus added in v0.2.5

func (s *StatusBar) PrintStatus(msg string, clearDelay time.Duration)

PrintStatus prints a new status message. This also resets the timer created by ClearStatus()

type StatusMsgRequest added in v0.2.10

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

StatusMsgRequest specifies the string to be drawn on the status message bar and an optional delay that tells the view to clear that message

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

func (s *Style) UnmarshalJSON(buf []byte) error

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

type Termbox added in v0.2.6

type Termbox struct{}

Termbox just hands out the processing to the termbox library

func (Termbox) Close added in v0.3.4

func (t Termbox) Close() error

func (Termbox) Flush added in v0.2.6

func (t Termbox) Flush() error

Flush calls termbox.Flush

func (Termbox) Init added in v0.3.4

func (t Termbox) Init() error

func (Termbox) PollEvent added in v0.2.6

func (t Termbox) PollEvent() chan termbox.Event

PollEvent returns a channel that you can listen to for termbox's events. The actual polling is done in a separate gouroutine

func (Termbox) PostInit added in v0.3.4

func (t Termbox) PostInit() error

func (Termbox) SendEvent added in v0.3.0

func (t Termbox) SendEvent(_ termbox.Event)

SendEvent is used to allow programmers generate random events, but it's only useful for testing purposes. When interactiving with termbox-go, this method is a noop

func (Termbox) SetCell added in v0.2.6

func (t Termbox) SetCell(x, y int, ch rune, fg, bg termbox.Attribute)

SetCell writes to the terminal

func (Termbox) Size added in v0.2.6

func (t Termbox) Size() (int, int)

Size returns the dimensions of the current terminal

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

func (UserPrompt) Draw added in v0.2.5

func (u UserPrompt) Draw()

Draw draws the query prompt

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
)

type View

type View struct {
	*Ctx
	// contains filtered or unexported fields
}

View handles the drawing/updating the screen

func (*View) Loop

func (v *View) Loop()

Loop receives requests to update the screen

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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