2022-12-15 04:00:54 +00:00
|
|
|
---
|
2023-08-26 15:30:51 +00:00
|
|
|
title: Module hilbish.runner
|
2022-12-15 04:00:54 +00:00
|
|
|
description: interactive command runner customization
|
|
|
|
layout: doc
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "API"
|
|
|
|
---
|
|
|
|
|
|
|
|
## Introduction
|
2023-12-26 02:32:37 +00:00
|
|
|
The runner interface contains functions that allow the user to change
|
2022-12-15 04:00:54 +00:00
|
|
|
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.
|
|
|
|
|
2023-12-26 02:32:37 +00:00
|
|
|
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): A numerical code to indicate the exit result.
|
|
|
|
- `input` (string): The user input. This will be used to add
|
|
|
|
to the history.
|
|
|
|
- `err` (string): A string to indicate an interal error for the runner.
|
|
|
|
It can be set to a few special values for Hilbish to throw the right hooks and have a better looking message:
|
|
|
|
|
|
|
|
`[command]: not-found` will throw a command.not-found hook based on what `[command]` is.
|
|
|
|
|
|
|
|
`[command]: not-executable` will throw a command.not-executable hook.
|
|
|
|
- `continue` (boolean): Whether to prompt the user for more input.
|
|
|
|
|
|
|
|
Here is a simple example of a fennel runner. It falls back to
|
|
|
|
shell script if fennel eval has an error.
|
|
|
|
```lua
|
|
|
|
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)
|
|
|
|
```
|
|
|
|
|
2022-12-15 04:00:54 +00:00
|
|
|
## Functions
|
2023-09-02 18:18:40 +00:00
|
|
|
|||
|
|
|
|
|----|----|
|
2023-12-04 00:54:00 +00:00
|
|
|
|<a href="#runner.setMode">setMode(cb)</a>|This is the same as the `hilbish.runnerMode` function.|
|
2023-09-02 18:18:40 +00:00
|
|
|
|<a href="#runner.lua">lua(cmd)</a>|Evaluates `cmd` as Lua input. This is the same as using `dofile`|
|
|
|
|
|<a href="#runner.sh">sh(cmd)</a>|Runs a command in Hilbish's shell script interpreter.|
|
|
|
|
|
2023-12-18 14:16:57 +00:00
|
|
|
<hr>
|
|
|
|
<div id='runner.setMode'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
hilbish.runner.setMode(cb)
|
|
|
|
<a href="#runner.setMode" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
|
|
|
|
2023-12-04 00:54:00 +00:00
|
|
|
This is the same as the `hilbish.runnerMode` function.
|
|
|
|
It takes a callback, which will be used to execute all interactive input.
|
2023-12-02 12:23:49 +00:00
|
|
|
In normal cases, neither callbacks should be overrided by the user,
|
|
|
|
as the higher level functions listed below this will handle it.
|
2023-12-25 23:52:16 +00:00
|
|
|
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
2023-12-04 00:54:00 +00:00
|
|
|
`function` **`cb`**
|
|
|
|
|
|
|
|
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
2023-12-18 14:16:57 +00:00
|
|
|
<hr>
|
|
|
|
<div id='runner.lua'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
hilbish.runner.lua(cmd)
|
|
|
|
<a href="#runner.lua" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2023-12-02 12:23:49 +00:00
|
|
|
Evaluates `cmd` as Lua input. This is the same as using `dofile`
|
|
|
|
or `load`, but is appropriated for the runner interface.
|
2023-12-25 23:52:16 +00:00
|
|
|
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
2023-12-04 00:54:00 +00:00
|
|
|
`string` **`cmd`**
|
|
|
|
|
|
|
|
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|
2023-12-18 14:16:57 +00:00
|
|
|
<hr>
|
|
|
|
<div id='runner.sh'>
|
2023-09-02 18:18:40 +00:00
|
|
|
<h4 class='heading'>
|
|
|
|
hilbish.runner.sh(cmd)
|
|
|
|
<a href="#runner.sh" class='heading-link'>
|
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
</a>
|
|
|
|
</h4>
|
2022-12-15 04:00:54 +00:00
|
|
|
|
2023-12-02 12:23:49 +00:00
|
|
|
Runs a command in Hilbish's shell script interpreter.
|
|
|
|
This is the equivalent of using `source`.
|
2023-12-25 23:52:16 +00:00
|
|
|
|
2023-08-26 15:30:51 +00:00
|
|
|
#### Parameters
|
2023-12-04 00:54:00 +00:00
|
|
|
`string` **`cmd`**
|
|
|
|
|
|
|
|
|
2023-09-02 20:01:57 +00:00
|
|
|
</div>
|
|
|
|
|