mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "2790982ad123115c6ddbc5764677fdca27668cea" and "984b8a430891781618ff5ccabda227501cfa4744" have entirely different histories.
2790982ad1
...
984b8a4308
79
complete.go
79
complete.go
|
@ -131,9 +131,84 @@ func completionLoader(rtm *rt.Runtime) *rt.Table {
|
|||
return mod
|
||||
}
|
||||
|
||||
// left as a shim, might doc in the same way as hilbish functions
|
||||
func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
return c.Next(), nil
|
||||
if err := c.CheckNArgs(2); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
line, err := c.StringArg(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// just for validation
|
||||
_, err = c.IntArg(1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx := strings.TrimLeft(line, " ")
|
||||
if len(ctx) == 0 {
|
||||
return c.PushingNext(t.Runtime, rt.TableValue(rt.NewTable()), rt.StringValue("")), nil
|
||||
}
|
||||
|
||||
ctx = aliases.Resolve(ctx)
|
||||
fields := strings.Split(ctx, " ")
|
||||
query := fields[len(fields) - 1]
|
||||
|
||||
luaFields := rt.NewTable()
|
||||
|
||||
for i, f := range fields {
|
||||
luaFields.Set(rt.IntValue(int64(i + 1)), rt.StringValue(f))
|
||||
}
|
||||
|
||||
compMod := hshMod.Get(rt.StringValue("completion")).AsTable()
|
||||
var term *rt.Termination
|
||||
if len(fields) == 1 {
|
||||
term = rt.NewTerminationWith(t.CurrentCont(), 2, false)
|
||||
err := rt.Call(t, compMod.Get(rt.StringValue("bins")), []rt.Value{
|
||||
rt.StringValue(query),
|
||||
rt.StringValue(ctx),
|
||||
rt.TableValue(luaFields),
|
||||
}, term)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
gterm := rt.NewTerminationWith(t.CurrentCont(), 2, false)
|
||||
err := rt.Call(t, compMod.Get(rt.StringValue("call")), []rt.Value{
|
||||
rt.StringValue("commands." + fields[0]),
|
||||
rt.StringValue(query),
|
||||
rt.StringValue(ctx),
|
||||
rt.TableValue(luaFields),
|
||||
}, gterm)
|
||||
|
||||
if err == nil {
|
||||
groups := gterm.Get(0)
|
||||
pfx := gterm.Get(1)
|
||||
|
||||
return c.PushingNext(t.Runtime, groups, pfx), nil
|
||||
}
|
||||
|
||||
// error means there isnt a command handler - default to files in that case
|
||||
term = rt.NewTerminationWith(t.CurrentCont(), 2, false)
|
||||
err = rt.Call(t, compMod.Get(rt.StringValue("files")), []rt.Value{
|
||||
rt.StringValue(query),
|
||||
rt.StringValue(ctx),
|
||||
rt.TableValue(luaFields),
|
||||
}, term)
|
||||
}
|
||||
|
||||
comps := term.Get(0)
|
||||
pfx := term.Get(1)
|
||||
|
||||
groups := rt.NewTable()
|
||||
|
||||
compGroup := rt.NewTable()
|
||||
compGroup.Set(rt.StringValue("items"), comps)
|
||||
compGroup.Set(rt.StringValue("type"), rt.StringValue("grid"))
|
||||
|
||||
groups.Set(rt.IntValue(1), rt.TableValue(compGroup))
|
||||
return c.PushingNext(t.Runtime, rt.TableValue(groups), pfx), nil
|
||||
}
|
||||
|
||||
func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
A bit after creation, we have the outside nature. Little plants, seeds,
|
||||
growing to their final phase: a full plant. A lot of Hilbish itself is
|
||||
written in Go, but there are parts made in Lua, being the `doc` command,
|
||||
command not executable/found hooks to print a message in the shell,
|
||||
and other things.
|
||||
|
||||
Hilbish's Lua core module is called `nature`. It's handled after everything
|
||||
on the Go side initializes, which is what that first sentence was from.
|
||||
|
||||
# Nature Modules
|
||||
Currently, `nature` provides 1 intended public module: `nature.dirs`.
|
||||
It is a simple API for managing recent directories and old
|
||||
current working directory.
|
2
main.go
2
main.go
|
@ -62,7 +62,7 @@ func main() {
|
|||
if defaultHistDir == "" {
|
||||
defaultHistDir = filepath.Join(userDataDir, "hilbish")
|
||||
} else {
|
||||
defaultHistDir = filepath.Join(expandHome(defaultHistDir), "hilbish")
|
||||
defaultHistDir = expandHome(defaultHistDir)
|
||||
}
|
||||
defaultHistPath = filepath.Join(defaultHistDir, ".hilbish-history")
|
||||
helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
function hilbish.completion.handler(line, pos)
|
||||
if type(line) ~= 'string' then error '#1 must be a string' end
|
||||
if type(pos) ~= 'number' then error '#2 must be a number' end
|
||||
|
||||
-- trim leading whitespace
|
||||
local ctx = line:gsub('^%s*(.-)$', '%1')
|
||||
if ctx:len() == 0 then return {}, '' end
|
||||
|
||||
local res = hilbish.aliases.resolve(ctx)
|
||||
local resFields = string.split(res, ' ')
|
||||
local fields = string.split(ctx, ' ')
|
||||
if #fields > 1 and #resFields > 1 then
|
||||
fields = resFields
|
||||
end
|
||||
local query = fields[#fields]
|
||||
|
||||
if #fields == 1 then
|
||||
local comps, pfx = hilbish.completion.bins(query, ctx, fields)
|
||||
local compGroup = {
|
||||
items = comps,
|
||||
type = 'grid'
|
||||
}
|
||||
|
||||
return {compGroup}, pfx
|
||||
else
|
||||
local ok, compGroups, pfx = pcall(hilbish.completion.call,
|
||||
'command.' .. #fields[1], query, ctx, fields)
|
||||
if ok then
|
||||
return compGroups, pfx
|
||||
end
|
||||
|
||||
local comps, pfx = hilbish.completion.files(query, ctx, fields)
|
||||
local compGroup = {
|
||||
items = comps,
|
||||
type = 'grid'
|
||||
}
|
||||
|
||||
return {compGroup}, pfx
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue