Documentation
¶
Overview ¶
Package history persists the user's command/message history in an append-only file and provides cursor-based navigation and search over it.
Index ¶
- type History
- func (h *History) Add(message string) error
- func (h *History) FindNextContains(query string, from int) (msg string, idx int, ok bool)
- func (h *History) FindPrevContains(query string, from int) (msg string, idx int, ok bool)
- func (h *History) LatestMatch(prefix string) string
- func (h *History) Next() string
- func (h *History) Previous() string
- func (h *History) SetCurrent(i int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type History ¶
type History struct {
Messages []string
// contains filtered or unexported fields
}
History is the in-memory view of a persistent message history. The cursor (used by History.Previous and History.Next) stays in [0, len(Messages)], where len(Messages) means "past the most recent entry".
func New ¶
New loads the history stored under baseDir/.cagent/history. If baseDir is empty, the user's home directory is used.
func (*History) Add ¶
Add records a new message. Any prior occurrence of the same message is removed and the new one becomes the most recent entry.
func (*History) FindNextContains ¶
FindNextContains searches forward from index from+1 for an entry containing query (case-insensitive). An empty query matches any entry. Pass -1 to start from the oldest entry.
func (*History) FindPrevContains ¶
FindPrevContains searches backward from index from-1 for an entry containing query (case-insensitive). An empty query matches any entry. Pass len(Messages) to start from the most recent entry.
func (*History) LatestMatch ¶
LatestMatch returns the most recent entry that strictly extends prefix, or an empty string when none does.
func (*History) Next ¶
Next moves the cursor one step toward newer entries and returns the entry under it. Past the most recent entry, returns an empty string.
func (*History) Previous ¶
Previous moves the cursor one step toward older entries and returns the entry under it. At the oldest entry, the cursor stays put.
func (*History) SetCurrent ¶
SetCurrent positions the cursor at index i, clamped to [0, len(Messages)]. Keeping the cursor in this range guarantees that subsequent Previous and Next calls never index out of bounds.