peco

package module
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 32 Imported by: 22

README

peco

Simplistic interactive filtering tool

NOTE: If you are viewing this on GitHub, this document refers to the state of peco in whatever current branch you are viewing, not necessarily the state of a currently released version. Please make sure to checkout the Changes file for features and changes.

This README is long and comprehensive. Use the Table of Contents to navigate to the section that interests you. It has been placed at the bottom of the README file because of its length.

If you use peco, please consider sponsoring the authors of this project from the "Sponsor" button on the project page at https://github.com/peco/peco. Sponsorship plans start at $1 :)

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:

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

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)

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:

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! (this example uses C-Space)

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)

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, Regexp and Fuzzy 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.

The Fuzzy filter allows you to find matches using partial patterns. For example, when searching for ALongString, you can enable the Fuzzy filter and search ALS to find it. The Fuzzy filter uses smart case search like the SmartCase filter. With the FuzzyLongestSort flag enabled in the configuration file, it does a smarter match. It sorts the matched lines by the following precedence: 1. longer substring, 2. earlier (left positioned) substring, and 3. shorter line.

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

Works on Windows!

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

Showing peco running on Windows cmd.exe

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 macOS homebrew users)

macOS (Homebrew, Scarf)

If you're on macOS and want to use homebrew:

brew install peco

or with Scarf:

scarf install peco
Debian and Ubuntu based distributions (APT, Scarf)

There is an official Debian package that can be installed via APT:

apt install peco

or with Scarf:

scarf install peco
Void Linux (XBPS)
xbps-install -S peco
Arch Linux

There is an official Arch Linux package that can be installed via pacman:

pacman -Syu peco
Windows (Chocolatey NuGet Users)

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

C:\> choco install peco
Building peco yourself

Make sure to clone the source code under $GOPATH (i.e. $GOPATH/src/github.com/peco/peco). This is required as the main binary refers to an internal package, which requires that the source code be located in the correct package location.

Navigate to the directory above, then run:

make build

This will do the following:

  1. Run go build to create releases/$VERSION_NUMBER/peco

You can copy the binary to somewhere in your $PATH, and it should just work.

The above installs the correct versions of peco's dependencies. Then build it:

go build cmd/peco/peco.go

This compiles a peco binary in the root of the cloned peco repository. Copy this file to an appropriate location.

Please DO NOT use go get to install this tool. It bypasses the developers' intention of controlling the dependency versioning.

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 beforehand what the most likely query string is.

--print-query

When exiting, prints out the query typed by the user as the first line of output. The query will be printed even if there are no matches, if the program is terminated normally (i.e. enter key). On the other hand, the query will NOT be printed if the user exits via a cancel (i.e. esc key).

--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|Fuzzy

Specifies the initial filter to use upon start up. You should specify the name of the filter like IgnoreCase, CaseSensitive, SmartCase, Regexp and Fuzzy. 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.

--on-cancel success|error

Specifies the exit status to use when the user cancels the query execution. For historical and back-compatibility reasons, the default is success, meaning if the user cancels the query, the exit status is 0. When you choose error, peco will exit with a non-zero value.

--selection-prefix string

When specified, peco uses the specified prefix instead of changing line color to indicate currently selected line(s). default is to use colors. This option is experimental.

--exec string

When specified, peco executes the specified external command (via shell), with peco's currently selected line(s) as its input from STDIN.

Upon exiting from the external command, the control goes back to peco where you can keep browsing your search buffer, and to possibly execute your external command repeatedly afterwards.

To exit out of peco when running in this mode, you must execute the Cancel command, usually the escape key.

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 directory 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, Regexp and Fuzzy.

FuzzyLongestSort

Enables the longest substring match and sorts the output. It affects only the Fuzzy filter.

Default value for FuzzyLongestSort is false.

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 intact.

Default value for StickySelection is false.

OnCancel
{
    "OnCancel": "error"
}

OnCancel is equivalent to --on-cancel command line option.

MaxScanBufferSize
{
    "MaxScanBufferSize": 256
}

