mirror of https://github.com/Hilbis/Hilbish
feat: implement history interface
parent
021d20585d
commit
d24d773e2d
8
api.go
8
api.go
|
@ -104,12 +104,12 @@ Check out the {blue}{bold}guide{reset} command to get started.
|
||||||
//util.Document(L, aliasesModule, "Alias inferface for Hilbish.")
|
//util.Document(L, aliasesModule, "Alias inferface for Hilbish.")
|
||||||
mod.Set(rt.StringValue("aliases"), rt.TableValue(aliasesModule))
|
mod.Set(rt.StringValue("aliases"), rt.TableValue(aliasesModule))
|
||||||
|
|
||||||
/*
|
|
||||||
// hilbish.history table
|
// hilbish.history table
|
||||||
historyModule := lr.Loader(L)
|
historyModule := lr.Loader(rtm)
|
||||||
util.Document(L, historyModule, "History interface for Hilbish.")
|
//util.Document(L, historyModule, "History interface for Hilbish.")
|
||||||
L.SetField(mod, "history", historyModule)
|
mod.Set(rt.StringValue("history"), rt.TableValue(historyModule))
|
||||||
|
|
||||||
|
/*
|
||||||
// hilbish.completion table
|
// hilbish.completion table
|
||||||
hshcomp := L.NewTable()
|
hshcomp := L.NewTable()
|
||||||
|
|
||||||
|
|
71
rl.go
71
rl.go
|
@ -5,6 +5,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"hilbish/util"
|
||||||
|
|
||||||
"github.com/maxlandon/readline"
|
"github.com/maxlandon/readline"
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
)
|
)
|
||||||
|
@ -292,58 +294,65 @@ func (lr *lineReader) Resize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lua module
|
// lua module
|
||||||
/*
|
func (lr *lineReader) Loader(rtm *rt.Runtime) *rt.Table {
|
||||||
func (lr *lineReader) Loader(L *lua.LState) *lua.LTable {
|
lrLua := map[string]util.LuaExport{
|
||||||
lrLua := map[string]lua.LGFunction{
|
"add": {lr.luaAddHistory, 1, false},
|
||||||
"add": lr.luaAddHistory,
|
"all": {lr.luaAllHistory, 0, false},
|
||||||
"all": lr.luaAllHistory,
|
"clear": {lr.luaClearHistory, 0, false},
|
||||||
"clear": lr.luaClearHistory,
|
"get": {lr.luaGetHistory, 1, false},
|
||||||
"get": lr.luaGetHistory,
|
"size": {lr.luaSize, 0, false},
|
||||||
"size": lr.luaSize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod := l.SetFuncs(l.NewTable(), lrLua)
|
mod := rt.NewTable()
|
||||||
|
util.SetExports(rtm, mod, lrLua)
|
||||||
|
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *lineReader) luaAddHistory(l *lua.LState) int {
|
func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
cmd := l.CheckString(1)
|
if err := c.Check1Arg(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cmd, err := c.StringArg(0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
lr.AddHistory(cmd)
|
lr.AddHistory(cmd)
|
||||||
|
|
||||||
return 0
|
return c.Next(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *lineReader) luaSize(L *lua.LState) int {
|
func (lr *lineReader) luaSize(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
L.Push(lua.LNumber(fileHist.Len()))
|
return c.PushingNext1(t.Runtime, rt.IntValue(int64(fileHist.Len()))), nil
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *lineReader) luaGetHistory(L *lua.LState) int {
|
func (lr *lineReader) luaGetHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
idx := L.CheckInt(1)
|
if err := c.Check1Arg(); err != nil {
|
||||||
cmd, _ := fileHist.GetLine(idx)
|
return nil, err
|
||||||
L.Push(lua.LString(cmd))
|
}
|
||||||
|
idx, err := c.IntArg(0)
|
||||||
return 1
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *lineReader) luaAllHistory(L *lua.LState) int {
|
cmd, _ := fileHist.GetLine(int(idx))
|
||||||
tbl := L.NewTable()
|
|
||||||
|
return c.PushingNext1(t.Runtime, rt.StringValue(cmd)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lr *lineReader) luaAllHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
tbl := rt.NewTable()
|
||||||
size := fileHist.Len()
|
size := fileHist.Len()
|
||||||
|
|
||||||
for i := 1; i < size; i++ {
|
for i := 1; i < size; i++ {
|
||||||
cmd, _ := fileHist.GetLine(i)
|
cmd, _ := fileHist.GetLine(i)
|
||||||
tbl.Append(lua.LString(cmd))
|
tbl.Set(rt.IntValue(int64(i)), rt.StringValue(cmd))
|
||||||
}
|
}
|
||||||
|
|
||||||
L.Push(tbl)
|
return c.PushingNext1(t.Runtime, rt.TableValue(tbl)), nil
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *lineReader) luaClearHistory(l *lua.LState) int {
|
func (lr *lineReader) luaClearHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
fileHist.clear()
|
fileHist.clear()
|
||||||
return 0
|
return c.Next(), nil
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in New Issue