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")
ErrEndOfHistory is returned by Cursor.Get if the cursor is currently over the edge.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶ added in v0.15.0
type Cursor interface { // Prev moves the cursor to the previous command. Prev() // Next moves the cursor to the next command. Next() // Get returns the command the cursor is currently at, or any error if the // cursor is in an invalid state. If the cursor is "over the edge", the // error is ErrEndOfHistory. Get() (store.Cmd, error) }
Cursor is used to navigate a Store.
func NewDedupCursor ¶ added in v0.15.0
NewDedupCursor returns a cursor that skips over all duplicate entries.
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) NextCmd(from int, prefix string) (store.Cmd, error) }
DB is the interface of the storage database.
type FaultyInMemoryDB ¶ added in v0.15.0
type FaultyInMemoryDB interface { DB // SetOneOffError causes the next operation on the database to return the // given error. SetOneOffError(err error) }
FaultyInMemoryDB is an in-memory DB implementation that can be injected one-off errors. It is useful in tests.
func NewFaultyInMemoryDB ¶ added in v0.15.0
func NewFaultyInMemoryDB(cmds ...string) FaultyInMemoryDB
NewFaultyInMemoryDB creates a new FaultyInMemoryDB with the given commands.
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) // Cursor returns a cursor that iterating through commands with the given // prefix. The cursor is initially placed just after the last command in the // store. Cursor(prefix string) Cursor }
Store is an abstract interface for history store.
func NewDBStore ¶
NewDBStore returns a Store backed by a database with the view of all commands frozen at creation.
func NewHybridStore ¶ added in v0.15.0
NewHybridStore returns a store that provides a view of all the commands that exists in the database, plus a in-memory session history.
func NewMemStore ¶ added in v0.15.0
NewMemStore returns a Store that stores command history in memory.