Compare commits

..

No commits in common. "4080ba90e95cef5805e48d24b46dc1121155aea2" and "3d525aa7da4c58b9eba91fe65e302e9958c76755" have entirely different histories.

4 changed files with 69 additions and 81 deletions

91
api.go
View File

@ -63,29 +63,12 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
return c.PushingNext1(t.Runtime, val), nil return c.PushingNext1(t.Runtime, val), nil
} }
modNewIndex := func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { modNewIndex := func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
k, err := c.StringArg(1) k := c.Arg(1)
if err != nil {
return nil, err
}
v := c.Arg(2) v := c.Arg(2)
if k == "highlighter" { if modVal := mod.Get(k); modVal != rt.NilValue {
var err error
// fine to assign, since itll be either nil or a closure
highlighter, err = c.ClosureArg(2)
if err != nil {
return nil, errors.New("hilbish.highlighter has to be a function")
}
} else if k == "hinter" {
var err error
hinter, err = c.ClosureArg(2)
if err != nil {
return nil, errors.New("hilbish.hinter has to be a function")
}
} else if modVal := mod.Get(rt.StringValue(k)); modVal != rt.NilValue {
return nil, errors.New("not allowed to override in hilbish table") return nil, errors.New("not allowed to override in hilbish table")
} }
mod.Set(rt.StringValue(k), v) mod.Set(k, v)
return c.Next(), nil return c.Next(), nil
} }
@ -510,7 +493,7 @@ func hlinterval(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// replacing <cmd> with the name of the command (for example `command.git`). // replacing <cmd> with the name of the command (for example `command.git`).
// `cb` must be a function that returns a table of "completion groups." // `cb` must be a function that returns a table of "completion groups."
// A completion group is a table with the keys `items` and `type`. // A completion group is a table with the keys `items` and `type`.
// `items` being a table of items and `type` being the display type, which is // `items` being a table of items and `type` being the display type of
// `grid` (the normal file completion display) or `list` (with a description) // `grid` (the normal file completion display) or `list` (with a description)
// --- @param scope string // --- @param scope string
// --- @param cb function // --- @param cb function
@ -546,27 +529,18 @@ func hlprependPath(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil return c.Next(), nil
} }
// which(name) // which(binName)
// Checks if `name` is a valid command // Searches for an executable called `binName` in the directories of $PATH
// --- @param binName string // --- @param binName string
func hlwhich(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlwhich(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
if err := c.Check1Arg(); err != nil { if err := c.Check1Arg(); err != nil {
return nil, err return nil, err
} }
name, err := c.StringArg(0) binName, err := c.StringArg(0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
path, err := exec.LookPath(binName)
cmd := aliases.Resolve(name)
// check for commander
if commands[cmd] != nil {
// they dont resolve to a path, so just send the cmd
return c.PushingNext1(t.Runtime, rt.StringValue(cmd)), nil
}
path, err := exec.LookPath(cmd)
if err != nil { if err != nil {
return c.Next(), nil return c.Next(), nil
} }
@ -616,6 +590,7 @@ func hlrunnerMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
switch mode.Type() { switch mode.Type() {
case rt.StringType: case rt.StringType:
switch mode.AsString() { switch mode.AsString() {
// no fallthrough doesnt work so eh
case "hybrid", "hybridRev", "lua", "sh": runnerMode = mode case "hybrid", "hybridRev", "lua", "sh": runnerMode = mode
default: return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.AsString()) default: return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.AsString())
} }
@ -626,24 +601,40 @@ func hlrunnerMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil return c.Next(), nil
} }
// hinter(line, pos) // hinter(cb)
// The command line hint handler. It gets called on every key insert to // Sets the hinter function. This will be called on every key insert to determine
// determine what text to use as an inline hint. It is passed the current // what text to use as an inline hint. The callback is passed 2 arguments:
// line and cursor position. It is expected to return a string which is used // the current line and the position. It is expected to return a string
// as the text for the hint. This is by default a shim. To set hints, // which will be used for the hint.
// override this function with your custom handler. // --- @param cb function
// --- @param line string
// --- @param pos int
func hlhinter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlhinter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil if err := c.Check1Arg(); err != nil {
return nil, err
}
hinterCb, err := c.ClosureArg(0)
if err != nil {
return nil, err
}
hinter = hinterCb
return c.Next(), err
} }
// highlighter(line) // highlighter(cb)
// Line highlighter handler. This is mainly for syntax highlighting, but in // Sets the highlighter function. This is mainly for syntax hightlighting, but in
// reality could set the input of the prompt to *display* anything. The // reality could set the input of the prompt to display anything. The callback
// callback is passed the current line and is expected to return a line that // is passed the current line as typed and is expected to return a line that will
// will be used as the input display. // be used to display in the line.
// --- @param line string // --- @param cb function
func hlhighlighter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func hlhighlighter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil if err := c.Check1Arg(); err != nil {
return nil, err
}
highlighterCb, err := c.ClosureArg(0)
if err != nil {
return nil, err
}
highlighter = highlighterCb
return c.Next(), err
} }

View File

