Documentation ¶
Overview ¶
Package histutil provides utilities for working with command history.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEndOfHistory = errors.New("end of history")
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface { NextCmdSeq() (int, error) AddCmd(cmd string) (int, error) CmdsWithSeq(from, upto int) ([]store.Cmd, error) PrevCmd(upto int, prefix string) (store.Cmd, error) }
DB is the interface of the storage database.
type Fuser ¶
type Fuser struct {
// contains filtered or unexported fields
}
Fuser provides a view of command history that is fused from the shared storage-backed command history and per-session history.
func (*Fuser) AllCmds ¶
AllCmds returns all visible commands, consisting of commands that were already in the database at startup, plus the per-session history.
func (*Fuser) FastForward ¶
FastForward fast-forwards the view of command history, so that commands added by other sessions since the start of the current session are available.
func (*Fuser) SessionCmds ¶
SessionCmds returns the per-session history.
type Store ¶
type Store interface { // AddCmd adds a new command history entry and returns its sequence number. // Depending on the implementation, the Store might respect cmd.Seq and // return it as is, or allocate another sequence number. AddCmd(cmd store.Cmd) (int, error) // AllCmds returns all commands kept in the store. AllCmds() ([]store.Cmd, error) // LastCmd returns the last command in the store. LastCmd() (store.Cmd, error) }
Store is an abstract interface for history store.
func NewDBStoreFrozen ¶
NewDBStoreFrozen returns a Store backed by a database, with the view of all commands frozen at creation.
func NewMemoryStore ¶
func NewMemoryStore() Store
NewMemoryStore returns a Store that stores command history in memory.
type TestDB ¶
TestDB is an implementation of the DB interface that can be used for testing.
func (*TestDB) NextCmdSeq ¶
type Walker ¶
type Walker interface { Prefix() string CurrentSeq() int CurrentCmd() string Prev() error Next() error }
Walker is used for walking through history entries with a given (possibly empty) prefix, skipping duplicates entries.
func NewSimpleWalker ¶
NewSimpleWalker returns a Walker, given the slice of all commands and the prefix.