Controls the buffer sized (in kilobytes) used by bufio.Scanner, which is responsible for reading the input lines. If you believe that your input has very long lines that prohibit peco from reading them, try increasing this number.

The same time, the default MaxScanBuferSize is 256kb.

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 macOS
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.ScrollFirstItem Scrolls to the first item (in the entire buffer, not the current screen)
peco.ScrollLastItem Scrolls to the last item (in the entire buffer, not the current screen)
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 filtered by query and not filtered.
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.RotateFilter
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
  • "0"-"255" for 256color (Use256Color must be enabled)
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
  • "on_0"-"on_255" for 256color (Use256Color must be enabled)
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, Regexp and Fuzzy 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. Your 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 searchable 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
  }
}

SelectionPrefix

SelectionPrefix is equivalent to using --selection-prefix in the command line.

{
  "SelectionPrefix": ">"
}

Use256Color

Boolean value that determines whether or not to use 256color. The default is false.

Note: This has no effect on Windows because Windows console does not support extra color modes.

{
    "Use256Color": true
}

FAQ

Does peco work on (msys2|cygwin)?

No. https://github.com/peco/peco/issues/336#issuecomment-243939696 (Updated Feb 23, 2017: "Maybe" on cygwin https://github.com/peco/peco/issues/336#issuecomment-281912949)

Non-latin fonts (e.g. Japanese) look weird on my Windows machine...?

Are you using raster fonts? https://github.com/peco/peco/issues/341

