mirror of https://github.com/Hilbis/Hilbish
docs: document history interface
parent
9d5f6de064
commit
2ee506f958
|
@ -9,3 +9,16 @@ The history interface deals with command history.
|
||||||
This includes the ability to override functions to change the main
|
This includes the ability to override functions to change the main
|
||||||
method of saving history.
|
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.
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
local hilbish = {}
|
local hilbish = {}
|
||||||
|
|
||||||
--- This is an alias (ha) for the `hilbish.alias` function.
|
--- This is an alias (ha) for the `hilbish.alias` function.
|
||||||
|
--- @param alias string
|
||||||
|
--- @param cmd string
|
||||||
function hilbish.aliases.add(alias, cmd) end
|
function hilbish.aliases.add(alias, cmd) end
|
||||||
|
|
||||||
--- Sets an alias of `cmd` to `orig`
|
--- Sets an alias of `cmd` to `orig`
|
||||||
|
@ -125,4 +127,19 @@ function hilbish.aliases.list() end
|
||||||
--- @param alias string
|
--- @param alias string
|
||||||
function hilbish.aliases.resolve(alias) end
|
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
|
return hilbish
|
||||||
|
|
15
rl.go
15
rl.go
|
@ -245,6 +245,10 @@ func (lr *lineReader) Loader(rtm *rt.Runtime) *rt.Table {
|
||||||
return mod
|
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) {
|
func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
if err := c.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -258,10 +262,18 @@ func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error)
|
||||||
return c.Next(), nil
|
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) {
|
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
|
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) {
|
func (lr *lineReader) luaGetHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
if err := c.Check1Arg(); err != nil {
|
||||||
return nil, err
|
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
|
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) {
|
func (lr *lineReader) luaClearHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
lr.fileHist.clear()
|
lr.fileHist.clear()
|
||||||
return c.Next(), nil
|
return c.Next(), nil
|
||||||
|
|
Loading…
Reference in New Issue