- InputReader - Reads from os.Stdin or file
- RawListBuffer - Buffers output from InputReader
- QueryFilter - Receive stream of Line objects, and filters according to user query
- FilteredLineBuffer - Buffers output from QueryFilter
- PagedLineBuffer - Type of FilteredLineBuffer, but creates a "paged" view of the filtered buffer, so it can be displayed to the terminal
InputReader reads from a io.Reader.
ir := InputReader{}
ir.Loop()
InputReader provides channels to work with it.
ch = ir.ReadyCh()
ch = ir.CancelCh()
ch = ir.OutputCh()
name | description |
---|---|
ReadyCh | There's something coming in from the source Reader. This is needed to handle piped chain of commands in the CLI |
CancelCh | Close this channel to cancel the pipeline. Except for in case of an error, InputReader does not close it. The caller needs to close it |
OutputCh | This is where you receive the actual input data |
RawListBuffer is where the input from InputReader is buffered to. This data needs to be buffered because peco expects the user to type and retype queries to filter this data. It needs to be re-fetchable.
Users interact against this buffer.
<-ir.ReadyCh() // input is coming in!
// do terminal configuration, etc
// RawListBuffer needs access to InputReader
rlb := &RawListBuffer{src: ir}
QueryFilters are what does the most interesting stuff (previously called Matcher)
rf := RegexpFilter{} // IgnoreCaseFilter, SmartCaseFilter, etc.
go rf.Filter(rlb.PipelineChannels())
FilteredLineBuffer stores the result of the QueryFilters. Buffering is required because we will be paging these results
flb := &FilteredListBuffer{src: rf}
FilteredLineBuffer knows the indices to the original RawLineBuffer. For example, suppose the RawLineBuffer looks like this:
1. Foo
2. Bar
3. Baz
And you filtered it so that in your FilteredLineBuffer you have
2. Bar
3. Baz
When you select index 0
on the FilteredLineBuffer, it knows that it's actually index 1
in the RawLineBuffer
PagedLineBuffer a special type of FilteredLineBuffer. It's created from RawLineBuffer or FilteredLineBuffer to extract a particular page within the buffer.
plb := rlb.AsPagedBuffer(
1, // page
10, // perPage
)