histutil

package
v0.14.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package histutil provides utilities for working with command history.

Index

Constants

This section is empty.

Variables

View Source
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 NewFuser

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

NewFuser returns a new Fuser from a database.

func (*Fuser) AddCmd

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

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

func (*Fuser) AllCmds

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

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

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

LastCmd returns the last command within the fused view.

func (*Fuser) SessionCmds

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

SessionCmds returns the per-session history.

func (*Fuser) Walker

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

Walker returns a walker for the fused command 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 NewDBStore

func NewDBStore(db DB) Store

NewDBStore returns a Store backed by a database.

func NewDBStoreFrozen

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

func NewMemoryStore() Store

NewMemoryStore returns a Store that stores command history in memory.

type TestDB

type TestDB struct {
	AllCmds []string

	OneOffError error
}

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

func (*TestDB) AddCmd

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

func (*TestDB) CmdsWithSeq

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

func (*TestDB) NextCmdSeq

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

func (*TestDB) PrevCmd

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

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

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

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

func NewWalker

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

Jump to

Keyboard shortcuts

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