Source File
history.go
Belonging Package
github.com/reeflective/readline/internal/history
package historyvar defaultSourceName = "default history"// Source is an interface to allow you to write your own history logging tools.// By default readline will just use the dummyLineHistory interface which only// logs the history to memory ([]string to be precise).type Source interface {// Append takes the line and returns an updated number of lines or an errorWrite(string) (int, error)// GetLine takes the historic line number and returns the line or an errorGetLine(int) (string, error)// Len returns the number of history linesLen() int// Dump returns everything in readline. The return is an interface{} because// not all LineHistory implementations will want to structure the history in// the same way. And since Dump() is not actually used by the readline API// internally, this methods return can be structured in whichever way is most// convenient for your own applications (or even just create an empty// function which returns `nil` if you don't require Dump() either)Dump() interface{}}// memory is an in memory history.// One such history is bound to the readline shell by default.type memory struct {items []string}// NewInMemoryHistory creates a new in-memory command history source.func () Source {return new(memory)}// Write to history.func ( *memory) ( string) (int, error) {.items = append(.items, )return len(.items), nil}// GetLine returns a line from history.func ( *memory) ( int) (string, error) {if len(.items) == 0 {return "", nil}return .items[], nil}// Len returns the number of lines in history.func ( *memory) () int {return len(.items)}// Dump returns the entire history.func ( *memory) () interface{} {return .items}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |