package histutil

import (
	

	
)

// NewMemStore returns a Store that stores command history in memory.
func ( ...string) Store {
	 := make([]store.Cmd, len())
	for ,  := range  {
		[] = store.Cmd{Text: , Seq: }
	}
	return &memStore{}
}

type memStore struct{ cmds []store.Cmd }

func ( *memStore) () ([]store.Cmd, error) {
	return .cmds, nil
}

func ( *memStore) ( store.Cmd) (int, error) {
	if .Seq < 0 {
		.Seq = len(.cmds) + 1
	}
	.cmds = append(.cmds, )
	return .Seq, nil
}

func ( *memStore) ( string) Cursor {
	return &memStoreCursor{.cmds, , len(.cmds)}
}

type memStoreCursor struct {
	cmds   []store.Cmd
	prefix string
	index  int
}

func ( *memStoreCursor) () {
	if .index < 0 {
		return
	}
	for .index--; .index >= 0; .index-- {
		if strings.HasPrefix(.cmds[.index].Text, .prefix) {
			return
		}
	}
}

func ( *memStoreCursor) () {
	if .index >= len(.cmds) {
		return
	}
	for .index++; .index < len(.cmds); .index++ {
		if strings.HasPrefix(.cmds[.index].Text, .prefix) {
			return
		}
	}
}

func ( *memStoreCursor) () (store.Cmd, error) {
	if .index < 0 || .index >= len(.cmds) {
		return store.Cmd{}, ErrEndOfHistory
	}
	return .cmds[.index], nil
}