Compare commits

..

No commits in common. "22d8a615447a2a9e6d486b3c0f5f80d946ad56f5" and "f2a2ac44d64ab6fb67e9515da7ffca449d95fe81" have entirely different histories.

6 changed files with 2 additions and 143 deletions

5
api.go
View File

@ -84,11 +84,6 @@ The nice lil shell for {blue}Lua{reset} fanatics!
util.Document(L, aliasesModule, "Alias inferface for Hilbish.") util.Document(L, aliasesModule, "Alias inferface for Hilbish.")
L.SetField(mod, "aliases", aliasesModule) 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) L.Push(mod)
return 1 return 1

2
lua.go
View File

@ -12,7 +12,7 @@ import (
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
) )
var minimalconf = `hilbish.prompt '& '` var minimalconf = `prompt '& '`
func luaInit() { func luaInit() {
l = lua.NewState() l = lua.NewState()

View File

@ -184,7 +184,6 @@ input:
// If we get a completely random error, print // If we get a completely random error, print
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
} }
oldInput := input
input = strings.TrimSpace(input) input = strings.TrimSpace(input)
if len(input) == 0 { if len(input) == 0 {
@ -203,11 +202,7 @@ input:
} }
} }
} }
handleHistory(input)
// if input has space at the beginning, dont put in history
if !strings.HasPrefix(oldInput, " ") {
handleHistory(input)
}
runInput(input) runInput(input)
termwidth, _, err := term.GetSize(0) termwidth, _, err := term.GetSize(0)

57
rl.go
View File

@ -205,60 +205,3 @@ func (lr *lineReader) ClearInput() {
func (lr *lineReader) Resize() { func (lr *lineReader) Resize() {
readline.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
}

View File

@ -41,40 +41,3 @@ func (lr *lineReader) Resize() {
return 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
}

View File

@ -63,40 +63,3 @@ func (lr *lineReader) Resize() {
return 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
}