mirror of https://github.com/Hilbis/Hilbish
docs: add docs for hilbish.runner interface
parent
309b7605e3
commit
66c1eb95cd
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
name: Interface hilbish.runner
|
||||||
|
description: interactive command runner customization
|
||||||
|
layout: apidoc
|
||||||
|
---
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
### setMode(cb)
|
||||||
|
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 listed below this will handle it.
|
||||||
|
|
||||||
|
### lua(cmd)
|
||||||
|
Evaluates `cmd` as Lua input. This is the same as using `dofile`
|
||||||
|
or `load`, but is appropriated for the runner interface.
|
||||||
|
|
||||||
|
### sh(cmd)
|
||||||
|
Runs a command in Hilbish's shell script interpreter.
|
||||||
|
This is the equivalent of using `source`.
|
||||||
|
|
|
@ -7,6 +7,12 @@ local hilbish = {}
|
||||||
--- @param cmd string
|
--- @param cmd string
|
||||||
function hilbish.aliases.add(alias, cmd) end
|
function hilbish.aliases.add(alias, cmd) end
|
||||||
|
|
||||||
|
--- 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 listed below this will handle it.
|
||||||
|
function hilbish.runner.setMode(cb) end
|
||||||
|
|
||||||
--- Calls a completer function. This is mainly used to call
|
--- Calls a completer function. This is mainly used to call
|
||||||
--- a command completer, which will have a `name` in the form
|
--- a command completer, which will have a `name` in the form
|
||||||
--- of `command.name`, example: `command.git`
|
--- of `command.name`, example: `command.git`
|
||||||
|
@ -128,6 +134,14 @@ function hilbish.completions.bins(query, ctx, fields) end
|
||||||
--- Returns file completion candidates based on the provided query.
|
--- Returns file completion candidates based on the provided query.
|
||||||
function hilbish.completions.files(query, ctx, fields) end
|
function hilbish.completions.files(query, ctx, fields) end
|
||||||
|
|
||||||
|
--- Evaluates `cmd` as Lua input. This is the same as using `dofile`
|
||||||
|
--- or `load`, but is appropriated for the runner interface.
|
||||||
|
function hilbish.runner.lua(cmd) end
|
||||||
|
|
||||||
|
--- Runs a command in Hilbish's shell script interpreter.
|
||||||
|
--- This is the equivalent of using `source`.
|
||||||
|
function hilbish.runner.sh(cmd) end
|
||||||
|
|
||||||
--- Stops a timer.
|
--- Stops a timer.
|
||||||
function hilbish.timers:stop() end
|
function hilbish.timers:stop() end
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,13 @@ import (
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// #interface runner
|
||||||
|
// interactive command runner customization
|
||||||
|
// 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.
|
||||||
func runnerModeLoader(rtm *rt.Runtime) *rt.Table {
|
func runnerModeLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
exports := map[string]util.LuaExport{
|
exports := map[string]util.LuaExport{
|
||||||
"sh": {shRunner, 1, false},
|
"sh": {shRunner, 1, false},
|
||||||
|
@ -19,6 +26,18 @@ func runnerModeLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #interface runner
|
||||||
|
// setMode(cb)
|
||||||
|
// 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 listed below this will handle it.
|
||||||
|
func _runnerMode() {}
|
||||||
|
|
||||||
|
// #interface runner
|
||||||
|
// sh(cmd)
|
||||||
|
// Runs a command in Hilbish's shell script interpreter.
|
||||||
|
// This is the equivalent of using `source`.
|
||||||
func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func shRunner(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
|
||||||
|
@ -42,6 +61,10 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.PushingNext(t.Runtime, rt.TableValue(runnerRet)), nil
|
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`
|
||||||
|
// or `load`, but is appropriated for the runner interface.
|
||||||
func luaRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func luaRunner(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
|
||||||
|
|
Loading…
Reference in New Issue