diff --git a/docs/api/hilbish/hilbish.history.md b/docs/api/hilbish/hilbish.history.md index a0de417..f20aaef 100644 --- a/docs/api/hilbish/hilbish.history.md +++ b/docs/api/hilbish/hilbish.history.md @@ -9,3 +9,16 @@ The history interface deals with command history. This includes the ability to override functions to change the main method of saving history. +## Functions +### add(cmd) +Adds a command to the history. + +### clear() +Deletes all commands from the history. + +### get(idx) +Retrieves a command from the history based on the `idx`. + +### size() +Returns the amount of commands in the history. + diff --git a/emmyLuaDocs/hilbish.lua b/emmyLuaDocs/hilbish.lua index fdd7b38..8fefd60 100644 --- a/emmyLuaDocs/hilbish.lua +++ b/emmyLuaDocs/hilbish.lua @@ -3,6 +3,8 @@ local hilbish = {} --- This is an alias (ha) for the `hilbish.alias` function. +--- @param alias string +--- @param cmd string function hilbish.aliases.add(alias, cmd) end --- Sets an alias of `cmd` to `orig` @@ -125,4 +127,19 @@ function hilbish.aliases.list() end --- @param alias string function hilbish.aliases.resolve(alias) end +--- Adds a command to the history. +--- @param cmd string +function hilbish.history.add(cmd) end + +--- Deletes all commands from the history. +function hilbish.history.clear() end + +--- Retrieves a command from the history based on the `idx`. +--- @param idx number +function hilbish.history.get(idx) end + +--- Returns the amount of commands in the history. +--- @returns number +function hilbish.history.size() end + return hilbish diff --git a/rl.go b/rl.go index 8ec711c..6356f64 100644 --- a/rl.go +++ b/rl.go @@ -245,6 +245,10 @@ func (lr *lineReader) Loader(rtm *rt.Runtime) *rt.Table { return mod } +// #interface history +// add(cmd) +// Adds a command to the history. +// --- @param cmd string func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err @@ -258,10 +262,18 @@ func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) return c.Next(), nil } +// #interface history +// size() +// Returns the amount of commands in the history. +// --- @returns number func (lr *lineReader) luaSize(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.PushingNext1(t.Runtime, rt.IntValue(int64(lr.fileHist.Len()))), nil } +// #interface history +// get(idx) +// Retrieves a command from the history based on the `idx`. +// --- @param idx number func (lr *lineReader) luaGetHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err @@ -288,6 +300,9 @@ func (lr *lineReader) luaAllHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) return c.PushingNext1(t.Runtime, rt.TableValue(tbl)), nil } +// #interface history +// clear() +// Deletes all commands from the history. func (lr *lineReader) luaClearHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { lr.fileHist.clear() return c.Next(), nil