Compare commits

...

6 Commits

23 changed files with 231 additions and 94 deletions

2
api.go
View File

@ -403,7 +403,7 @@ hilbish.appendPath '~/go/bin'
-- Will add ~/go/bin to the command path.
-- Or do multiple:
hilbush.appendPath {
hilbish.appendPath {
'~/go/bin',
'~/.local/bin'
}

View File

@ -533,7 +533,7 @@ func main() {
if dps.IsMember {
continue
}
f.WriteString(fmt.Sprintf("<hr><div id='%s'>", dps.FuncName))
f.WriteString(fmt.Sprintf("<hr>\n<div id='%s'>", dps.FuncName))
htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(modname + "." + dps.FuncSig, "<", `\<`, -1), func(typ string) string {
typName := typ[1:]
typLookup := typeTable[strings.ToLower(typName)]

View File

@ -41,7 +41,8 @@ this function will set the user prompt.
|<a href="#release">release(name, catcher)</a>|Removes the `catcher` for the event with `name`.|
|<a href="#throw">throw(name, ...args)</a>|Throws a hook with `name` with the provided `args`.|
<hr><div id='catch'>
<hr>
<div id='catch'>
<h4 class='heading'>
bait.catch(name, cb)
<a href="#catch" class='heading-link'>
@ -67,7 +68,8 @@ end)
```
</div>
<hr><div id='catchOnce'>
<hr>
<div id='catchOnce'>
<h4 class='heading'>
bait.catchOnce(name, cb)
<a href="#catchOnce" class='heading-link'>
@ -85,7 +87,8 @@ The function that will be called when the event is thrown.
</div>
<hr><div id='hooks'>
<hr>
<div id='hooks'>
<h4 class='heading'>
bait.hooks(name) -> table
<a href="#hooks" class='heading-link'>
@ -100,7 +103,8 @@ The name of the function
</div>
<hr><div id='release'>
<hr>
<div id='release'>
<h4 class='heading'>
bait.release(name, catcher)
<a href="#release" class='heading-link'>
@ -132,7 +136,8 @@ bait.release('event', hookCallback)
```
</div>
<hr><div id='throw'>
<hr>
<div id='throw'>
<h4 class='heading'>
bait.throw(name, ...args)
<a href="#throw" class='heading-link'>

View File

@ -42,7 +42,8 @@ This sink is for writing errors, as the name would suggest.
|<a href="#deregister">deregister(name)</a>|Removes the named command. Note that this will only remove Commander-registered commands.|
|<a href="#register">register(name, cb)</a>|Adds a new command with the given `name`. When Hilbish has to run a command with a name,|
<hr><div id='deregister'>
<hr>
<div id='deregister'>
<h4 class='heading'>
commander.deregister(name)
<a href="#deregister" class='heading-link'>
@ -57,7 +58,8 @@ Name of the command to remove.
</div>
<hr><div id='register'>
<hr>
<div id='register'>
<h4 class='heading'>
commander.register(name, cb)
<a href="#register" class='heading-link'>

View File

@ -31,7 +31,8 @@ library offers more functions and will work on any operating system Hilbish does
|----|----|
|pathSep|The operating system's path separator.|
<hr><div id='abs'>
<hr>
<div id='abs'>
<h4 class='heading'>
fs.abs(path) -> string
<a href="#abs" class='heading-link'>
@ -47,7 +48,8 @@ This can be used to resolve short paths like `..` to `/home/user`.
</div>
<hr><div id='basename'>
<hr>
<div id='basename'>
<h4 class='heading'>
fs.basename(path) -> string
<a href="#basename" class='heading-link'>
@ -63,7 +65,8 @@ Path to get the base name of.
</div>
<hr><div id='cd'>
<hr>
<div id='cd'>
<h4 class='heading'>
fs.cd(dir)
<a href="#cd" class='heading-link'>
@ -78,7 +81,8 @@ Path to change directory to.
</div>
<hr><div id='dir'>
<hr>
<div id='dir'>
<h4 class='heading'>
fs.dir(path) -> string
<a href="#dir" class='heading-link'>
@ -94,7 +98,8 @@ Path to get the directory for.
</div>
<hr><div id='glob'>
<hr>
<div id='glob'>
<h4 class='heading'>
fs.glob(pattern) -> matches (table)
<a href="#glob" class='heading-link'>
@ -125,7 +130,8 @@ print(matches)
```
</div>
<hr><div id='join'>
<hr>
<div id='join'>
<h4 class='heading'>
fs.join(...path) -> string
<a href="#join" class='heading-link'>
@ -148,7 +154,8 @@ print(fs.join(hilbish.userDir.config, 'hilbish'))
```
</div>
<hr><div id='mkdir'>
<hr>
<div id='mkdir'>
<h4 class='heading'>
fs.mkdir(name, recursive)
<a href="#mkdir" class='heading-link'>
@ -175,7 +182,8 @@ Whether to create parent directories for the provided name
```
</div>
<hr><div id='readdir'>
<hr>
<div id='readdir'>
<h4 class='heading'>
fs.readdir(path) -> table[string]
<a href="#readdir" class='heading-link'>
@ -190,7 +198,8 @@ Returns a list of all files and directories in the provided path.
</div>
<hr><div id='stat'>
<hr>
<div id='stat'>
<h4 class='heading'>
fs.stat(path) -> {}
<a href="#stat" class='heading-link'>

View File

@ -46,7 +46,8 @@ interfaces and functions which directly relate to shell functionality.
|vimMode|Current Vim input mode of Hilbish (will be nil if not in Vim input mode)|
|exitCode|Exit code of the last executed command|
<hr><div id='alias'>
<hr>
<div id='alias'>
<h4 class='heading'>
hilbish.alias(cmd, orig)
<a href="#alias" class='heading-link'>
@ -75,7 +76,8 @@ hilbish.alias('dircount', 'ls %1 | wc -l')
```
</div>
<hr><div id='appendPath'>
<hr>
<div id='appendPath'>
<h4 class='heading'>
hilbish.appendPath(dir)
<a href="#appendPath" class='heading-link'>
@ -96,14 +98,15 @@ hilbish.appendPath '~/go/bin'
-- Will add ~/go/bin to the command path.
-- Or do multiple:
hilbush.appendPath {
hilbish.appendPath {
'~/go/bin',
'~/.local/bin'
}
```
</div>
<hr><div id='complete'>
<hr>
<div id='complete'>
<h4 class='heading'>
hilbish.complete(scope, cb)
<a href="#complete" class='heading-link'>
@ -125,7 +128,8 @@ provides more details.
</div>
<hr><div id='cwd'>
<hr>
<div id='cwd'>
<h4 class='heading'>
hilbish.cwd() -> string
<a href="#cwd" class='heading-link'>
@ -138,7 +142,8 @@ Returns the current directory of the shell
This function has no parameters.
</div>
<hr><div id='exec'>
<hr>
<div id='exec'>
<h4 class='heading'>
hilbish.exec(cmd)
<a href="#exec" class='heading-link'>
@ -154,7 +159,8 @@ This can be used to do an in-place restart.
</div>
<hr><div id='goro'>
<hr>
<div id='goro'>
<h4 class='heading'>
hilbish.goro(fn)
<a href="#goro" class='heading-link'>
@ -171,7 +177,8 @@ This can be used to run any function in another thread.
</div>
<hr><div id='highlighter'>
<hr>
<div id='highlighter'>
<h4 class='heading'>
hilbish.highlighter(line)
<a href="#highlighter" class='heading-link'>
@ -198,7 +205,8 @@ end
```
</div>
<hr><div id='hinter'>
<hr>
<div id='hinter'>
<h4 class='heading'>
hilbish.hinter(line, pos)
<a href="#hinter" class='heading-link'>
@ -229,7 +237,8 @@ end
```
</div>
<hr><div id='inputMode'>
<hr>
<div id='inputMode'>
<h4 class='heading'>
hilbish.inputMode(mode)
<a href="#inputMode" class='heading-link'>
@ -246,7 +255,8 @@ Vim-like with modes and Vim keybinds.
</div>
<hr><div id='interval'>
<hr>
<div id='interval'>
<h4 class='heading'>
hilbish.interval(cb, time) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#timer" style="text-decoration: none;" id="lol">Timer</a>
<a href="#interval" class='heading-link'>
@ -265,7 +275,8 @@ This creates a timer that starts immediately.
</div>
<hr><div id='multiprompt'>
<hr>
<div id='multiprompt'>
<h4 class='heading'>
hilbish.multiprompt(str)
<a href="#multiprompt" class='heading-link'>
@ -301,7 +312,8 @@ hilbish.multiprompt '-->'
```
</div>
<hr><div id='prependPath'>
<hr>
<div id='prependPath'>
<h4 class='heading'>
hilbish.prependPath(dir)
<a href="#prependPath" class='heading-link'>
@ -316,7 +328,8 @@ Prepends `dir` to $PATH.
</div>
<hr><div id='prompt'>
<hr>
<div id='prompt'>
<h4 class='heading'>
hilbish.prompt(str, typ)
<a href="#prompt" class='heading-link'>
@ -348,7 +361,8 @@ hilbish.prompt '%u@%h :%d $'
```
</div>
<hr><div id='read'>
<hr>
<div id='read'>
<h4 class='heading'>
hilbish.read(prompt) -> input (string)
<a href="#read" class='heading-link'>
@ -365,7 +379,8 @@ Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which s
</div>
<hr><div id='run'>
<hr>
<div id='run'>
<h4 class='heading'>
hilbish.run(cmd, returnOut) -> exitCode (number), stdout (string), stderr (string)
<a href="#run" class='heading-link'>
@ -383,7 +398,8 @@ If this is true, the function will return the standard output and error of the c
</div>
<hr><div id='runnerMode'>
<hr>
<div id='runnerMode'>
<h4 class='heading'>
hilbish.runnerMode(mode)
<a href="#runnerMode" class='heading-link'>
@ -402,7 +418,8 @@ will call it to execute user input instead.
</div>
<hr><div id='timeout'>
<hr>
<div id='timeout'>
<h4 class='heading'>
hilbish.timeout(cb, time) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#timer" style="text-decoration: none;" id="lol">Timer</a>
<a href="#timeout" class='heading-link'>
@ -421,7 +438,8 @@ This creates a Timer that starts immediately.
</div>
<hr><div id='which'>
<hr>
<div id='which'>
<h4 class='heading'>
hilbish.which(name) -> string
<a href="#which" class='heading-link'>

View File

@ -18,7 +18,8 @@ The alias interface deals with all command aliases in Hilbish.
|<a href="#aliases.list">list() -> table[string, string]</a>|Get a table of all aliases, with string keys as the alias and the value as the command.|
|<a href="#aliases.resolve">resolve(alias) -> string?</a>|Resolves an alias to its original command. Will thrown an error if the alias doesn't exist.|
<hr><div id='aliases.add'>
<hr>
<div id='aliases.add'>
<h4 class='heading'>
hilbish.aliases.add(alias, cmd)
<a href="#aliases.add" class='heading-link'>
@ -31,7 +32,8 @@ This is an alias (ha) for the [hilbish.alias](../#alias) function.
This function has no parameters.
</div>
<hr><div id='aliases.delete'>
<hr>
<div id='aliases.delete'>
<h4 class='heading'>
hilbish.aliases.delete(name)
<a href="#aliases.delete" class='heading-link'>
@ -46,7 +48,8 @@ Removes an alias.
</div>
<hr><div id='aliases.list'>
<hr>
<div id='aliases.list'>
<h4 class='heading'>
hilbish.aliases.list() -> table[string, string]
<a href="#aliases.list" class='heading-link'>
@ -68,7 +71,8 @@ local aliases = hilbish.aliases.list()
```
</div>
<hr><div id='aliases.resolve'>
<hr>
<div id='aliases.resolve'>
<h4 class='heading'>
hilbish.aliases.resolve(alias) -> string?
<a href="#aliases.resolve" class='heading-link'>

View File

@ -18,7 +18,8 @@ The completions interface deals with tab completions.
|<a href="#completion.files">files(query, ctx, fields) -> entries (table), prefix (string)</a>|Returns file matches based on the provided parameters.|
|<a href="#completion.handler">handler(line, pos)</a>|This function contains the general completion handler for Hilbish. This function handles|
<hr><div id='completion.bins'>
<hr>
<div id='completion.bins'>
<h4 class='heading'>
hilbish.completion.bins(query, ctx, fields) -> entries (table), prefix (string)
<a href="#completion.bins" class='heading-link'>
@ -60,7 +61,8 @@ end)
```
</div>
<hr><div id='completion.call'>
<hr>
<div id='completion.call'>
<h4 class='heading'>
hilbish.completion.call(name, query, ctx, fields) -> completionGroups (table), prefix (string)
<a href="#completion.call" class='heading-link'>
@ -86,7 +88,8 @@ You can check the Completions doc or `doc completions` for info on the `completi
</div>
<hr><div id='completion.files'>
<hr>
<div id='completion.files'>
<h4 class='heading'>
hilbish.completion.files(query, ctx, fields) -> entries (table), prefix (string)
<a href="#completion.files" class='heading-link'>
@ -108,7 +111,8 @@ This function is meant to be used as a helper in a command completion handler.
</div>
<hr><div id='completion.handler'>
<hr>
<div id='completion.handler'>
<h4 class='heading'>
hilbish.completion.handler(line, pos)
<a href="#completion.handler" class='heading-link'>

View File

@ -20,7 +20,8 @@ directly interact with the line editor in use.
|<a href="#editor.getChar">getChar() -> string</a>|Reads a keystroke from the user. This is in a format of something like Ctrl-L.|
|<a href="#editor.setVimRegister">setVimRegister(register, text)</a>|Sets the vim register at `register` to hold the passed text.|
<hr><div id='editor.getLine'>
<hr>
<div id='editor.getLine'>
<h4 class='heading'>
hilbish.editor.getLine() -> string
<a href="#editor.getLine" class='heading-link'>
@ -33,7 +34,8 @@ Returns the current input line.
This function has no parameters.
</div>
<hr><div id='editor.getVimRegister'>
<hr>
<div id='editor.getVimRegister'>
<h4 class='heading'>
hilbish.editor.getVimRegister(register) -> string
<a href="#editor.getVimRegister" class='heading-link'>
@ -48,7 +50,8 @@ Returns the text that is at the register.
</div>
<hr><div id='editor.insert'>
<hr>
<div id='editor.insert'>
<h4 class='heading'>
hilbish.editor.insert(text)
<a href="#editor.insert" class='heading-link'>
@ -63,7 +66,8 @@ Inserts text into the Hilbish command line.
</div>
<hr><div id='editor.getChar'>
<hr>
<div id='editor.getChar'>
<h4 class='heading'>
hilbish.editor.getChar() -> string
<a href="#editor.getChar" class='heading-link'>
@ -76,7 +80,8 @@ Reads a keystroke from the user. This is in a format of something like Ctrl-L.
This function has no parameters.
</div>
<hr><div id='editor.setVimRegister'>
<hr>
<div id='editor.setVimRegister'>
<h4 class='heading'>
hilbish.editor.setVimRegister(register, text)
<a href="#editor.setVimRegister" class='heading-link'>

View File

@ -21,7 +21,8 @@ method of saving history.
|<a href="#history.get">get(index)</a>|Retrieves a command from the history based on the `index`.|
|<a href="#history.size">size() -> number</a>|Returns the amount of commands in the history.|
<hr><div id='history.add'>
<hr>
<div id='history.add'>
<h4 class='heading'>
hilbish.history.add(cmd)
<a href="#history.add" class='heading-link'>
@ -36,7 +37,8 @@ Adds a command to the history.
</div>
<hr><div id='history.all'>
<hr>
<div id='history.all'>
<h4 class='heading'>
hilbish.history.all() -> table
<a href="#history.all" class='heading-link'>
@ -49,7 +51,8 @@ Retrieves all history as a table.
This function has no parameters.
</div>
<hr><div id='history.clear'>
<hr>
<div id='history.clear'>
<h4 class='heading'>
hilbish.history.clear()
<a href="#history.clear" class='heading-link'>
@ -62,7 +65,8 @@ Deletes all commands from the history.
This function has no parameters.
</div>
<hr><div id='history.get'>
<hr>
<div id='history.get'>
<h4 class='heading'>
hilbish.history.get(index)
<a href="#history.get" class='heading-link'>
@ -77,7 +81,8 @@ Retrieves a command from the history based on the `index`.
</div>
<hr><div id='history.size'>
<hr>
<div id='history.size'>
<h4 class='heading'>
hilbish.history.size() -> number
<a href="#history.size" class='heading-link'>

View File

@ -23,7 +23,8 @@ interactive usage or with the functions defined below for use in external runner
|<a href="#jobs.get">get(id) -> @Job</a>|Get a job object via its ID.|
|<a href="#jobs.last">last() -> @Job</a>|Returns the last added job to the table.|
<hr><div id='jobs.add'>
<hr>
<div id='jobs.add'>
<h4 class='heading'>
hilbish.jobs.add(cmdstr, args, execPath)
<a href="#jobs.add" class='heading-link'>
@ -51,7 +52,8 @@ hilbish.jobs.add('go build', {'go', 'build'}, '/usr/bin/go')
```
</div>
<hr><div id='jobs.all'>
<hr>
<div id='jobs.all'>
<h4 class='heading'>
hilbish.jobs.all() -> table[<a href="/Hilbish/docs/api/hilbish/hilbish.jobs/#job" style="text-decoration: none;" id="lol">Job</a>]
<a href="#jobs.all" class='heading-link'>
@ -64,7 +66,8 @@ Returns a table of all job objects.
This function has no parameters.
</div>
<hr><div id='jobs.disown'>
<hr>
<div id='jobs.disown'>
<h4 class='heading'>
hilbish.jobs.disown(id)
<a href="#jobs.disown" class='heading-link'>
@ -79,7 +82,8 @@ Disowns a job. This simply deletes it from the list of jobs without stopping it.
</div>
<hr><div id='jobs.get'>
<hr>
<div id='jobs.get'>
<h4 class='heading'>
hilbish.jobs.get(id) -> <a href="/Hilbish/docs/api/hilbish/hilbish.jobs/#job" style="text-decoration: none;" id="lol">Job</a>
<a href="#jobs.get" class='heading-link'>
@ -92,7 +96,8 @@ Get a job object via its ID.
This function has no parameters.
</div>
<hr><div id='jobs.last'>
<hr>
<div id='jobs.last'>
<h4 class='heading'>
hilbish.jobs.last() -> <a href="/Hilbish/docs/api/hilbish/hilbish.jobs/#job" style="text-decoration: none;" id="lol">Job</a>
<a href="#jobs.last" class='heading-link'>

View File

@ -53,7 +53,8 @@ If you attempt to require and print the result (`print(require 'plugin')`), it w
|----|----|
|paths|A list of paths to search when loading native modules. This is in the style of Lua search paths and will be used when requiring native modules. Example: `?.so;?/?.so`|
<hr><div id='module.load'>
<hr>
<div id='module.load'>
<h4 class='heading'>
hilbish.module.load(path)
<a href="#module.load" class='heading-link'>

View File

@ -21,7 +21,8 @@ write command in Fennel.
|<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.|
<hr><div id='runner.setMode'>
<hr>
<div id='runner.setMode'>
<h4 class='heading'>
hilbish.runner.setMode(cb)
<a href="#runner.setMode" class='heading-link'>
@ -39,7 +40,8 @@ as the higher level functions listed below this will handle it.
</div>
<hr><div id='runner.lua'>
<hr>
<div id='runner.lua'>
<h4 class='heading'>
hilbish.runner.lua(cmd)
<a href="#runner.lua" class='heading-link'>
@ -55,7 +57,8 @@ or `load`, but is appropriated for the runner interface.
</div>
<hr><div id='runner.sh'>
<hr>
<div id='runner.sh'>
<h4 class='heading'>
hilbish.runner.sh(cmd)
<a href="#runner.sh" class='heading-link'>

View File

@ -38,7 +38,8 @@ print(t.running) // true
|INTERVAL|Constant for an interval timer type|
|TIMEOUT|Constant for a timeout timer type|
<hr><div id='timers.create'>
<hr>
<div id='timers.create'>
<h4 class='heading'>
hilbish.timers.create(type, time, callback) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#timer" style="text-decoration: none;" id="lol">Timer</a>
<a href="#timers.create" class='heading-link'>
@ -59,7 +60,8 @@ The function to run for the timer.
</div>
<hr><div id='timers.get'>
<hr>
<div id='timers.get'>
<h4 class='heading'>
hilbish.timers.get(id) -> <a href="/Hilbish/docs/api/hilbish/hilbish.timers/#timer" style="text-decoration: none;" id="lol">Timer</a>
<a href="#timers.get" class='heading-link'>

View File

@ -18,7 +18,8 @@ The terminal library is a simple and lower level library for certain terminal in
|<a href="#setRaw">setRaw()</a>|Puts the terminal into raw mode.|
|<a href="#size">size()</a>|Gets the dimensions of the terminal. Returns a table with `width` and `height`|
<hr><div id='restoreState'>
<hr>
<div id='restoreState'>
<h4 class='heading'>
terminal.restoreState()
<a href="#restoreState" class='heading-link'>
@ -31,7 +32,8 @@ Restores the last saved state of the terminal
This function has no parameters.
</div>
<hr><div id='saveState'>
<hr>
<div id='saveState'>
<h4 class='heading'>
terminal.saveState()
<a href="#saveState" class='heading-link'>
@ -44,7 +46,8 @@ Saves the current state of the terminal.
This function has no parameters.
</div>
<hr><div id='setRaw'>
<hr>
<div id='setRaw'>
<h4 class='heading'>
terminal.setRaw()
<a href="#setRaw" class='heading-link'>
@ -57,7 +60,8 @@ Puts the terminal into raw mode.
This function has no parameters.
</div>
<hr><div id='size'>
<hr>
<div id='size'>
<h4 class='heading'>
terminal.size()
<a href="#size" class='heading-link'>

View File

@ -1,5 +1,5 @@
---
title: Hooks
title: Signals
description:
layout: doc
weight: -50
@ -7,5 +7,5 @@ menu:
docs
---
Hooks are Hilbish's versions of events, which are used via the [Bait](../api/bait) module.
For more detail on how to act on these hooks, you may check the Bait page.
Signals are global events emitted with the [Bait](../api/bait) module.
For more detail on how to use these signals, you may check the Bait page.

View File

@ -4,7 +4,7 @@ description:
layout: doc
menu:
docs:
parent: "Hooks"
parent: "Signals"
---
- `command.preexec` -> input, cmdStr > Thrown before a command

View File

@ -4,7 +4,7 @@ description:
layout: doc
menu:
docs:
parent: "Hooks"
parent: "Signals"
---
+ `hilbish.exit` > Sent when Hilbish is about to exit.

View File

@ -4,7 +4,7 @@ description:
layout: doc
menu:
docs:
parent: "Hooks"
parent: "Signals"
---
+ `signal.sigint` > Sent when Hilbish receives SIGINT (on Ctrl-C).

View File

@ -10,8 +10,8 @@ growing to their final phase: a full plant. A lot of Hilbish itself is
written in Go, but there are parts made in Lua, being most builtins
(`doc`, `cd`, cdr), completions, and other things.
Hilbish's Lua core module is called `nature`. It's handled after everything
on the Go side initializes, which is what that first sentence was from.
Hilbish's Lua core module is called `nature`.
It runs after Hilbish's Go core does.
# Nature Modules
Currently, `nature` provides 1 intended public module: `nature.dirs`.

View File

@ -6,6 +6,38 @@ local Greenhouse = require 'nature.greenhouse'
local Page = require 'nature.greenhouse.page'
local docfuncs = require 'nature.doc'
local function strip(text, ...)
for _, pat in ipairs {...} do
text = text:gsub(pat, '\n')
end
return text
end
local function transformHTMLandMD(text)
return strip(text, '|||', '|%-%-%-%-|%-%-%-%-|')
:gsub('|(.-)|(.-)|', function(entry1, entry2)
return string.format('%s - %s', entry1, entry2)
end)
:gsub('^\n\n', '\n')
:gsub('\n%s+\n', '\n\n')
:gsub(' \n', '\n\n')
:gsub('{{< (%w+) `(.-)` >}}', function(shortcode, text)
return docfuncs.renderInfoBlock(shortcode, text)
end)
:gsub('```(%w+)\n(.-)```', function(lang, text)
return docfuncs.renderCodeBlock(text)
end)
:gsub('```\n(.-)\n```', function(text)
return docfuncs.renderCodeBlock(text)
end)
:gsub('`[^\n].-`', lunacolors.cyan)
:gsub('#+ (.-\n)', function(heading) return lunacolors.blue(lunacolors.bold('' .. heading)) end)
:gsub('%*%*(.-)%*%*', lunacolors.bold)
:gsub('<hr>', '{separator}')
:gsub('<.->', '')
end
commander.register('doc', function(args, sinks)
local moddocPath = hilbish.dataDir .. '/docs/'
local stat = pcall(fs.stat, '.git/refs/heads/extended-job-api')
@ -29,10 +61,9 @@ Available sections: ]] .. table.concat(modules, ', ')
local vals = {}
local docs = d
local valsStr = docs:match '%-%-%-\n([^%-%-%-]+)\n'
print(valsStr)
local valsStr = docs:match '^%-%-%-\n.-\n%-%-%-'
if valsStr then
docs = docs:sub(valsStr:len() + 10, #docs)
docs = docs:sub(valsStr:len() + 2, #docs)
-- parse vals
local lines = string.split(valsStr, '\n')
@ -117,9 +148,7 @@ Available sections: ]] .. table.concat(modules, ', ')
end
local backtickOccurence = 0
local function formatDocText(d)
return d:gsub('```(%w+)\n(.-)```', function(lang, text)
return docfuncs.renderCodeBlock(text)
end)
return transformHTMLandMD(d)
--[[
return lunacolors.format(d:gsub('`(.-)`', function(t)
return docfuncs.renderCodeBlock(t)
@ -131,7 +160,7 @@ Available sections: ]] .. table.concat(modules, ', ')
end
local doc, vals = handleYamlInfo(#args == 0 and doc or formatDocText(f:read '*a':gsub('-([%d]+)', '%1')))
local doc, vals = handleYamlInfo(#args == 0 and doc or formatDocText(f:read '*a'))
if #moddocs ~= 0 and f then
doc = doc .. '\nSubdocs: ' .. table.concat(subdocs, ', ') .. '\n\n'
end
@ -149,8 +178,8 @@ Available sections: ]] .. table.concat(modules, ', ')
end
local f = io.open(moddocPath .. sdFile, 'rb')
local doc, vals = handleYamlInfo(f:read '*a':gsub('-([%d]+)', '%1'))
local page = Page(vals.title, formatDocText(doc))
local doc, vals = handleYamlInfo(formatDocText(f:read '*a'))
local page = Page(vals.title or sdName, doc)
page.description = vals.description
gh:addPage(page)
end

View File

@ -17,11 +17,31 @@ function M.renderCodeBlock(text)
end
for i, line in ipairs(lines) do
lines[i] = M.highlight(line:sub(0, longest))
.. string.rep(' ', longest - line:len())
lines[i] = ' ' .. M.highlight(line:sub(0, longest))
.. string.rep(' ', longest - line:len()) .. ' '
end
return '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n'
end
function M.renderInfoBlock(type, text)
local longest = 0
local lines = string.split(text:gsub('\t', ' '), '\n')
for i, line in ipairs(lines) do
local len = line:len()
if len > longest then longest = len end
end
for i, line in ipairs(lines) do
lines[i] = ' ' .. M.highlight(line:sub(0, longest))
.. string.rep(' ', longest - line:len()) .. ' '
end
local heading
if type == 'warning' then
heading = lunacolors.yellowBg(lunacolors.black(' ⚠ Warning '))
end
return '\n' .. heading .. '\n' .. lunacolors.format('{greyBg}' .. table.concat(lines, '\n')) .. '\n'
end
return M

View File

@ -18,12 +18,20 @@ function Greenhouse:new(sink)
self.contents = nil -- or can be a table
self.start = 1 -- where to start drawing from (should replace with self.region.y)
self.offset = 1 -- vertical text offset
self.horizOffset = 1
self.sink = sink
self.pages = {}
self.curPage = 1
self.step = {
horizontal = 5,
vertical = 1
}
self.separator = ''
self.keybinds = {
['Up'] = function(self) self:scroll 'up' end,
['Down'] = function(self) self:scroll 'down' end,
['Left'] = function(self) self:scroll 'left' end,
['Right'] = function(self) self:scroll 'right' end,
['Ctrl-Left'] = self.previous,
['Ctrl-Right'] = self.next,
['Ctrl-N'] = function(self) self:toc(true) end,
@ -51,7 +59,7 @@ function Greenhouse:updateCurrentPage(text)
page:setText(text)
end
local function sub(str, limit)
function Greenhouse:sub(str, offset, limit)
local overhead = 0
local function addOverhead(s)
overhead = overhead + string.len(s)
@ -63,7 +71,8 @@ local function sub(str, limit)
:gsub('\x1b%[%d+;%d+%w', addOverhead)
:gsub('\x1b%[%d+%w', addOverhead)
return s:sub(0, limit + overhead)
return s:sub(offset, utf8.offset(str, limit + overhead) or limit + overhead)
--return s:sub(offset, limit + overhead)
end
function Greenhouse:draw()
@ -88,7 +97,9 @@ function Greenhouse:draw()
if i == offset + self.region.height - 1 then writer = self.sink.write end
writer(self.sink, sub(lines[i]:gsub('\t', ' '), self.region.width))
self.sink:write(ansikit.getCSI(self.start + i - offset .. ';1', 'H'))
local line = lines[i]:gsub('{separator}', function() return self.separator:rep(self.region.width - 1) end)
writer(self.sink, self:sub(line:gsub('\t', ' '), self.horizOffset, self.region.width))
end
writer(self.sink, '\27[0m')
self:render()
@ -110,13 +121,23 @@ function Greenhouse:scroll(direction)
local lines = self.pages[self.curPage].lines
local oldOffset = self.offset
local oldHorizOffset = self.horizOffset
if direction == 'down' then
self.offset = math.min(self.offset + 1, math.max(1, #lines - self.region.height))
self.offset = math.min(self.offset + self.step.vertical, math.max(1, #lines - self.region.height))
elseif direction == 'up' then
self.offset = math.max(self.offset - 1, 1)
self.offset = math.max(self.offset - self.step.vertical, 1)
end
--[[
if direction == 'left' then
self.horizOffset = math.max(self.horizOffset - self.step.horizontal, 1)
elseif direction == 'right' then
self.horizOffset = self.horizOffset + self.step.horizontal
end
]]--
if self.offset ~= oldOffset then self:draw() end
if self.horizOffset ~= oldHorizOffset then self:draw() end
end
function Greenhouse:update()