Module hilbish.runner
Introduction
The runner interface contains functions that allow the user to change how Hilbish interprets interactive input. Users can add and change the default runner for interactive input to any language or script of their choosing. A good example is using it to write command in Fennel.
Runners are functions that evaluate user input. The default runners in Hilbish can run shell script and Lua code.
A runner is passed the input and has to return a table with these values.
All are not required, only the useful ones the runner needs to return.
(So if there isn’t an error, just omit err.)
exitCode(number): Exit code of the commandinput(string): The text input of the user. This is used by Hilbish to append extra input, in case more is requested.err(string): A string that represents an error from the runner. This should only be set when, for example, there is a syntax error. It can be set to a few special values for Hilbish to throw the right hooks and have a better looking message.\<command>: not-foundwill throw acommand.not-foundhook based on what\<command>is.\<command>: not-executablewill throw acommand.not-executablehook.
continue(boolean): Whether Hilbish should prompt the user for no inputnewline(boolean): Whether a newline should be added at the end ofinput.
Here is a simple example of a fennel runner. It falls back to shell script if fennel eval has an error.
local fennel = require 'fennel'
hilbish.runnerMode(function(input)
local ok = pcall(fennel.eval, input)
if ok then
return {
input = input
}
end
return hilbish.runner.sh(input)
end)
Functions
| lua(cmd) | Evaluates cmd as Lua input. This is the same as using dofile |
| sh() | nil |
| setMode(mode) | NOTE: This function is deprecated and will be removed in 3.0 |
| setCurrent(name) | Sets Hilbish’s runner mode by name. |
| set(name, runner) | Sets a runner by name. The difference between this function and |
| run(input, priv) | Runs input with the currently set Hilbish runner. |
| getCurrent() | Returns the current runner by name. |
| get(name) | Get a runner by name. |
| exec(cmd, runnerName) | Executes cmd with a runner. |
| add(name, runner) | Adds a runner to the table of available runners. |
hilbish.runner.lua(cmd)
Evaluates cmd as Lua input. This is the same as using dofile
or load, but is appropriated for the runner interface.
Parameters
string cmd
hilbish.runner.add(name, runner)
Adds a runner to the table of available runners. If runner is a table, it must have the run function in it.
Parameters
name string
Name of the runner
runner function|table
hilbish.runner.exec(cmd, runnerName)
Executes cmd with a runner.
If runnerName is not specified, it uses the default Hilbish runner.
Parameters
cmd string
runnerName string?
hilbish.runner.get(name)
Get a runner by name.
Parameters
name string
Name of the runner to retrieve.
hilbish.runner.getCurrent()
Returns the current runner by name.
Parameters
This function has no parameters.
hilbish.runner.run(input, priv)
Runs input with the currently set Hilbish runner.
This method is how Hilbish executes commands.
priv is an optional boolean used to state if the input should be saved to history.
Parameters
input string
priv bool
hilbish.runner.set(name, runner)
Sets a runner by name. The difference between this function and add, is set will not check if the named runner exists. The runner table must have the run function in it.
Parameters
name string
runner table
hilbish.runner.setMode(mode)
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.
Parameters
mode string|function