Documentation ¶
Index ¶
- func Complete(h *Sources, forward, filter bool, maxLines int, regex *regexp.Regexp) completion.Values
- func Init(hist *Sources)
- type Item
- type Source
- type Sources
- func (h *Sources) Accept(hold, infer bool, err error)
- func (h *Sources) Add(name string, hist Source)
- func (h *Sources) AddFromFile(name, file string)
- func (h *Sources) Current() Source
- func (h *Sources) Cycle(next bool)
- func (h *Sources) Delete(sources ...string)
- func (h *Sources) Fetch(pos int)
- func (h *Sources) GetLast() string
- func (h *Sources) InferNext()
- func (h *Sources) InsertMatch(line *core.Line, cur *core.Cursor, usePos, fwd, regexp bool)
- func (h *Sources) Last() inputrc.Bind
- func (h *Sources) LineAccepted() (bool, string, error)
- func (h *Sources) Name() string
- func (h *Sources) OnLastSource() bool
- func (h *Sources) Pos() int
- func (h *Sources) Redo()
- func (h *Sources) Reset()
- func (h *Sources) Revert()
- func (h *Sources) Save()
- func (h *Sources) SaveWithCommand(bind inputrc.Bind)
- func (h *Sources) SkipSave()
- func (h *Sources) Suggest(line *core.Line) core.Line
- func (h *Sources) Undo()
- func (h *Sources) Walk(pos int)
- func (h *Sources) Write(infer bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Complete ¶
func Complete(h *Sources, forward, filter bool, maxLines int, regex *regexp.Regexp) completion.Values
Complete returns completions with the current history source values. If forward is true, the completions are proposed from the most ancient line in the history source to the most recent. If filter is true, only lines that match the current input line as a prefix are given.
Types ¶
type Source ¶
type Source interface { // Append takes the line and returns an updated number of lines or an error Write(string) (int, error) // GetLine takes the historic line number and returns the line or an error GetLine(int) (string, error) // Len returns the number of history lines Len() int // Dump returns everything in readline. The return is an interface{} because // not all LineHistory implementations will want to structure the history in // the same way. And since Dump() is not actually used by the readline API // internally, this methods return can be structured in whichever way is most // convenient for your own applications (or even just create an empty // function which returns `nil` if you don't require Dump() either) Dump() interface{} }
Source is an interface to allow you to write your own history logging tools. By default readline will just use the dummyLineHistory interface which only logs the history to memory ([]string to be precise).
func NewInMemoryHistory ¶
func NewInMemoryHistory() Source
NewInMemoryHistory creates a new in-memory command history source.
func NewSourceFromFile ¶
NewSourceFromFile returns a new history source writing to and reading from a file.
type Sources ¶
type Sources struct {
// contains filtered or unexported fields
}
Sources manages and serves all history sources for the current shell.
func NewSources ¶
NewSources is a required constructor for the history sources manager type.
func (*Sources) Accept ¶
Accept is used to signal the line has been accepted by the user and must be returned to the readline caller. If hold is true, the line is preserved and redisplayed on the next loop. If infer, the line is not written to the history, but preserved as a line to match against on the next loop. If infer is false, the line is automatically written to active sources.
func (*Sources) Add ¶
Add adds a source of history lines bound to a given name (printed above this source when used). If the shell currently has only an in-memory (default) history source available, the call will drop this source and replace it with the provided one. Following calls add to the list.
func (*Sources) AddFromFile ¶
AddFromFile adds a command history source from a file path. The name is used when using/searching the history source.
func (*Sources) Cycle ¶
Cycle checks for the next history source (if any) and makes it the active one. The active one is used in completions, and all history-related commands. If next is false, the engine cycles to the previous source.
func (*Sources) Delete ¶
Delete deletes one or more history source by name. If no arguments are passed, all currently bound sources are removed.
func (*Sources) Fetch ¶
Fetch fetches the history event at the provided index position and makes it the current buffer.
func (*Sources) InferNext ¶
func (h *Sources) InferNext()
InferNext finds a line matching the current line in the history, then finds the line event following it and, if any, inserts it.
func (*Sources) InsertMatch ¶
InsertMatch replaces the buffer with the first history line matching the provided buffer, either as a substring (if regexp is true), or as a prefix. If the line argument is nil, the current line buffer is used to match against.
func (*Sources) LineAccepted ¶
LineAccepted returns true if the user has accepted the line, signaling that the shell must return from its loop. The error can be nil, but may indicate a CtrlC/CtrlD style error.
func (*Sources) OnLastSource ¶
OnLastSource returns true if the currently active history source is the last one in the list.
func (*Sources) Pos ¶
Pos returns the current position in the undo history, which is equal to its length minus the number of previous undo calls.
func (*Sources) Redo ¶
func (h *Sources) Redo()
Redo cancels an undo action if any has been made, or if at the begin of the undo history, restores the original line's contents as their were before starting undoing.
func (*Sources) Reset ¶
func (h *Sources) Reset()
Reset will reset the current position in the list of undo items, but will not delete any of them.
func (*Sources) Revert ¶
func (h *Sources) Revert()
Revert goes back to the initial state of the line, which is what it was like when the shell started reading user input. Note that this state might be a line that was inferred, accept-and-held from the previous readline run.
func (*Sources) Save ¶
func (h *Sources) Save()
Save saves the current line and cursor position as an undo state item. If this was called while the shell was in the middle of its undo history (eg. the caller has undone one or more times), all undone steps are dropped.
func (*Sources) SaveWithCommand ¶
SaveWithCommand is only meant to be called in the main readline loop of the shell, and not from within commands themselves: it does the same job as Save(), but also keeps the command that has just been executed.
func (*Sources) SkipSave ¶
func (h *Sources) SkipSave()
SkipSave will not save the current line when the target command is done (more precisely, the next call to h.Save() will have no effect). This function is not useful is most cases, as call to saves will efficiently compare the line with the last saved state, and will not add redundant ones.
func (*Sources) Suggest ¶
Suggest returns the first line matching the current line buffer, so that caller can use for things like history autosuggestion. If no line matches the current line, it will return the latter.
func (*Sources) Undo ¶
func (h *Sources) Undo()
Undo restores the line and cursor position to their last saved state.