github.com/elves/elvish@v0.15.0/pkg/cli/histutil/store.go (about) 1 package histutil 2 3 import ( 4 "errors" 5 6 "github.com/elves/elvish/pkg/store" 7 ) 8 9 // Store is an abstract interface for history store. 10 type Store interface { 11 // AddCmd adds a new command history entry and returns its sequence number. 12 // Depending on the implementation, the Store might respect cmd.Seq and 13 // return it as is, or allocate another sequence number. 14 AddCmd(cmd store.Cmd) (int, error) 15 // AllCmds returns all commands kept in the store. 16 AllCmds() ([]store.Cmd, error) 17 // Cursor returns a cursor that iterating through commands with the given 18 // prefix. The cursor is initially placed just after the last command in the 19 // store. 20 Cursor(prefix string) Cursor 21 } 22 23 // Cursor is used to navigate a Store. 24 type Cursor interface { 25 // Prev moves the cursor to the previous command. 26 Prev() 27 // Next moves the cursor to the next command. 28 Next() 29 // Get returns the command the cursor is currently at, or any error if the 30 // cursor is in an invalid state. If the cursor is "over the edge", the 31 // error is ErrEndOfHistory. 32 Get() (store.Cmd, error) 33 } 34 35 // ErrEndOfHistory is returned by Cursor.Get if the cursor is currently over the 36 // edge. 37 var ErrEndOfHistory = errors.New("end of history")