Package histutil provides utilities for working with command history.



    This section is empty.


    View Source
    var ErrEndOfHistory = errors.New("end of history")

      ErrEndOfHistory is returned by Cursor.Get if the cursor is currently over the edge.


      This section is empty.


      type Cursor

      type Cursor interface {
      	// Prev moves the cursor to the previous command.
      	// Next moves the cursor to the next command.
      	// 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

        func NewDedupCursor(c Cursor) Cursor

          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

            type FaultyInMemoryDB interface {
            	// 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

              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

                  func NewDBStore(db DB) (Store, error)

                    NewDBStore returns a Store backed by a database with the view of all commands frozen at creation.

                    func NewHybridStore

                    func NewHybridStore(db DB) (Store, error)

                      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

                      func NewMemStore(texts ...string) Store

                        NewMemStore returns a Store that stores command history in memory.