mirror of https://github.com/Hilbis/Hilbish
Compare commits
3 Commits
f2a2ac44d6
...
22d8a61544
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 22d8a61544 | |
TorchedSammy | 3f9aad64b5 | |
TorchedSammy | 8c802a6e6b |
5
api.go
5
api.go
|
@ -84,6 +84,11 @@ The nice lil shell for {blue}Lua{reset} fanatics!
|
|||
util.Document(L, aliasesModule, "Alias inferface for Hilbish.")
|
||||
L.SetField(mod, "aliases", aliasesModule)
|
||||
|
||||
// hilbish.history table
|
||||
historyModule := lr.Loader(L)
|
||||
util.Document(L, historyModule, "History interface for Hilbish.")
|
||||
L.SetField(mod, "history", historyModule)
|
||||
|
||||
L.Push(mod)
|
||||
|
||||
return 1
|
||||
|
|
2
lua.go
2
lua.go
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
var minimalconf = `prompt '& '`
|
||||
var minimalconf = `hilbish.prompt '& '`
|
||||
|
||||
func luaInit() {
|
||||
l = lua.NewState()
|
||||
|
|
5
main.go
5
main.go
|
@ -184,6 +184,7 @@ input:
|
|||
// If we get a completely random error, print
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
oldInput := input
|
||||
|
||||
input = strings.TrimSpace(input)
|
||||
if len(input) == 0 {
|
||||
|
@ -202,7 +203,11 @@ input:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if input has space at the beginning, dont put in history
|
||||
if !strings.HasPrefix(oldInput, " ") {
|
||||
handleHistory(input)
|
||||
}
|
||||
runInput(input)
|
||||
|
||||
termwidth, _, err := term.GetSize(0)
|
||||
|
|
57
rl.go
57
rl.go
|
@ -205,3 +205,60 @@ func (lr *lineReader) ClearInput() {
|
|||
func (lr *lineReader) Resize() {
|
||||
readline.Resize()
|
||||
}
|
||||
|
||||
// lua module
|
||||
func (lr *lineReader) Loader(L *lua.LState) *lua.LTable {
|
||||
lrLua := map[string]lua.LGFunction{
|
||||
"add": lr.luaAddHistory,
|
||||
"all": lr.luaAllHistory,
|
||||
"clear": lr.luaClearHistory,
|
||||
"get": lr.luaGetHistory,
|
||||
"size": lr.luaSize,
|
||||
}
|
||||
|
||||
mod := L.SetFuncs(L.NewTable(), lrLua)
|
||||
|
||||
return mod
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaAddHistory(l *lua.LState) int {
|
||||
cmd := l.CheckString(1)
|
||||
lr.AddHistory(cmd)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaSize(l *lua.LState) int {
|
||||
l.Push(lua.LNumber(readline.HistorySize()))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaGetHistory(l *lua.LState) int {
|
||||
idx := l.CheckInt(1)
|
||||
cmd := readline.GetHistory(idx)
|
||||
l.Push(lua.LString(cmd))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaAllHistory(l *lua.LState) int {
|
||||
tbl := l.NewTable()
|
||||
size := readline.HistorySize()
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
cmd := readline.GetHistory(i)
|
||||
tbl.Append(lua.LString(cmd))
|
||||
}
|
||||
|
||||
l.Push(tbl)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaClearHistory(l *lua.LState) int {
|
||||
readline.ClearHistory()
|
||||
readline.SaveHistory(defaultHistPath)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -41,3 +41,40 @@ func (lr *lineReader) Resize() {
|
|||
return
|
||||
}
|
||||
|
||||
// lua module
|
||||
func (lr *lineReader) Loader() *lua.LTable {
|
||||
lrLua := map[string]lua.LGFunction{
|
||||
"add": lr.luaAddHistory,
|
||||
"all": lr.luaAllHistory,
|
||||
"clear": lr.luaClearHistory,
|
||||
"get": lr.luaGetHistory,
|
||||
"size": lr.luaSize,
|
||||
}
|
||||
|
||||
mod := l.SetFuncs(l.NewTable(), lrLua)
|
||||
|
||||
return mod
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaAddHistory(l *lua.LState) int {
|
||||
cmd := l.CheckString(1)
|
||||
lr.AddHistory(cmd)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaSize(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaGetHistory(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaAllHistory(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaClearHistory(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -63,3 +63,40 @@ func (lr *lineReader) Resize() {
|
|||
return
|
||||
}
|
||||
|
||||
// lua module
|
||||
func (lr *lineReader) Loader() *lua.LTable {
|
||||
lrLua := map[string]lua.LGFunction{
|
||||
"add": lr.luaAddHistory,
|
||||
"all": lr.luaAllHistory,
|
||||
"clear": lr.luaClearHistory,
|
||||
"get": lr.luaGetHistory,
|
||||
"size": lr.luaSize,
|
||||
}
|
||||
|
||||
mod := l.SetFuncs(l.NewTable(), lrLua)
|
||||
|
||||
return mod
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaAddHistory(l *lua.LState) int {
|
||||
cmd := l.CheckString(1)
|
||||
lr.AddHistory(cmd)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaSize(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaGetHistory(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaAllHistory(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (lr *lineReader) luaClearHistory(l *lua.LState) int {
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue