mirror of https://github.com/Hilbis/Hilbish
fix: use slice for doc pieces instead of a map
a map doesnt have a fixed order which results in a new order everytime docs are generated. i forgot that important detail..docs-refactor
parent
aa43515213
commit
079bedc6dc
|
@ -26,7 +26,7 @@ type emmyPiece struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type module struct {
|
type module struct {
|
||||||
Docs map[string]docPiece
|
Docs []docPiece
|
||||||
ShortDescription string
|
ShortDescription string
|
||||||
Description string
|
Description string
|
||||||
Interface bool
|
Interface bool
|
||||||
|
@ -119,19 +119,19 @@ func main() {
|
||||||
|
|
||||||
for l, f := range pkgs {
|
for l, f := range pkgs {
|
||||||
p := doc.New(f, "./", doc.AllDecls)
|
p := doc.New(f, "./", doc.AllDecls)
|
||||||
pieces := make(map[string]docPiece)
|
pieces := []docPiece{}
|
||||||
mod := l
|
mod := l
|
||||||
for _, t := range p.Funcs {
|
for _, t := range p.Funcs {
|
||||||
piece := setupDoc(mod, t)
|
piece := setupDoc(mod, t)
|
||||||
if piece != nil {
|
if piece != nil {
|
||||||
pieces[piece.FuncName] = *piece
|
pieces = append(pieces, *piece)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, t := range p.Types {
|
for _, t := range p.Types {
|
||||||
for _, m := range t.Methods {
|
for _, m := range t.Methods {
|
||||||
piece := setupDoc(mod, m)
|
piece := setupDoc(mod, m)
|
||||||
if piece != nil {
|
if piece != nil {
|
||||||
pieces[piece.FuncName] = *piece
|
pieces = append(pieces, *piece)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,6 @@ func main() {
|
||||||
if mod == "main" {
|
if mod == "main" {
|
||||||
modN = "hilbish"
|
modN = "hilbish"
|
||||||
}
|
}
|
||||||
fmt.Println(mod)
|
|
||||||
f, _ := os.Create("docs/api/" + modN + ".md")
|
f, _ := os.Create("docs/api/" + modN + ".md")
|
||||||
f.WriteString(fmt.Sprintf(header, modN, v.ShortDescription))
|
f.WriteString(fmt.Sprintf(header, modN, v.ShortDescription))
|
||||||
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n## Functions\n", v.Description))
|
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n## Functions\n", v.Description))
|
||||||
|
@ -168,8 +167,12 @@ func main() {
|
||||||
ff, _ := os.Create("emmyLuaDocs/" + modN + ".lua")
|
ff, _ := os.Create("emmyLuaDocs/" + modN + ".lua")
|
||||||
ff.WriteString("--- @meta\n\nlocal " + modN + " = {}\n\n")
|
ff.WriteString("--- @meta\n\nlocal " + modN + " = {}\n\n")
|
||||||
for _, em := range emmyDocs[mod] {
|
for _, em := range emmyDocs[mod] {
|
||||||
funcdocs := v.Docs[em.FuncName].Doc
|
funcdocs := []string{}
|
||||||
fmt.Println(funcdocs)
|
for _, dps := range docs[mod].Docs{
|
||||||
|
if dps.FuncName == em.FuncName {
|
||||||
|
funcdocs = dps.Doc
|
||||||
|
}
|
||||||
|
}
|
||||||
ff.WriteString("--- " + strings.Join(funcdocs, "\n--- ") + "\n")
|
ff.WriteString("--- " + strings.Join(funcdocs, "\n--- ") + "\n")
|
||||||
if len(em.Docs) != 0 {
|
if len(em.Docs) != 0 {
|
||||||
ff.WriteString(strings.Join(em.Docs, "\n") + "\n")
|
ff.WriteString(strings.Join(em.Docs, "\n") + "\n")
|
||||||
|
|
|
@ -1,31 +1,91 @@
|
||||||
---
|
---
|
||||||
name: Module bait
|
name: Module bait
|
||||||
description: the event emitter
|
description: the core Hilbish API
|
||||||
layout: apidoc
|
layout: apidoc
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
Bait is the event emitter for Hilbish. Why name it bait? Why not.
|
The Hilbish module includes the core API, containing
|
||||||
It throws hooks that you can catch. This is what you will use if
|
interfaces and functions which directly relate to shell functionality.
|
||||||
you want to listen in on hooks to know when certain things have
|
|
||||||
happened, like when you've changed directory, a command has failed,
|
|
||||||
etc. To find all available hooks thrown by Hilbish, see doc hooks.
|
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### catchOnce(name, cb)
|
### alias(cmd, orig)
|
||||||
Same as catch, but only runs the `cb` once and then removes the hook
|
Sets an alias of `cmd` to `orig`
|
||||||
|
|
||||||
### hooks(name) -> {cb, cb...}
|
### appendPath(dir)
|
||||||
Returns a table with hooks on the event with `name`.
|
Appends `dir` to $PATH
|
||||||
|
|
||||||
### release(name, catcher)
|
### complete(scope, cb)
|
||||||
Removes the `catcher` for the event with `name`
|
Registers a completion handler for `scope`.
|
||||||
For this to work, `catcher` has to be the same function used to catch
|
A `scope` is currently only expected to be `command.<cmd>`,
|
||||||
an event, like one saved to a variable.
|
replacing <cmd> with the name of the command (for example `command.git`).
|
||||||
|
`cb` must be a function that returns a table of "completion groups."
|
||||||
|
Check `doc completions` for more information.
|
||||||
|
|
||||||
### throw(name, ...args)
|
### cwd()
|
||||||
Throws a hook with `name` with the provided `args`
|
Returns the current directory of the shell
|
||||||
|
|
||||||
### catch(name, cb)
|
### exec(cmd)
|
||||||
Catches a hook with `name`. Runs the `cb` when it is thrown
|
Replaces running hilbish with `cmd`
|
||||||
|
|
||||||
|
### goro(fn)
|
||||||
|
Puts `fn` in a goroutine
|
||||||
|
|
||||||
|
### highlighter(line)
|
||||||
|
Line highlighter handler. This is mainly for syntax highlighting, but in
|
||||||
|
reality could set the input of the prompt to *display* anything. The
|
||||||
|
callback is passed the current line and is expected to return a line that
|
||||||
|
will be used as the input display.
|
||||||
|
|
||||||
|
### 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
|
||||||
|
line and cursor position. It is expected to return a string which is used
|
||||||
|
as the text for the hint. This is by default a shim. To set hints,
|
||||||
|
override this function with your custom handler.
|
||||||
|
|
||||||
|
### inputMode(mode)
|
||||||
|
Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
|
||||||
|
|
||||||
|
### interval(cb, time)
|
||||||
|
Runs the `cb` function every `time` milliseconds.
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### multiprompt(str)
|
||||||
|
Changes the continued line prompt to `str`
|
||||||
|
|
||||||
|
### prependPath(dir)
|
||||||
|
Prepends `dir` to $PATH
|
||||||
|
|
||||||
|
### prompt(str, typ?)
|
||||||
|
Changes the shell prompt to `str`
|
||||||
|
There are a few verbs that can be used in the prompt text.
|
||||||
|
These will be formatted and replaced with the appropriate values.
|
||||||
|
`%d` - Current working directory
|
||||||
|
`%u` - Name of current user
|
||||||
|
`%h` - Hostname of device
|
||||||
|
|
||||||
|
### read(prompt?) -> input?
|
||||||
|
Read input from the user, using Hilbish's line editor/input reader.
|
||||||
|
This is a separate instance from the one Hilbish actually uses.
|
||||||
|
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||||
|
|
||||||
|
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
||||||
|
Runs `cmd` in Hilbish's sh interpreter.
|
||||||
|
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
||||||
|
3rd values instead of being outputted to the terminal.
|
||||||
|
|
||||||
|
### runnerMode(mode)
|
||||||
|
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.
|
||||||
|
|
||||||
|
### timeout(cb, time)
|
||||||
|
Runs the `cb` function after `time` in milliseconds
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### which(name)
|
||||||
|
Checks if `name` is a valid command
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
---
|
---
|
||||||
name: Module commander
|
name: Module commander
|
||||||
description: library for custom commands
|
description: low level terminal library
|
||||||
layout: apidoc
|
layout: apidoc
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
Commander is a library for writing custom commands in Lua.
|
The terminal library is a simple and lower level library for certain terminal interactions.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### deregister(name)
|
### restoreState()
|
||||||
Deregisters any command registered with `name`
|
Restores the last saved state of the terminal
|
||||||
|
|
||||||
### register(name, cb)
|
### saveState()
|
||||||
Register a command with `name` that runs `cb` when ran
|
Saves the current state of the terminal
|
||||||
|
|
||||||
|
### setRaw()
|
||||||
|
Puts the terminal in raw mode
|
||||||
|
|
||||||
|
### size()
|
||||||
|
Gets the dimensions of the terminal. Returns a table with `width` and `height`
|
||||||
|
Note: this is not the size in relation to the dimensions of the display
|
||||||
|
|
||||||
|
|
100
docs/api/fs.md
100
docs/api/fs.md
|
@ -1,43 +1,91 @@
|
||||||
---
|
---
|
||||||
name: Module fs
|
name: Module fs
|
||||||
description: filesystem interaction and functionality library
|
description: the core Hilbish API
|
||||||
layout: apidoc
|
layout: apidoc
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
The fs module provides easy and simple access to filesystem functions
|
The Hilbish module includes the core API, containing
|
||||||
and other things, and acts an addition to the Lua standard library's
|
interfaces and functions which directly relate to shell functionality.
|
||||||
I/O and filesystem functions.
|
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### basename(path)
|
### alias(cmd, orig)
|
||||||
Gives the basename of `path`. For the rules,
|
Sets an alias of `cmd` to `orig`
|
||||||
see Go's filepath.Base
|
|
||||||
|
|
||||||
### cd(dir)
|
### appendPath(dir)
|
||||||
Changes directory to `dir`
|
Appends `dir` to $PATH
|
||||||
|
|
||||||
### dir(path)
|
### complete(scope, cb)
|
||||||
Returns the directory part of `path`. For the rules, see Go's
|
Registers a completion handler for `scope`.
|
||||||
filepath.Dir
|
A `scope` is currently only expected to be `command.<cmd>`,
|
||||||
|
replacing <cmd> with the name of the command (for example `command.git`).
|
||||||
|
`cb` must be a function that returns a table of "completion groups."
|
||||||
|
Check `doc completions` for more information.
|
||||||
|
|
||||||
### readdir(dir)
|
### cwd()
|
||||||
Returns a table of files in `dir`
|
Returns the current directory of the shell
|
||||||
|
|
||||||
### abs(path)
|
### exec(cmd)
|
||||||
Gives an absolute version of `path`.
|
Replaces running hilbish with `cmd`
|
||||||
|
|
||||||
### glob(pattern)
|
### goro(fn)
|
||||||
Glob all files and directories that match the pattern.
|
Puts `fn` in a goroutine
|
||||||
For the rules, see Go's filepath.Glob
|
|
||||||
|
|
||||||
### join(paths...)
|
### highlighter(line)
|
||||||
Takes paths and joins them together with the OS's
|
Line highlighter handler. This is mainly for syntax highlighting, but in
|
||||||
directory separator (forward or backward slash).
|
reality could set the input of the prompt to *display* anything. The
|
||||||
|
callback is passed the current line and is expected to return a line that
|
||||||
|
will be used as the input display.
|
||||||
|
|
||||||
### mkdir(name, recursive)
|
### hinter(line, pos)
|
||||||
Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
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
|
||||||
|
line and cursor position. It is expected to return a string which is used
|
||||||
|
as the text for the hint. This is by default a shim. To set hints,
|
||||||
|
override this function with your custom handler.
|
||||||
|
|
||||||
### stat(path)
|
### inputMode(mode)
|
||||||
Returns info about `path`
|
Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
|
||||||
|
|
||||||
|
### interval(cb, time)
|
||||||
|
Runs the `cb` function every `time` milliseconds.
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### multiprompt(str)
|
||||||
|
Changes the continued line prompt to `str`
|
||||||
|
|
||||||
|
### prependPath(dir)
|
||||||
|
Prepends `dir` to $PATH
|
||||||
|
|
||||||
|
### prompt(str, typ?)
|
||||||
|
Changes the shell prompt to `str`
|
||||||
|
There are a few verbs that can be used in the prompt text.
|
||||||
|
These will be formatted and replaced with the appropriate values.
|
||||||
|
`%d` - Current working directory
|
||||||
|
`%u` - Name of current user
|
||||||
|
`%h` - Hostname of device
|
||||||
|
|
||||||
|
### read(prompt?) -> input?
|
||||||
|
Read input from the user, using Hilbish's line editor/input reader.
|
||||||
|
This is a separate instance from the one Hilbish actually uses.
|
||||||
|
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||||
|
|
||||||
|
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
||||||
|
Runs `cmd` in Hilbish's sh interpreter.
|
||||||
|
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
||||||
|
3rd values instead of being outputted to the terminal.
|
||||||
|
|
||||||
|
### runnerMode(mode)
|
||||||
|
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.
|
||||||
|
|
||||||
|
### timeout(cb, time)
|
||||||
|
Runs the `cb` function after `time` in milliseconds
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### which(name)
|
||||||
|
Checks if `name` is a valid command
|
||||||
|
|
||||||
|
|
|
@ -9,19 +9,34 @@ The Hilbish module includes the core API, containing
|
||||||
interfaces and functions which directly relate to shell functionality.
|
interfaces and functions which directly relate to shell functionality.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### runnerMode(mode)
|
### alias(cmd, orig)
|
||||||
Sets the execution/runner mode for interactive Hilbish. This determines whether
|
Sets an alias of `cmd` to `orig`
|
||||||
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.
|
|
||||||
|
|
||||||
### appendPath(dir)
|
### appendPath(dir)
|
||||||
Appends `dir` to $PATH
|
Appends `dir` to $PATH
|
||||||
|
|
||||||
|
### complete(scope, cb)
|
||||||
|
Registers a completion handler for `scope`.
|
||||||
|
A `scope` is currently only expected to be `command.<cmd>`,
|
||||||
|
replacing <cmd> with the name of the command (for example `command.git`).
|
||||||
|
`cb` must be a function that returns a table of "completion groups."
|
||||||
|
Check `doc completions` for more information.
|
||||||
|
|
||||||
|
### cwd()
|
||||||
|
Returns the current directory of the shell
|
||||||
|
|
||||||
|
### exec(cmd)
|
||||||
|
Replaces running hilbish with `cmd`
|
||||||
|
|
||||||
### goro(fn)
|
### goro(fn)
|
||||||
Puts `fn` in a goroutine
|
Puts `fn` in a goroutine
|
||||||
|
|
||||||
|
### highlighter(line)
|
||||||
|
Line highlighter handler. This is mainly for syntax highlighting, but in
|
||||||
|
reality could set the input of the prompt to *display* anything. The
|
||||||
|
callback is passed the current line and is expected to return a line that
|
||||||
|
will be used as the input display.
|
||||||
|
|
||||||
### hinter(line, pos)
|
### hinter(line, pos)
|
||||||
The command line hint handler. It gets called on every key insert to
|
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
|
determine what text to use as an inline hint. It is passed the current
|
||||||
|
@ -29,34 +44,6 @@ line and cursor position. It is expected to return a string which is used
|
||||||
as the text for the hint. This is by default a shim. To set hints,
|
as the text for the hint. This is by default a shim. To set hints,
|
||||||
override this function with your custom handler.
|
override this function with your custom handler.
|
||||||
|
|
||||||
### read(prompt?) -> input?
|
|
||||||
Read input from the user, using Hilbish's line editor/input reader.
|
|
||||||
This is a separate instance from the one Hilbish actually uses.
|
|
||||||
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
|
||||||
|
|
||||||
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
|
||||||
Runs `cmd` in Hilbish's sh interpreter.
|
|
||||||
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
|
||||||
3rd values instead of being outputted to the terminal.
|
|
||||||
|
|
||||||
### prompt(str, typ?)
|
|
||||||
Changes the shell prompt to `str`
|
|
||||||
There are a few verbs that can be used in the prompt text.
|
|
||||||
These will be formatted and replaced with the appropriate values.
|
|
||||||
`%d` - Current working directory
|
|
||||||
`%u` - Name of current user
|
|
||||||
`%h` - Hostname of device
|
|
||||||
|
|
||||||
### timeout(cb, time)
|
|
||||||
Runs the `cb` function after `time` in milliseconds
|
|
||||||
Returns a `timer` object (see `doc timers`).
|
|
||||||
|
|
||||||
### which(name)
|
|
||||||
Checks if `name` is a valid command
|
|
||||||
|
|
||||||
### exec(cmd)
|
|
||||||
Replaces running hilbish with `cmd`
|
|
||||||
|
|
||||||
### inputMode(mode)
|
### inputMode(mode)
|
||||||
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
|
||||||
|
|
||||||
|
@ -70,22 +57,35 @@ Changes the continued line prompt to `str`
|
||||||
### prependPath(dir)
|
### prependPath(dir)
|
||||||
Prepends `dir` to $PATH
|
Prepends `dir` to $PATH
|
||||||
|
|
||||||
### complete(scope, cb)
|
### prompt(str, typ?)
|
||||||
Registers a completion handler for `scope`.
|
Changes the shell prompt to `str`
|
||||||
A `scope` is currently only expected to be `command.<cmd>`,
|
There are a few verbs that can be used in the prompt text.
|
||||||
replacing <cmd> with the name of the command (for example `command.git`).
|
These will be formatted and replaced with the appropriate values.
|
||||||
`cb` must be a function that returns a table of "completion groups."
|
`%d` - Current working directory
|
||||||
Check `doc completions` for more information.
|
`%u` - Name of current user
|
||||||
|
`%h` - Hostname of device
|
||||||
|
|
||||||
### highlighter(line)
|
### read(prompt?) -> input?
|
||||||
Line highlighter handler. This is mainly for syntax highlighting, but in
|
Read input from the user, using Hilbish's line editor/input reader.
|
||||||
reality could set the input of the prompt to *display* anything. The
|
This is a separate instance from the one Hilbish actually uses.
|
||||||
callback is passed the current line and is expected to return a line that
|
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||||
will be used as the input display.
|
|
||||||
|
|
||||||
### alias(cmd, orig)
|
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
||||||
Sets an alias of `cmd` to `orig`
|
Runs `cmd` in Hilbish's sh interpreter.
|
||||||
|
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
||||||
|
3rd values instead of being outputted to the terminal.
|
||||||
|
|
||||||
### cwd()
|
### runnerMode(mode)
|
||||||
Returns the current directory of the shell
|
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.
|
||||||
|
|
||||||
|
### timeout(cb, time)
|
||||||
|
Runs the `cb` function after `time` in milliseconds
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### which(name)
|
||||||
|
Checks if `name` is a valid command
|
||||||
|
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
---
|
|
||||||
name: Module main
|
|
||||||
description: the core Hilbish API
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The Hilbish module includes the core API, containing
|
|
||||||
interfaces and functions which directly relate to shell functionality.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
### interval(cb, time)
|
|
||||||
Runs the `cb` function every `time` milliseconds.
|
|
||||||
Returns a `timer` object (see `doc timers`).
|
|
||||||
|
|
||||||
### timeout(cb, time)
|
|
||||||
Runs the `cb` function after `time` in milliseconds
|
|
||||||
Returns a `timer` object (see `doc timers`).
|
|
||||||
|
|
||||||
### cwd()
|
|
||||||
Returns the current directory of the shell
|
|
||||||
|
|
||||||
### goro(fn)
|
|
||||||
Puts `fn` in a goroutine
|
|
||||||
|
|
||||||
### prompt(str, typ?)
|
|
||||||
Changes the shell prompt to `str`
|
|
||||||
There are a few verbs that can be used in the prompt text.
|
|
||||||
These will be formatted and replaced with the appropriate values.
|
|
||||||
`%d` - Current working directory
|
|
||||||
`%u` - Name of current user
|
|
||||||
`%h` - Hostname of device
|
|
||||||
|
|
||||||
### read(prompt?) -> input?
|
|
||||||
Read input from the user, using Hilbish's line editor/input reader.
|
|
||||||
This is a separate instance from the one Hilbish actually uses.
|
|
||||||
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
|
||||||
|
|
||||||
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
|
||||||
Runs `cmd` in Hilbish's sh interpreter.
|
|
||||||
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
|
||||||
3rd values instead of being outputted to the terminal.
|
|
||||||
|
|
||||||
### 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
|
|
||||||
line and cursor position. It is expected to return a string which is used
|
|
||||||
as the text for the hint. This is by default a shim. To set hints,
|
|
||||||
override this function with your custom handler.
|
|
||||||
|
|
||||||
### inputMode(mode)
|
|
||||||
Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
|
|
||||||
|
|
||||||
### multiprompt(str)
|
|
||||||
Changes the continued line prompt to `str`
|
|
||||||
|
|
||||||
### prependPath(dir)
|
|
||||||
Prepends `dir` to $PATH
|
|
||||||
|
|
||||||
### runnerMode(mode)
|
|
||||||
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.
|
|
||||||
|
|
||||||
### appendPath(dir)
|
|
||||||
Appends `dir` to $PATH
|
|
||||||
|
|
||||||
### highlighter(line)
|
|
||||||
Line highlighter handler. This is mainly for syntax highlighting, but in
|
|
||||||
reality could set the input of the prompt to *display* anything. The
|
|
||||||
callback is passed the current line and is expected to return a line that
|
|
||||||
will be used as the input display.
|
|
||||||
|
|
||||||
### exec(cmd)
|
|
||||||
Replaces running hilbish with `cmd`
|
|
||||||
|
|
||||||
### which(name)
|
|
||||||
Checks if `name` is a valid command
|
|
||||||
|
|
||||||
### alias(cmd, orig)
|
|
||||||
Sets an alias of `cmd` to `orig`
|
|
||||||
|
|
||||||
### complete(scope, cb)
|
|
||||||
Registers a completion handler for `scope`.
|
|
||||||
A `scope` is currently only expected to be `command.<cmd>`,
|
|
||||||
replacing <cmd> with the name of the command (for example `command.git`).
|
|
||||||
`cb` must be a function that returns a table of "completion groups."
|
|
||||||
Check `doc completions` for more information.
|
|
||||||
|
|
|
@ -1,23 +1,91 @@
|
||||||
---
|
---
|
||||||
name: Module terminal
|
name: Module terminal
|
||||||
description: low level terminal library
|
description: the core Hilbish API
|
||||||
layout: apidoc
|
layout: apidoc
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
The terminal library is a simple and lower level library for certain terminal interactions.
|
The Hilbish module includes the core API, containing
|
||||||
|
interfaces and functions which directly relate to shell functionality.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### size()
|
### alias(cmd, orig)
|
||||||
Gets the dimensions of the terminal. Returns a table with `width` and `height`
|
Sets an alias of `cmd` to `orig`
|
||||||
Note: this is not the size in relation to the dimensions of the display
|
|
||||||
|
|
||||||
### restoreState()
|
### appendPath(dir)
|
||||||
Restores the last saved state of the terminal
|
Appends `dir` to $PATH
|
||||||
|
|
||||||
### saveState()
|
### complete(scope, cb)
|
||||||
Saves the current state of the terminal
|
Registers a completion handler for `scope`.
|
||||||
|
A `scope` is currently only expected to be `command.<cmd>`,
|
||||||
|
replacing <cmd> with the name of the command (for example `command.git`).
|
||||||
|
`cb` must be a function that returns a table of "completion groups."
|
||||||
|
Check `doc completions` for more information.
|
||||||
|
|
||||||
### setRaw()
|
### cwd()
|
||||||
Puts the terminal in raw mode
|
Returns the current directory of the shell
|
||||||
|
|
||||||
|
### exec(cmd)
|
||||||
|
Replaces running hilbish with `cmd`
|
||||||
|
|
||||||
|
### goro(fn)
|
||||||
|
Puts `fn` in a goroutine
|
||||||
|
|
||||||
|
### highlighter(line)
|
||||||
|
Line highlighter handler. This is mainly for syntax highlighting, but in
|
||||||
|
reality could set the input of the prompt to *display* anything. The
|
||||||
|
callback is passed the current line and is expected to return a line that
|
||||||
|
will be used as the input display.
|
||||||
|
|
||||||
|
### 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
|
||||||
|
line and cursor position. It is expected to return a string which is used
|
||||||
|
as the text for the hint. This is by default a shim. To set hints,
|
||||||
|
override this function with your custom handler.
|
||||||
|
|
||||||
|
### inputMode(mode)
|
||||||
|
Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
|
||||||
|
|
||||||
|
### interval(cb, time)
|
||||||
|
Runs the `cb` function every `time` milliseconds.
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### multiprompt(str)
|
||||||
|
Changes the continued line prompt to `str`
|
||||||
|
|
||||||
|
### prependPath(dir)
|
||||||
|
Prepends `dir` to $PATH
|
||||||
|
|
||||||
|
### prompt(str, typ?)
|
||||||
|
Changes the shell prompt to `str`
|
||||||
|
There are a few verbs that can be used in the prompt text.
|
||||||
|
These will be formatted and replaced with the appropriate values.
|
||||||
|
`%d` - Current working directory
|
||||||
|
`%u` - Name of current user
|
||||||
|
`%h` - Hostname of device
|
||||||
|
|
||||||
|
### read(prompt?) -> input?
|
||||||
|
Read input from the user, using Hilbish's line editor/input reader.
|
||||||
|
This is a separate instance from the one Hilbish actually uses.
|
||||||
|
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
||||||
|
|
||||||
|
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
||||||
|
Runs `cmd` in Hilbish's sh interpreter.
|
||||||
|
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
||||||
|
3rd values instead of being outputted to the terminal.
|
||||||
|
|
||||||
|
### runnerMode(mode)
|
||||||
|
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.
|
||||||
|
|
||||||
|
### timeout(cb, time)
|
||||||
|
Runs the `cb` function after `time` in milliseconds
|
||||||
|
Returns a `timer` object (see `doc timers`).
|
||||||
|
|
||||||
|
### which(name)
|
||||||
|
Checks if `name` is a valid command
|
||||||
|
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
--- @meta
|
|
||||||
|
|
||||||
local main = {}
|
|
||||||
|
|
||||||
--- Sets an alias of `cmd` to `orig`
|
|
||||||
--- @param cmd string
|
|
||||||
--- @param orig string
|
|
||||||
function main.hlalias(cmd, orig) end
|
|
||||||
|
|
||||||
--- Appends `dir` to $PATH
|
|
||||||
--- @param dir string|table
|
|
||||||
function main.hlappendPath(dir) end
|
|
||||||
|
|
||||||
--- Registers a completion handler for `scope`.
|
|
||||||
--- A `scope` is currently only expected to be `command.<cmd>`,
|
|
||||||
--- replacing <cmd> with the name of the command (for example `command.git`).
|
|
||||||
--- `cb` must be a function that returns a table of "completion groups."
|
|
||||||
--- Check `doc completions` for more information.
|
|
||||||
--- @param scope string
|
|
||||||
--- @param cb function
|
|
||||||
function main.hlcomplete(scope, cb) end
|
|
||||||
|
|
||||||
--- Returns the current directory of the shell
|
|
||||||
function main.hlcwd() end
|
|
||||||
|
|
||||||
--- Replaces running hilbish with `cmd`
|
|
||||||
--- @param cmd string
|
|
||||||
function main.hlexec(cmd) end
|
|
||||||
|
|
||||||
--- Puts `fn` in a goroutine
|
|
||||||
--- @param fn function
|
|
||||||
function main.hlgoro(fn) end
|
|
||||||
|
|
||||||
--- Line highlighter handler. This is mainly for syntax highlighting, but in
|
|
||||||
--- reality could set the input of the prompt to *display* anything. The
|
|
||||||
--- callback is passed the current line and is expected to return a line that
|
|
||||||
--- will be used as the input display.
|
|
||||||
--- @param line string
|
|
||||||
function main.hlhighlighter(line) end
|
|
||||||
|
|
||||||
--- 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
|
|
||||||
--- line and cursor position. It is expected to return a string which is used
|
|
||||||
--- as the text for the hint. This is by default a shim. To set hints,
|
|
||||||
--- override this function with your custom handler.
|
|
||||||
--- @param line string
|
|
||||||
--- @param pos int
|
|
||||||
function main.hlhinter(line, pos) end
|
|
||||||
|
|
||||||
--- Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
|
|
||||||
--- @param mode string
|
|
||||||
function main.hlinputMode(mode) end
|
|
||||||
|
|
||||||
--- Runs the `cb` function every `time` milliseconds.
|
|
||||||
--- Returns a `timer` object (see `doc timers`).
|
|
||||||
--- @param cb function
|
|
||||||
--- @param time number
|
|
||||||
--- @return table
|
|
||||||
function main.hlinterval(cb, time) end
|
|
||||||
|
|
||||||
--- Changes the continued line prompt to `str`
|
|
||||||
--- @param str string
|
|
||||||
function main.hlmultiprompt(str) end
|
|
||||||
|
|
||||||
--- Prepends `dir` to $PATH
|
|
||||||
--- @param dir string
|
|
||||||
function main.hlprependPath(dir) end
|
|
||||||
|
|
||||||
--- Changes the shell prompt to `str`
|
|
||||||
--- There are a few verbs that can be used in the prompt text.
|
|
||||||
--- These will be formatted and replaced with the appropriate values.
|
|
||||||
--- `%d` - Current working directory
|
|
||||||
--- `%u` - Name of current user
|
|
||||||
--- `%h` - Hostname of device
|
|
||||||
--- @param str string
|
|
||||||
--- @param typ string Type of prompt, being left or right. Left by default.
|
|
||||||
function main.hlprompt(str, typ) end
|
|
||||||
|
|
||||||
--- Read input from the user, using Hilbish's line editor/input reader.
|
|
||||||
--- This is a separate instance from the one Hilbish actually uses.
|
|
||||||
--- Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
|
||||||
--- @param prompt string
|
|
||||||
function main.hlread(prompt) end
|
|
||||||
|
|
||||||
--- Runs `cmd` in Hilbish's sh interpreter.
|
|
||||||
--- If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
|
||||||
--- 3rd values instead of being outputted to the terminal.
|
|
||||||
--- @param cmd string
|
|
||||||
function main.hlrun(cmd) end
|
|
||||||
|
|
||||||
--- 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.
|
|
||||||
--- @param mode string|function
|
|
||||||
function main.hlrunnerMode(mode) end
|
|
||||||
|
|
||||||
--- Runs the `cb` function after `time` in milliseconds
|
|
||||||
--- Returns a `timer` object (see `doc timers`).
|
|
||||||
--- @param cb function
|
|
||||||
--- @param time number
|
|
||||||
--- @return table
|
|
||||||
function main.hltimeout(cb, time) end
|
|
||||||
|
|
||||||
--- Checks if `name` is a valid command
|
|
||||||
--- @param binName string
|
|
||||||
function main.hlwhich(binName) end
|
|
||||||
|
|
||||||
return main
|
|
Loading…
Reference in New Issue