diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2171249..28e72a3 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,6 +4,7 @@ on: push: branches: - master + workflow_dispatch: jobs: gen: diff --git a/api.go b/api.go index 8602942..f8136a6 100644 --- a/api.go +++ b/api.go @@ -38,7 +38,6 @@ var exports = map[string]util.LuaExport{ "complete": {hlcomplete, 2, false}, "cwd": {hlcwd, 0, false}, "exec": {hlexec, 1, false}, - "runnerMode": {hlrunnerMode, 1, false}, "goro": {hlgoro, 1, true}, "highlighter": {hlhighlighter, 1, false}, "hinter": {hlhinter, 1, false}, @@ -639,37 +638,6 @@ func hlinputMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), nil } -// runnerMode(mode) -// **NOTE: This function is deprecated and will be removed in 3.0** -// Use `hilbish.runner.setCurrent` instead. -// Sets the execution/runner mode for interactive Hilbish. -// This determines whether Hilbish wll try to run input as Lua -// and/or sh or only do one of either. -// Accepted values for mode are hybrid (the default), hybridRev (sh first then Lua), -// sh, and lua. It also accepts a function, to which if it is passed one -// will call it to execute user input instead. -// Read [about runner mode](../features/runner-mode) for more information. -// #param mode string|function -func hlrunnerMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { - // TODO: Reimplement in Lua - if err := c.Check1Arg(); err != nil { - return nil, err - } - mode := c.Arg(0) - - switch mode.Type() { - case rt.StringType: - switch mode.AsString() { - 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()) - } - case rt.FunctionType: runnerMode = mode - default: return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.TypeName()) - } - - return c.Next(), nil -} - // hinter(line, pos) // The command line hint handler. It gets called on every key insert to // determine what text to use as an inline hint. It is passed the current diff --git a/exec.go b/exec.go index 9819d15..8fd92ea 100644 --- a/exec.go +++ b/exec.go @@ -8,7 +8,6 @@ import ( "strings" "hilbish/util" - //herror "hilbish/errors" rt "github.com/arnodel/golua/runtime" //"github.com/yuin/gopher-lua/parse" @@ -23,13 +22,13 @@ func runInput(input string, priv bool) { cmdString := aliases.Resolve(input) hooks.Emit("command.preexec", input, cmdString) + // save incase it changes while prompting (For some reason) currentRunner := runnerMode rerun: var exitCode uint8 var cont bool var newline bool - // save incase it changes while prompting (For some reason) input, exitCode, cont, newline, runnerErr, err := runLuaRunner(currentRunner, input) if err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/nature/runnerLegacy.lua b/nature/runnerLegacy.lua new file mode 100644 index 0000000..5bd132a --- /dev/null +++ b/nature/runnerLegacy.lua @@ -0,0 +1,34 @@ +-- @module hilbish + +--- **NOTE: This function is deprecated and will be removed in 3.0** +--- Use `hilbish.runner.setCurrent` instead. +--- Sets the execution/runner mode for interactive Hilbish. +--- This determines whether Hilbish wll try to run input as Lua +--- and/or sh or only do one of either. +--- Accepted values for mode are hybrid (the default), hybridRev (sh first then Lua), +--- sh, and lua. It also accepts a function, to which if it is passed one +--- will call it to execute user input instead. +--- Read [about runner mode](../features/runner-mode) for more information. +-- @param mode string|function +function hilbish.runnerMode(mode) + if type(mode) == 'string' then + hilbish.runner.setCurrent(mode) + elseif type(mode) == 'function' then + hilbish.runner.set('_', { + run = mode + }) + hilbish.runner.setCurrent '_' + else + error('expected runner mode type to be either string or function, got', type(mode)) + end +end + +--- **NOTE: This function is deprecated and will be removed in 3.0** +--- Use `hilbish.runner.setCurrent` instead. +--- This is the same as the `hilbish.runnerMode` function. +--- It takes a callback, which will be used to execute all interactive input. +--- Or a string which names the runner mode to use. +-- @param mode string|function +function hilbish.runner.setMode(mode) + hilbish.runnerMode(mode) +end diff --git a/runnermode.go b/runnermode.go index f1e2bf0..9e7a3ff 100644 --- a/runnermode.go +++ b/runnermode.go @@ -53,9 +53,7 @@ end) */ func runnerModeLoader(rtm *rt.Runtime) *rt.Table { exports := map[string]util.LuaExport{ - //"sh": {shRunner, 1, false}, "lua": {luaRunner, 1, false}, - "setMode": {hlrunnerMode, 1, false}, } mod := rt.NewTable() @@ -64,48 +62,6 @@ func runnerModeLoader(rtm *rt.Runtime) *rt.Table { return mod } -// #interface runner -// setMode(cb) -// **NOTE: This function is deprecated and will be removed in 3.0** -// Use `hilbish.runner.setCurrent` instead. -// This is the same as the `hilbish.runnerMode` function. -// It takes a callback, which will be used to execute all interactive input. -// In normal cases, neither callbacks should be overrided by the user, -// as the higher level functions (setCurrent) this will handle it. -// #param cb function -func _runnerMode() {} - -// #interface runner -// sh(cmd) -// Runs a command in Hilbish's shell script interpreter. -// This is the equivalent of using `source`. -// #param cmd string -/* -func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { - if err := c.Check1Arg(); err != nil { - return nil, err - } - cmd, err := c.StringArg(0) - if err != nil { - return nil, err - } - - _, exitCode, cont, newline, err := execSh(aliases.Resolve(cmd)) - var luaErr rt.Value = rt.NilValue - if err != nil { - luaErr = rt.StringValue(err.Error()) - } - runnerRet := rt.NewTable() - runnerRet.Set(rt.StringValue("input"), rt.StringValue(cmd)) - runnerRet.Set(rt.StringValue("exitCode"), rt.IntValue(int64(exitCode))) - runnerRet.Set(rt.StringValue("continue"), rt.BoolValue(cont)) - runnerRet.Set(rt.StringValue("newline"), rt.BoolValue(newline)) - runnerRet.Set(rt.StringValue("err"), luaErr) - - return c.PushingNext(t.Runtime, rt.TableValue(runnerRet)), nil -} -*/ - // #interface runner // lua(cmd) // Evaluates `cmd` as Lua input. This is the same as using `dofile` diff --git a/util/sink.go b/util/sink.go index 69fc594..8d1167e 100644 --- a/util/sink.go +++ b/util/sink.go @@ -14,8 +14,7 @@ import ( var sinkMetaKey = rt.StringValue("hshsink") // #type -// A sink is a structure that has input and/or output to/from -// a desination. +// A sink is a structure that has input and/or output to/from a desination. type Sink struct{ Rw *bufio.ReadWriter file *os.File