Seeing escape sequences [200~ and [201~ when pasting text?

Disable bracketed paste mode. https://github.com/peco/peco/issues/417

Hacking

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

  1. Make sure you have go installed, with GOPATH appropriately set
  2. Make sure you have make installed
  3. Run make installdeps (You only need to do this once)

To test, run

make test

To build, run

make build

This will create a peco binary in $(RELEASE_DIR)/peco_$(GOOS)_$(GOARCH)/peco$(SUFFIX). Or, of course, you can just run

go build cmd/peco/peco.go

which will create the binary in the local directory.

TODO

Unit test it.

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)
  • Naruki Tanabe (narugit)

Notes

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

Table of Contents

Documentation

Index

Constants

View Source
const (
	DefaultLayoutType  = LayoutTypeTopDown // LayoutTypeTopDown makes the layout so 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 (
	IgnoreCaseMatch    = "IgnoreCase"
	CaseSensitiveMatch = "CaseSensitive"
	SmartCaseMatch     = "SmartCase"
	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

func LocateRcfile(locater configLocateFunc) (string, error)

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(string, keyseq.KeyList)
	Execute(context.Context, *Peco, 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(context.Context, *Peco, 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(ctx context.Context, state *Peco, 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 ActionMap added in v0.4.0

type ActionMap interface {
	ExecuteAction(context.Context, *Peco, termbox.Event) error
}

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(screen Screen, 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 {
	*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(state *Peco) *BasicLayout

NewBottomUpLayout creates a new Layout in bottom-up format

func NewDefaultLayout added in v0.2.5

func NewDefaultLayout(state *Peco) *BasicLayout

NewDefaultLayout creates a new Layout in the default format (top-down)

func (*BasicLayout) CalculatePage added in v0.2.5

func (l *BasicLayout) CalculatePage(state *Peco, perPage int) error

CalculatePage calculates which page we're displaying

func (*BasicLayout) DrawPrompt added in v0.2.9

func (l *BasicLayout) DrawPrompt(state *Peco)

DrawPrompt draws the prompt to the terminal

func (*BasicLayout) DrawScreen added in v0.2.5

func (l *BasicLayout) DrawScreen(state *Peco, options *DrawOptions)

DrawScreen draws the entire screen

func (*BasicLayout) MovePage added in v0.2.5

func (l *BasicLayout) MovePage(state *Peco, p PagingRequest) (moved bool)

MovePage scrolls the screen

func (*BasicLayout) PurgeDisplayCache added in v0.3.4

func (l *BasicLayout) PurgeDisplayCache()

type Buffer added in v0.4.0

type Buffer interface {
	LineAt(int) (line.Line, error)
	Size() int
	// contains filtered or unexported methods
}

Buffer interface is used for containers for lines to be processed by peco.

type CLI added in v0.3.0

type CLI struct {
}

type CLIOptions added in v0.3.0

type CLIOptions struct {
	OptHelp            bool   `short:"h" long:"help" description:"show this help message and exit"`
	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' or 'bottom-up'. default is 'top-down'"`
	OptSelect1         bool   `long:"select-1" description:"select first item and immediately exit if the input contains only 1 item"`
	OptOnCancel        string `` /* 141-byte string literal not displayed */
	OptSelectionPrefix string `` /* 174-byte string literal not displayed */
	OptExec            string `` /* 204-byte string literal not displayed */
	OptPrintQuery      bool   `long:"print-query" description:"print out the current query as first line of output"`
}

func (CLIOptions) Validate added in v0.4.0

func (options CLIOptions) Validate() error

type Caret added in v0.4.0

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

func (*Caret) Move added in v0.4.0

func (c *Caret) Move(diff int)

func (*Caret) Pos added in v0.4.0

func (c *Caret) Pos() int

func (*Caret) SetPos added in v0.4.0

func (c *Caret) SetPos(p int)

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"`
	Use256Color         bool              `json:"Use256Color"`
	OnCancel            string            `json:"OnCancel"`
	CustomMatcher       map[string][]string
	CustomFilter        map[string]CustomFilterConfig
	QueryExecutionDelay int
	StickySelection     bool
	MaxScanBufferSize   int
	FuzzyLongestSort    bool

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

	// Use this prefix to denote currently selected line
	SelectionPrefix string `json:"SelectionPrefix"`
}

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

func (*Config) Init added in v0.4.0

func (c *Config) Init() error

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 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 DrawOptions added in v0.4.2

type DrawOptions struct {
	RunningQuery bool
	DisableCache bool
}

type Filter

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

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

func NewFilter added in v0.4.0

func NewFilter(state *Peco) *Filter

func (*Filter) Loop

func (f *Filter) Loop(ctx context.Context, cancel func()) error

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(ctx context.Context, q hub.Payload)

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 Query

type FilteredBuffer added in v0.4.0

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

FilteredBuffer 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 NewFilteredBuffer added in v0.4.0

func NewFilteredBuffer(src Buffer, page, perPage int) *FilteredBuffer

func (FilteredBuffer) LineAt added in v0.4.0

func (flb FilteredBuffer) LineAt(i int) (line.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 (*FilteredBuffer) MaxColumn added in v0.5.1

func (flb *FilteredBuffer) MaxColumn() int

MaxColumn returns the max column size, which controls the amount we can scroll to the right

func (FilteredBuffer) Size added in v0.4.0

func (flb FilteredBuffer) Size() int

Size returns the number of lines in the buffer

type Input

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

func NewInput added in v0.4.0

func NewInput(state *Peco, am ActionMap, src chan termbox.Event) *Input

func (*Input) Loop

func (i *Input) Loop(ctx context.Context, cancel func()) error

type Inputseq added in v0.4.0

type Inputseq []string

Inputseq is a list of keys that the user typed

func (*Inputseq) Add added in v0.4.0

func (is *Inputseq) Add(s string)

func (Inputseq) KeyNames added in v0.4.0

func (is Inputseq) KeyNames() []string

func (Inputseq) Len added in v0.4.0

func (is Inputseq) Len() int

func (*Inputseq) Reset added in v0.4.0

func (is *Inputseq) Reset()

type JumpToLineRequest added in v0.3.4

type JumpToLineRequest int

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

ApplyKeybinding applies all of the custom key bindings on top of the default key bindings

func (Keymap) ExecuteAction added in v0.4.0

func (km Keymap) ExecuteAction(ctx context.Context, state *Peco, ev termbox.Event) (err error)

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

func (Keymap) Sequence added in v0.4.0

func (km Keymap) Sequence() Keyseq

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(*Peco)
	DrawScreen(*Peco, *DrawOptions)
	MovePage(*Peco, 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 ListArea added in v0.2.5

type ListArea struct {
	*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(screen Screen, anchor VerticalAnchor, anchorOffset int, sortTopDown bool, styles *StyleSet) *ListArea

NewListArea creates a new ListArea struct

func (*ListArea) Draw added in v0.2.5

func (l *ListArea) Draw(state *Peco, parent Layout, perPage int, options *DrawOptions)

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 Location added in v0.4.0

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

func (Location) Column added in v0.4.0

func (l Location) Column() int

func (Location) LineNumber added in v0.4.0

func (l Location) LineNumber() int

func (Location) MaxPage added in v0.4.0

func (l Location) MaxPage() int

func (Location) Offset added in v0.4.0

func (l Location) Offset() int

func (Location) Page added in v0.4.0

func (l Location) Page() int

func (Location) PageCrop added in v0.4.0

func (l Location) PageCrop() PageCrop

func (Location) PerPage added in v0.4.0

func (l Location) PerPage() int

func (*Location) SetColumn added in v0.4.0

func (l *Location) SetColumn(n int)

func (*Location) SetLineNumber added in v0.4.0

func (l *Location) SetLineNumber(n int)

func (*Location) SetMaxPage added in v0.4.0

func (l *Location) SetMaxPage(n int)

func (*Location) SetOffset added in v0.4.0

func (l *Location) SetOffset(n int)

func (*Location) SetPage added in v0.4.0

func (l *Location) SetPage(n int)

func (*Location) SetPerPage added in v0.4.0

func (l *Location) SetPerPage(n int)

func (*Location) SetTotal added in v0.4.0

func (l *Location) SetTotal(n int)

func (Location) Total added in v0.4.0

func (l Location) Total() int

type MatchIndexer added in v0.4.7

type MatchIndexer interface {
	// 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
}

type MemoryBuffer added in v0.4.0

type MemoryBuffer struct {
	PeriodicFunc func()
	// contains filtered or unexported fields
}

MemoryBuffer is an implementation of Buffer

func NewMemoryBuffer added in v0.4.0

func NewMemoryBuffer() *MemoryBuffer

func (*MemoryBuffer) Accept added in v0.4.0

func (mb *MemoryBuffer) Accept(ctx context.Context, in chan interface{}, _ pipeline.ChanOutput)

func (*MemoryBuffer) Done added in v0.4.0

func (mb *MemoryBuffer) Done() <-chan struct{}

func (*MemoryBuffer) LineAt added in v0.4.0

func (mb *MemoryBuffer) LineAt(n int) (line.Line, error)

func (*MemoryBuffer) Reset added in v0.4.0

func (mb *MemoryBuffer) Reset()

func (*MemoryBuffer) Size added in v0.4.0

func (mb *MemoryBuffer) Size() int

type MessageHub added in v0.4.4

type MessageHub interface {
	Batch(context.Context, func(context.Context), bool)
	DrawCh() chan hub.Payload
	PagingCh() chan hub.Payload
	QueryCh() chan hub.Payload
	SendDraw(context.Context, interface{})
	SendDrawPrompt(context.Context)
	SendPaging(context.Context, interface{})
	SendQuery(context.Context, string)
	SendStatusMsg(context.Context, string)
	SendStatusMsgAndClear(context.Context, string, time.Duration)
	StatusMsgCh() chan hub.Payload
}

MessageHub is the interface that must be satisfied by the message hub component. Unless we're in testing, github.com/peco/peco/hub.Hub is used.

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 Buffer) *FilteredBuffer

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

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       PagingRequestType = iota // ToLineAbove moves the selection to the line above
	ToScrollPageDown                           // ToScrollPageDown moves the selection to the next page
	ToLineBelow                                // ToLineBelow moves the selection to the line below
	ToScrollPageUp                             // ToScrollPageUp moves the selection to the previous page
	ToScrollLeft                               // ToScrollLeft scrolls screen to the left
	ToScrollRight                              // ToScrollRight scrolls screen to the right
	ToLineInPage                               // ToLineInPage jumps to a particular line on the page
	ToScrollFirstItem                          // ToScrollFirstItem
	ToScrollLastItem                           // ToScrollLastItem
)

func (PagingRequestType) String added in v0.4.0

func (i PagingRequestType) String() string

func (PagingRequestType) Type added in v0.3.4

type Peco added in v0.4.0

type Peco struct {
	Argv   []string
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

Peco is the global object containing everything required to run peco. It also contains the global state of the program.

func New added in v0.4.0

func New() *Peco

func (*Peco) ApplyConfig added in v0.4.0

func (p *Peco) ApplyConfig(opts CLIOptions) error

func (*Peco) Caret added in v0.4.0

func (p *Peco) Caret() *Caret

func (*Peco) CurrentLineBuffer added in v0.4.0

func (p *Peco) CurrentLineBuffer() Buffer

func (*Peco) Err added in v0.4.0

func (p *Peco) Err() error

func (*Peco) ExecQuery added in v0.4.0

func (p *Peco) ExecQuery(nextFunc func()) bool

ExecQuery executes the query, taking in consideration things like the exec-delay, and user's multiple successive inputs in a very short span

if nextFunc is non-nil, then nextFunc is executed after the query is executed

func (*Peco) Exit added in v0.4.0

func (p *Peco) Exit(err error)

func (*Peco) Filters added in v0.4.0

func (p *Peco) Filters() *filter.Set

func (*Peco) Hub added in v0.4.0

func (p *Peco) Hub() MessageHub

func (*Peco) Inputseq added in v0.4.0

func (p *Peco) Inputseq() *Inputseq

func (*Peco) Keymap added in v0.4.0

func (p *Peco) Keymap() Keymap

func (*Peco) LayoutType added in v0.4.0

func (p *Peco) LayoutType() string

func (*Peco) Location added in v0.4.0

func (p *Peco) Location() *Location

func (*Peco) PrintResults added in v0.4.6

func (p *Peco) PrintResults()

func (*Peco) Prompt added in v0.4.0

func (p *Peco) Prompt() string

func (*Peco) Query added in v0.4.0

func (p *Peco) Query() *Query

func (*Peco) QueryExecDelay added in v0.4.0

func (p *Peco) QueryExecDelay() time.Duration

func (*Peco) Ready added in v0.4.0

func (p *Peco) Ready() <-chan struct{}

func (*Peco) ResetCurrentLineBuffer added in v0.4.0

func (p *Peco) ResetCurrentLineBuffer()

func (*Peco) ResultCh added in v0.4.0

func (p *Peco) ResultCh() chan line.Line

func (*Peco) Run added in v0.4.0

func (p *Peco) Run(ctx context.Context) (err error)

func (*Peco) Screen added in v0.4.0

func (p *Peco) Screen() Screen

func (*Peco) Selection added in v0.4.0

func (p *Peco) Selection() *Selection

func (*Peco) SelectionRangeStart added in v0.4.0

func (p *Peco) SelectionRangeStart() *RangeStart

func (*Peco) SetCurrentLineBuffer added in v0.4.0

func (p *Peco) SetCurrentLineBuffer(b Buffer)

func (*Peco) SetResultCh added in v0.4.0

func (p *Peco) SetResultCh(ch chan line.Line)

func (*Peco) SetSingleKeyJumpMode added in v0.4.0

func (p *Peco) SetSingleKeyJumpMode(b bool)

func (*Peco) Setup added in v0.4.0

func (p *Peco) Setup() (err error)

func (*Peco) SetupSource added in v0.4.0

func (p *Peco) SetupSource(ctx context.Context) (s *Source, err error)

func (*Peco) SingleKeyJumpIndex added in v0.4.0

func (p *Peco) SingleKeyJumpIndex(ch rune) (uint, bool)

func (*Peco) SingleKeyJumpMode added in v0.4.0

func (p *Peco) SingleKeyJumpMode() bool

func (*Peco) SingleKeyJumpPrefixes added in v0.4.0

func (p *Peco) SingleKeyJumpPrefixes() []rune

func (*Peco) SingleKeyJumpShowPrefix added in v0.4.0

func (p *Peco) SingleKeyJumpShowPrefix() bool

func (*Peco) Source added in v0.4.0

func (p *Peco) Source() pipeline.Source

func (*Peco) Styles added in v0.4.0

func (p *Peco) Styles() *StyleSet

func (*Peco) ToggleSingleKeyJumpMode added in v0.4.0

func (p *Peco) ToggleSingleKeyJumpMode()

func (*Peco) Use256Color added in v0.5.8

func (p *Peco) Use256Color() bool

type PrintArgs added in v0.4.0

type PrintArgs struct {
	X       int
	XOffset int
	Y       int
	Fg      termbox.Attribute
	Bg      termbox.Attribute
	Msg     string
	Fill    bool
}

type Query added in v0.4.0

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

func (*Query) DeleteRange added in v0.4.0

func (q *Query) DeleteRange(start, end int)

func (*Query) InsertAt added in v0.4.0

func (q *Query) InsertAt(ch rune, where int)

func (*Query) Len added in v0.4.0

func (q *Query) Len() int

func (*Query) Reset added in v0.4.0

func (q *Query) Reset()

func (*Query) RestoreSavedQuery added in v0.4.0

func (q *Query) RestoreSavedQuery()

func (*Query) RuneAt added in v0.4.0

func (q *Query) RuneAt(where int) rune

func (*Query) Runes added in v0.4.0

func (q *Query) Runes() <-chan rune

Runes returns a channel that gives you the list of runes in the query

func (*Query) SaveQuery added in v0.4.0

func (q *Query) SaveQuery()

func (*Query) Set added in v0.4.0

func (q *Query) Set(s string)

func (*Query) String added in v0.4.0

func (q *Query) String() string

type RangeStart added in v0.4.0

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

func (*RangeStart) Reset added in v0.4.0

func (s *RangeStart) Reset()

func (*RangeStart) SetValue added in v0.4.0

func (s *RangeStart) SetValue(n int)

func (RangeStart) Valid added in v0.4.0

func (s RangeStart) Valid() bool

func (RangeStart) Value added in v0.4.0

func (s RangeStart) Value() int

type Screen added in v0.2.6

type Screen interface {
	Init(*Config) error
	Close() error
	Flush() error
	PollEvent(context.Context, *Config) chan termbox.Event
	Print(PrintArgs) int
	Resume()
	SetCell(int, int, rune, termbox.Attribute, termbox.Attribute)
	SetCursor(int, int)
	Size() (int, int)
	SendEvent(termbox.Event)
	Suspend()
}

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 {
	// contains filtered or unexported fields
}

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.Line)

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

func (*Selection) Ascend added in v0.4.0

func (s *Selection) Ascend(i btree.ItemIterator)

func (*Selection) Copy added in v0.5.0

func (s *Selection) Copy(dst *Selection)

func (*Selection) Has added in v0.1.3

func (s *Selection) Has(x line.Line) bool

func (*Selection) Len added in v0.1.3

func (s *Selection) Len() int

func (*Selection) Remove added in v0.1.3

func (s *Selection) Remove(l line.Line)

Remove removes the specified line from the selection

func (*Selection) Reset added in v0.4.0

func (s *Selection) Reset()

type SingleKeyJumpConfig added in v0.3.4

type SingleKeyJumpConfig struct {
	ShowPrefix bool `json:"ShowPrefix"`
}

type Source added in v0.4.0

type Source struct {
	pipeline.ChanOutput
	// contains filtered or unexported fields
}

Source implements pipeline.Source, and is the buffer for the input

func NewSource added in v0.4.0

func NewSource(name string, in io.Reader, isInfinite bool, idgen line.IDGenerator, capacity int, enableSep bool) *Source

Creates a new Source. Does not start processing the input until you call Setup()

func (*Source) Append added in v0.4.0

func (s *Source) Append(l line.Line)

func (*Source) IsInfinite added in v0.5.7

func (s *Source) IsInfinite() bool

func (*Source) LineAt added in v0.4.0

func (s *Source) LineAt(n int) (line.Line, error)

func (*Source) Name added in v0.5.1

func (s *Source) Name() string

func (*Source) Ready added in v0.4.0

func (s *Source) Ready() <-chan struct{}

Ready returns the "input ready" channel. It will be closed as soon as the first line of input is processed via Setup()

func (*Source) Reset added in v0.4.0

func (s *Source) Reset()

Reset resets the state of the source object so that it is ready to feed the filters

func (*Source) Setup added in v0.4.0

func (s *Source) Setup(ctx context.Context, state *Peco)

Setup reads from the input os.File.

func (*Source) SetupDone added in v0.4.0

func (s *Source) SetupDone() <-chan struct{}

SetupDone returns the "read all lines" channel. It will be closed as soon as the all input has been read

func (*Source) Size added in v0.4.0

func (s *Source) Size() int

func (*Source) Start added in v0.4.0

func (s *Source) Start(ctx context.Context, out pipeline.ChanOutput)

Start starts

type State added in v0.4.0

type State interface {
	Keymap() *Keymap
	Query() Query
	Screen() Screen
	SetCurrentCol(int)
	CurrentCol() int
	SetCurrentLine(int)
	CurrentLine() int
	SetSingleKeyJumpMode(bool)
	SingleKeyJumpMode() bool
}

type StatusBar added in v0.2.5

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

StatusBar draws the status message bar

func NewStatusBar added in v0.2.5

func NewStatusBar(screen Screen, anchor VerticalAnchor, anchorOffset int, styles *StyleSet) *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 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

func (*StyleSet) Init added in v0.4.0

func (ss *StyleSet) Init()

type Termbox added in v0.2.6

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

Termbox just hands out the processing to the termbox library

func NewTermbox added in v0.5.0

func NewTermbox() *Termbox

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(cfg *Config) error

func (*Termbox) PollEvent added in v0.2.6

func (t *Termbox) PollEvent(ctx context.Context, cfg *Config) 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(cfg *Config) error

func (*Termbox) Print added in v0.4.0

func (t *Termbox) Print(args PrintArgs) int

func (*Termbox) Resume added in v0.5.0

func (t *Termbox) Resume()

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) SetCursor added in v0.5.5

func (t *Termbox) SetCursor(x, y int)

func (*Termbox) Size added in v0.2.6

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

Size returns the dimensions of the current terminal

func (*Termbox) Suspend added in v0.5.0

func (t *Termbox) Suspend()

type UserPrompt added in v0.2.5

type UserPrompt struct {
	*AnchorSettings
	// contains filtered or unexported fields
}

UserPrompt draws the prompt line

func NewUserPrompt added in v0.2.5

func NewUserPrompt(screen Screen, anchor VerticalAnchor, anchorOffset int, prompt string, styles *StyleSet) *UserPrompt

NewUserPrompt creates a new UserPrompt struct

func (UserPrompt) Draw added in v0.2.5

func (u UserPrompt) Draw(state *Peco)

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    VerticalAnchor = iota + 1 // AnchorTop anchors elements towards the top of the screen
	AnchorBottom                           // AnchorBottom anchors elements towards the bottom of the screen
)

func (VerticalAnchor) String added in v0.4.0

func (i VerticalAnchor) String() string

type View

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

View handles the drawing/updating the screen

func NewView added in v0.4.0

func NewView(state *Peco) *View

func (*View) Loop

func (v *View) Loop(ctx context.Context, cancel func()) error

Directories

Path Synopsis
cmd
internal
Package pipeline implements the basic data processing pipeline used by peco
Package pipeline implements the basic data processing pipeline used by peco

Jump to

Keyboard shortcuts

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