Compare commits

..

8 Commits

Author SHA1 Message Date
TorchedSammy 970fe43413
chore: remove newline between replace directives in module file 2021-12-07 18:01:39 -04:00
TorchedSammy 11aaa0cd36
feat: accept a function in complete
the `complete` function will now also accept a nested function in the table
for you to have more fine control over what is suggested and easily
filter specific things
2021-12-07 17:58:56 -04:00
TorchedSammy 6bff669abe
docs(bait): document catchOnce 2021-12-07 17:41:41 -04:00
TorchedSammy c6edbc20af
style: dont explicitly set exitcode to 0 since its the default value 2021-12-07 17:27:07 -04:00
TorchedSammy 82b4fa5e7c
fix(docgen): revert "fix(docgen): trim trailing space from doc comments"
This reverts commit 3f1f698511.
removes the newlines, dont do this for now
2021-12-07 17:08:25 -04:00
TorchedSammy 3f1f698511
fix(docgen): trim trailing space from doc comments 2021-12-07 16:57:53 -04:00
TorchedSammy 3421f286f2
fix: remove index subdoc (resolves #84) 2021-12-07 16:24:55 -04:00
TorchedSammy bfc141f655
fix: add home to recent dirs when visited (cd with no args) 2021-12-07 16:13:05 -04:00
6 changed files with 55 additions and 14 deletions

View File

@ -1,4 +1,6 @@
catch(name, cb) > Catches a hook with `name`. Runs the `cb` when it is thrown
catchOnce(name, cb) > Same as catch, but only runs the `cb` once and then removes the hook
throw(name, ...args) > Throws a hook with `name` with the provided `args`

1
go.mod
View File

@ -22,5 +22,4 @@ require (
)
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20211022004519-f67a49cb50f5
replace github.com/maxlandon/readline => github.com/Rosettea/readline-1 v0.1.0-beta.0.20211207003625-341c7985ad7d

View File

@ -55,7 +55,7 @@ func hilbishLoader(L *lua.LState) int {
// run(cmd)
// Runs `cmd` in Hilbish's sh interpreter
func hlrun(L *lua.LState) int {
var exitcode uint8 = 0
var exitcode uint8
cmd := L.CheckString(1)
err := execCommand(cmd)

View File

@ -37,6 +37,9 @@ commander.register('cd', function (args)
end
fs.cd(hilbish.home)
bait.throw('cd', hilbish.home)
table.insert(recentDirs, 1, hilbish.home)
recentDirs[11] = nil
end)
commander.register('exit', function()
@ -72,7 +75,8 @@ These are the global Hilbish functions that are always available and not part of
return
end
funcdocs = f:read '*a'
local subdocs = table.map(fs.readdir(moddocPath), function(fname)
local moddocs = table.filter(fs.readdir(moddocPath), function(f) return f ~= 'index.txt' end)
local subdocs = table.map(moddocs, function(fname)
return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.txt', '')))
end)
if subdocName == 'index' then

56
rl.go
View File

@ -1,3 +1,4 @@
//go:build !hilbiline && !goreadline
// +build !hilbiline,!goreadline
package main
@ -126,18 +127,53 @@ func newLineReader(prompt string) *lineReader {
if key.String() == fields[1] {
// if value is a table, we need to iterate over it
// and add each value to completions
valueTbl := value.(*lua.LTable)
valueTbl.ForEach(func(key lua.LValue, value lua.LValue) {
val := value.String()
if val == "<file>" {
// complete files
completions = append(completions, readline.FilenameCompleter(query, ctx)...)
} else {
if strings.HasPrefix(val, query) {
completions = append(completions, val)
// check if value is either a table or function
if value.Type() == lua.LTTable {
valueTbl := value.(*lua.LTable)
valueTbl.ForEach(func(key lua.LValue, value lua.LValue) {
val := value.String()
if val == "<file>" {
// complete files
completions = append(completions, readline.FilenameCompleter(query, ctx)...)
} else {
if strings.HasPrefix(val, query) {
completions = append(completions, val)
}
}
})
} else if value.Type() == lua.LTFunction {
// if value is a function, we need to call it
// and add each value to completions
// completionsCtx is the context we pass to the function,
// removing 2 fields from the fields array
completionsCtx := strings.Join(fields[2:], " ")
err := l.CallByParam(lua.P{
Fn: value,
NRet: 1,
Protect: true,
}, lua.LString(query), lua.LString(completionsCtx))
if err != nil {
return
}
})
luacompleteTable := l.Get(-1)
l.Pop(1)
// just check if its actually a table and add it to the completions
if cmpTbl, ok := luacompleteTable.(*lua.LTable); ok {
cmpTbl.ForEach(func(key lua.LValue, value lua.LValue) {
val := value.String()
if strings.HasPrefix(val, query) {
completions = append(completions, val)
}
})
}
} else {
// throw lua error
// complete.cmdname: error message...
l.RaiseError("complete." + fields[0] + ": completion value is not a table or function")
}
}
}
}

View File

@ -133,7 +133,7 @@ func execCommand(cmd string) error {
}
luaexitcode := l.Get(-1)
var exitcode uint8 = 0
var exitcode uint8
l.Pop(1)