@ -7,7 +7,7 @@ A `scope` is currently only expected to be `command.<cmd>`,
replacing <cmd> with the name of the command (for example `command.git`). replacing <cmd> with the name of the command (for example `command.git`).
`cb` must be a function that returns a table of "completion groups." `cb` must be a function that returns a table of "completion groups."
A completion group is a table with the keys `items` and `type`. A completion group is a table with the keys `items` and `type`.
`items` being a table of items and `type` being the display type, which is `items` being a table of items and `type` being the display type of
`grid` (the normal file completion display) or `list` (with a description) `grid` (the normal file completion display) or `list` (with a description)
cwd() > Returns the current directory of the shell cwd() > Returns the current directory of the shell
@ -16,16 +16,15 @@ exec(cmd) > Replaces running hilbish with `cmd`
goro(fn) > Puts `fn` in a goroutine goro(fn) > Puts `fn` in a goroutine
highlighter(line) > Line highlighter handler. This is mainly for syntax highlighting, but in highlighter(cb) > Sets the highlighter function. This is mainly for syntax hightlighting, but in
reality could set the input of the prompt to *display* anything. The reality could set the input of the prompt to display anything. The callback
callback is passed the current line and is expected to return a line that is passed the current line as typed and is expected to return a line that will
will be used as the input display. be used to display in the line.
hinter(line, pos) > The command line hint handler. It gets called on every key insert to hinter(cb) > Sets the hinter function. This will be called on every key insert to determine
determine what text to use as an inline hint. It is passed the current what text to use as an inline hint. The callback is passed 2 arguments:
line and cursor position. It is expected to return a string which is used the current line and the position. It is expected to return a string
as the text for the hint. This is by default a shim. To set hints, which will be used for the hint.
override this function with your custom handler.
inputMode(mode) > Sets the input mode for Hilbish's line reader. Accepts either emacs or vim inputMode(mode) > Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
@ -60,5 +59,5 @@ will call it to execute user input instead.
timeout(cb, time) > Runs the `cb` function after `time` in milliseconds timeout(cb, time) > Runs the `cb` function after `time` in milliseconds
Returns a `timer` object (see `doc timers`). Returns a `timer` object (see `doc timers`).
which(name) > Checks if `name` is a valid command which(binName) > Searches for an executable called `binName` in the directories of $PATH

View File

@ -16,7 +16,7 @@ function hilbish.appendPath(dir) end
--- replacing <cmd> with the name of the command (for example `command.git`). --- replacing <cmd> with the name of the command (for example `command.git`).
--- `cb` must be a function that returns a table of "completion groups." --- `cb` must be a function that returns a table of "completion groups."
--- A completion group is a table with the keys `items` and `type`. --- A completion group is a table with the keys `items` and `type`.
--- `items` being a table of items and `type` being the display type, which is --- `items` being a table of items and `type` being the display type of
--- `grid` (the normal file completion display) or `list` (with a description) --- `grid` (the normal file completion display) or `list` (with a description)
--- @param scope string --- @param scope string
--- @param cb function --- @param cb function
@ -33,21 +33,19 @@ function hilbish.exec(cmd) end
--- @param fn function --- @param fn function
function hilbish.goro(fn) end function hilbish.goro(fn) end
--- Line highlighter handler. This is mainly for syntax highlighting, but in --- Sets the highlighter function. This is mainly for syntax hightlighting, but in
--- reality could set the input of the prompt to *display* anything. The --- reality could set the input of the prompt to display anything. The callback
--- callback is passed the current line and is expected to return a line that --- is passed the current line as typed and is expected to return a line that will
--- will be used as the input display. --- be used to display in the line.
--- @param line string --- @param cb function
function hilbish.highlighter(line) end function hilbish.highlighter(cb) end
--- The command line hint handler. It gets called on every key insert to --- Sets the hinter function. This will be called on every key insert to determine
--- determine what text to use as an inline hint. It is passed the current --- what text to use as an inline hint. The callback is passed 2 arguments:
--- line and cursor position. It is expected to return a string which is used --- the current line and the position. It is expected to return a string
--- as the text for the hint. This is by default a shim. To set hints, --- which will be used for the hint.
--- override this function with your custom handler. --- @param cb function
--- @param line string function hilbish.hinter(cb) end
--- @param pos int
function hilbish.hinter(line, pos) end
--- Sets the input mode for Hilbish's line reader. Accepts either emacs or vim --- Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
--- @param mode string --- @param mode string
@ -105,7 +103,7 @@ function hilbish.runnerMode(mode) end
--- @return table --- @return table
function hilbish.timeout(cb, time) end function hilbish.timeout(cb, time) end
--- Checks if `name` is a valid command --- Searches for an executable called `binName` in the directories of $PATH
--- @param binName string --- @param binName string
function hilbish.which(binName) end function hilbish.which(binName) end

View File

@ -73,7 +73,7 @@ func runInput(input string, priv bool) {
} }
} else { } else {
// can only be a string or function so // can only be a string or function so
term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 3, false) term := rt.NewTerminationWith(l.MainThread().CurrentCont(), 2, false)
err := rt.Call(l.MainThread(), runnerMode, []rt.Value{rt.StringValue(cmdString)}, term) err := rt.Call(l.MainThread(), runnerMode, []rt.Value{rt.StringValue(cmdString)}, term)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
@ -81,9 +81,9 @@ func runInput(input string, priv bool) {
return return
} }
luaInput := term.Get(0) luaexitcode := term.Get(0)
luaexitcode := term.Get(1) runErr := term.Get(1)
runErr := term.Get(2) luaInput := term.Get(1)
var exitCode uint8 var exitCode uint8
if code, ok := luaexitcode.TryInt(); ok { if code, ok := luaexitcode.TryInt(); ok {