history

package
v0.0.0-...-8aadb99 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

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.

func Init

func Init(hist *Sources)

Init initializes the history sources positions and buffers at the start of each readline loop. If the last command asked to infer a command line from the history, it is performed now.

Types

type Item

type Item struct {
	Index    int
	DateTime time.Time
	Block    string
}

Item is the structure of an individual item in the History.list slice.

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

func NewSourceFromFile(file string) (Source, error)

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

func NewSources(line *core.Line, cur *core.Cursor, hint *ui.Hint, opts *inputrc.Config) *Sources

NewSources is a required constructor for the history sources manager type.

func (*Sources) Accept

func (h *Sources) Accept(hold, infer bool, err error)

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

func (h *Sources) Add(name string, hist Source)

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

func (h *Sources) AddFromFile(name, file string)

AddFromFile adds a command history source from a file path. The name is used when using/searching the history source.

func (*Sources) Current

func (h *Sources) Current() Source

Current returns the current/active history source.

func (*Sources) Cycle

func (h *Sources) Cycle(next bool)

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

func (h *Sources) Delete(sources ...string)

Delete deletes one or more history source by name. If no arguments are passed, all currently bound sources are removed.

func (*Sources) Fetch

func (h *Sources) Fetch(pos int)

Fetch fetches the history event at the provided index position and makes it the current buffer.

func (*Sources) GetLast

func (h *Sources) GetLast() string

GetLast returns the last saved history line in the active history source.

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

func (h *Sources) InsertMatch(line *core.Line, cur *core.Cursor, usePos, fwd, regexp bool)

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) Last

func (h *Sources) Last() inputrc.Bind

Last returns the last command ran by the shell.

func (*Sources) LineAccepted

func (h *Sources) LineAccepted() (bool, string, error)

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) Name

func (h *Sources) Name() string

Name returns the name of the currently active history source.

func (*Sources) OnLastSource

func (h *Sources) OnLastSource() bool

OnLastSource returns true if the currently active history source is the last one in the list.

func (*Sources) Pos

func (h *Sources) Pos() int

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

func (h *Sources) SaveWithCommand(bind inputrc.Bind)

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

func (h *Sources) Suggest(line *core.Line) core.Line

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.

func (*Sources) Walk

func (h *Sources) Walk(pos int)

Walk goes to the next or previous history line in the active source. If at the beginning of the history, the first history line is kept. If at the end of it, the main input buffer and cursor position is restored.

func (*Sources) Write

func (h *Sources) Write(infer bool)

Write writes the accepted input line to all available sources. If infer is true, the next history initialization will automatically insert the next history line event after the first match of the line, which one is then NOT written.

Jump to

Keyboard shortcuts

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