elvish: github.com/elves/elvish/pkg/cli/histutil Index | Files

package histutil

import "github.com/elves/elvish/pkg/cli/histutil"

Package histutil provides utilities for working with command history.

Index

Package Files

db.go doc.go fuser.go simple_walker.go store.go walker.go

Variables

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

type DB Uses

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 Uses

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 NewFuser Uses

func NewFuser(db DB) (*Fuser, error)

NewFuser returns a new Fuser from a database.

func (*Fuser) AddCmd Uses

func (f *Fuser) AddCmd(cmd string) (int, error)

AddCmd adds a command to both the database and the per-session history.

func (*Fuser) AllCmds Uses

func (f *Fuser) AllCmds() ([]store.Cmd, error)

AllCmds returns all visible commands, consisting of commands that were already in the database at startup, plus the per-session history.

func (*Fuser) FastForward Uses

func (f *Fuser) FastForward() error

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) LastCmd Uses

func (f *Fuser) LastCmd() (store.Cmd, error)

LastCmd returns the last command within the fused view.

func (*Fuser) SessionCmds Uses

func (f *Fuser) SessionCmds() []store.Cmd

SessionCmds returns the per-session history.

func (*Fuser) Walker Uses

func (f *Fuser) Walker(prefix string) Walker

Walker returns a walker for the fused command history.

type Store Uses

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 NewDBStore Uses

func NewDBStore(db DB) Store

NewDBStore returns a Store backed by a database.

func NewDBStoreFrozen Uses

func NewDBStoreFrozen(db DB) (Store, error)

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

func NewMemoryStore Uses

func NewMemoryStore() Store

NewMemoryStore returns a Store that stores command history in memory.

type TestDB Uses

type TestDB struct {
    AllCmds []string

    OneOffError error
}

TestDB is an implementation of the DB interface that can be used for testing.

func (*TestDB) AddCmd Uses

func (s *TestDB) AddCmd(cmd string) (int, error)

func (*TestDB) CmdsWithSeq Uses

func (s *TestDB) CmdsWithSeq(from, upto int) ([]store.Cmd, error)

func (*TestDB) NextCmdSeq Uses

func (s *TestDB) NextCmdSeq() (int, error)

func (*TestDB) PrevCmd Uses

func (s *TestDB) PrevCmd(upto int, prefix string) (store.Cmd, error)

type Walker Uses

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 Uses

func NewSimpleWalker(cmds []string, prefix string) Walker

NewSimpleWalker returns a Walker, given the slice of all commands and the prefix.

func NewWalker Uses

func NewWalker(store DB, upper int, cmds []store.Cmd, prefix string) Walker

Package histutil imports 4 packages (graph) and is imported by 4 packages. Updated 2019-12-30. Refresh now. Tools for package owners.