mirror of https://github.com/Hilbis/Hilbish
docs: add better introduction for bait module
also highlights codeblocks betterpull/260/head
parent
7c1984135b
commit
81b7e20cbf
|
@ -437,7 +437,7 @@ func main() {
|
||||||
f, _ := os.Create(docPath)
|
f, _ := os.Create(docPath)
|
||||||
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
||||||
typeTag, _ := regexp.Compile(`@\w+`)
|
typeTag, _ := regexp.Compile(`@\w+`)
|
||||||
modDescription := typeTag.ReplaceAllStringFunc(strings.Replace(modu.Description, "<", `\<`, -1), func(typ string) string {
|
modDescription := typeTag.ReplaceAllStringFunc(strings.Replace(strings.Replace(modu.Description, "<", `\<`, -1), "{{\\<", "{{<", -1), func(typ string) string {
|
||||||
typName := typ[1:]
|
typName := typ[1:]
|
||||||
typLookup := typeTable[strings.ToLower(typName)]
|
typLookup := typeTable[strings.ToLower(typName)]
|
||||||
ifaces := typLookup[0] + "." + typLookup[1] + "/"
|
ifaces := typLookup[0] + "." + typLookup[1] + "/"
|
||||||
|
|
|
@ -8,17 +8,37 @@ menu:
|
||||||
---
|
---
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
Bait is the event emitter for Hilbish. Why name it bait? Why not.
|
|
||||||
It throws hooks that you can catch. This is what you will use if
|
Bait is the event emitter for Hilbish. Much like Node.js and
|
||||||
you want to listen in on hooks to know when certain things have
|
its `events` system, many actions in Hilbish emit events.
|
||||||
happened, like when you've changed directory, a command has failed,
|
Unlike Node.js, Hilbish events are global. So make sure to
|
||||||
etc. To find all available hooks thrown by Hilbish, see doc hooks.
|
pick a unique name!
|
||||||
|
|
||||||
|
Usage of the Bait module consists of userstanding
|
||||||
|
event-driven architecture, but it's pretty simple:
|
||||||
|
If you want to act on a certain event, you can `catch` it.
|
||||||
|
You can act on events via callback functions.
|
||||||
|
|
||||||
|
Examples of this are in the Hilbish default config!
|
||||||
|
Consider this part of it:
|
||||||
|
```
|
||||||
|
bait.catch('command.exit', function(code)
|
||||||
|
running = false
|
||||||
|
doPrompt(code ~= 0)
|
||||||
|
doNotifyPrompt()
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
|
What this does is, whenever the `command.exit` event is thrown,
|
||||||
|
this function will set the user prompt.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
### bait.catch(name, cb)
|
### bait.catch(name, cb)
|
||||||
Catches a hook with `name`. Runs the `cb` when it is thrown
|
Catches a hook with `name`. Runs the `cb` when it is thrown
|
||||||
#### Parameters
|
#### Parameters
|
||||||
This function has no parameters.
|
`string` **`name`**
|
||||||
|
ummm
|
||||||
|
|
||||||
|
|
||||||
### bait.catchOnce(name, cb)
|
### bait.catchOnce(name, cb)
|
||||||
Same as catch, but only runs the `cb` once and then removes the hook
|
Same as catch, but only runs the `cb` once and then removes the hook
|
||||||
|
|
|
@ -1,9 +1,28 @@
|
||||||
// the event emitter
|
// the event emitter
|
||||||
// Bait is the event emitter for Hilbish. Why name it bait? Why not.
|
/*
|
||||||
// It throws hooks that you can catch. This is what you will use if
|
Bait is the event emitter for Hilbish. Much like Node.js and
|
||||||
// you want to listen in on hooks to know when certain things have
|
its `events` system, many actions in Hilbish emit events.
|
||||||
// happened, like when you've changed directory, a command has failed,
|
Unlike Node.js, Hilbish events are global. So make sure to
|
||||||
// etc. To find all available hooks thrown by Hilbish, see doc hooks.
|
pick a unique name!
|
||||||
|
|
||||||
|
Usage of the Bait module consists of userstanding
|
||||||
|
event-driven architecture, but it's pretty simple:
|
||||||
|
If you want to act on a certain event, you can `catch` it.
|
||||||
|
You can act on events via callback functions.
|
||||||
|
|
||||||
|
Examples of this are in the Hilbish default config!
|
||||||
|
Consider this part of it:
|
||||||
|
```
|
||||||
|
bait.catch('command.exit', function(code)
|
||||||
|
running = false
|
||||||
|
doPrompt(code ~= 0)
|
||||||
|
doNotifyPrompt()
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
|
What this does is, whenever the `command.exit` event is thrown,
|
||||||
|
this function will set the user prompt.
|
||||||
|
*/
|
||||||
package bait
|
package bait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -253,8 +272,8 @@ func (b *Bait) bthrow(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
|
||||||
// catch(name, cb)
|
// catch(name, cb)
|
||||||
// Catches a hook with `name`. Runs the `cb` when it is thrown
|
// Catches a hook with `name`. Runs the `cb` when it is thrown
|
||||||
// --- @param name string
|
// #param name string ummm
|
||||||
// --- @param cb function
|
// #param cb function ?
|
||||||
func (b *Bait) bcatch(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (b *Bait) bcatch(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
name, catcher, err := util.HandleStrCallback(t, c)
|
name, catcher, err := util.HandleStrCallback(t, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -29,6 +29,9 @@ enableGitInfo = true
|
||||||
[markup.goldmark.renderer]
|
[markup.goldmark.renderer]
|
||||||
unsafe = true
|
unsafe = true
|
||||||
|
|
||||||
|
[markup.highlight]
|
||||||
|
style = 'pastie'
|
||||||
|
|
||||||
[author]
|
[author]
|
||||||
[author.sammyette]
|
[author.sammyette]
|
||||||
name = 'sammyette'
|
name = 'sammyette'
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/* Background */ .bg { background-color: #ffffff; }
|
||||||
|
/* PreWrapper */ .chroma { background-color: #ffffff; }
|
||||||
|
/* Other */ .chroma .x { }
|
||||||
|
/* Error */ .chroma .err { color: #a61717; background-color: #e3d2d2 }
|
||||||
|
/* CodeLine */ .chroma .cl { }
|
||||||
|
/* LineTableTD */ .chroma .lntd { vertical-align: top; padding: 0; margin: 0; border: 0; }
|
||||||
|
/* LineTable */ .chroma .lntable { border-spacing: 0; padding: 0; margin: 0; border: 0; }
|
||||||
|
/* LineHighlight */ .chroma .hl { background-color: #ffffcc }
|
||||||
|
/* LineNumbersTable */ .chroma .lnt { white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
|
||||||
|
/* LineNumbers */ .chroma .ln { white-space: pre; user-select: none; margin-right: 0.4em; padding: 0 0.4em 0 0.4em;color: #7f7f7f }
|
||||||
|
/* Line */ .chroma .line { display: flex; }
|
||||||
|
/* Keyword */ .chroma .k { color: #008800; font-weight: bold }
|
||||||
|
/* KeywordConstant */ .chroma .kc { color: #008800; font-weight: bold }
|
||||||
|
/* KeywordDeclaration */ .chroma .kd { color: #008800; font-weight: bold }
|
||||||
|
/* KeywordNamespace */ .chroma .kn { color: #008800; font-weight: bold }
|
||||||
|
/* KeywordPseudo */ .chroma .kp { color: #008800 }
|
||||||
|
/* KeywordReserved */ .chroma .kr { color: #008800; font-weight: bold }
|
||||||
|
/* KeywordType */ .chroma .kt { color: #888888; font-weight: bold }
|
||||||
|
/* Name */ .chroma .n { }
|
||||||
|
/* NameAttribute */ .chroma .na { color: #336699 }
|
||||||
|
/* NameBuiltin */ .chroma .nb { color: #003388 }
|
||||||
|
/* NameBuiltinPseudo */ .chroma .bp { }
|
||||||
|
/* NameClass */ .chroma .nc { color: #bb0066; font-weight: bold }
|
||||||
|
/* NameConstant */ .chroma .no { color: #003366; font-weight: bold }
|
||||||
|
/* NameDecorator */ .chroma .nd { color: #555555 }
|
||||||
|
/* NameEntity */ .chroma .ni { }
|
||||||
|
/* NameException */ .chroma .ne { color: #bb0066; font-weight: bold }
|
||||||
|
/* NameFunction */ .chroma .nf { color: #0066bb; font-weight: bold }
|
||||||
|
/* NameFunctionMagic */ .chroma .fm { }
|
||||||
|
/* NameLabel */ .chroma .nl { color: #336699; font-style: italic }
|
||||||
|
/* NameNamespace */ .chroma .nn { color: #bb0066; font-weight: bold }
|
||||||
|
/* NameOther */ .chroma .nx { }
|
||||||
|
/* NameProperty */ .chroma .py { color: #336699; font-weight: bold }
|
||||||
|
/* NameTag */ .chroma .nt { color: #bb0066; font-weight: bold }
|
||||||
|
/* NameVariable */ .chroma .nv { color: #336699 }
|
||||||
|
/* NameVariableClass */ .chroma .vc { color: #336699 }
|
||||||
|
/* NameVariableGlobal */ .chroma .vg { color: #dd7700 }
|
||||||
|
/* NameVariableInstance */ .chroma .vi { color: #3333bb }
|
||||||
|
/* NameVariableMagic */ .chroma .vm { }
|
||||||
|
/* Literal */ .chroma .l { }
|
||||||
|
/* LiteralDate */ .chroma .ld { }
|
||||||
|
/* LiteralString */ .chroma .s { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringAffix */ .chroma .sa { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringBacktick */ .chroma .sb { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringChar */ .chroma .sc { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringDelimiter */ .chroma .dl { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringDoc */ .chroma .sd { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringDouble */ .chroma .s2 { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringEscape */ .chroma .se { color: #0044dd; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringHeredoc */ .chroma .sh { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringInterpol */ .chroma .si { color: #3333bb; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringOther */ .chroma .sx { color: #22bb22; background-color: #f0fff0 }
|
||||||
|
/* LiteralStringRegex */ .chroma .sr { color: #008800; background-color: #fff0ff }
|
||||||
|
/* LiteralStringSingle */ .chroma .s1 { color: #dd2200; background-color: #fff0f0 }
|
||||||
|
/* LiteralStringSymbol */ .chroma .ss { color: #aa6600; background-color: #fff0f0 }
|
||||||
|
/* LiteralNumber */ .chroma .m { color: #0000dd; font-weight: bold }
|
||||||
|
/* LiteralNumberBin */ .chroma .mb { color: #0000dd; font-weight: bold }
|
||||||
|
/* LiteralNumberFloat */ .chroma .mf { color: #0000dd; font-weight: bold }
|
||||||
|
/* LiteralNumberHex */ .chroma .mh { color: #0000dd; font-weight: bold }
|
||||||
|
/* LiteralNumberInteger */ .chroma .mi { color: #0000dd; font-weight: bold }
|
||||||
|
/* LiteralNumberIntegerLong */ .chroma .il { color: #0000dd; font-weight: bold }
|
||||||
|
/* LiteralNumberOct */ .chroma .mo { color: #0000dd; font-weight: bold }
|
||||||
|
/* Operator */ .chroma .o { }
|
||||||
|
/* OperatorWord */ .chroma .ow { color: #008800 }
|
||||||
|
/* Punctuation */ .chroma .p { }
|
||||||
|
/* Comment */ .chroma .c { color: #888888 }
|
||||||
|
/* CommentHashbang */ .chroma .ch { color: #888888 }
|
||||||
|
/* CommentMultiline */ .chroma .cm { color: #888888 }
|
||||||
|
/* CommentSingle */ .chroma .c1 { color: #888888 }
|
||||||
|
/* CommentSpecial */ .chroma .cs { color: #cc0000; background-color: #fff0f0; font-weight: bold }
|
||||||
|
/* CommentPreproc */ .chroma .cp { color: #cc0000; font-weight: bold }
|
||||||
|
/* CommentPreprocFile */ .chroma .cpf { color: #cc0000; font-weight: bold }
|
||||||
|
/* Generic */ .chroma .g { }
|
||||||
|
/* GenericDeleted */ .chroma .gd { color: #000000; background-color: #ffdddd }
|
||||||
|
/* GenericEmph */ .chroma .ge { font-style: italic }
|
||||||
|
/* GenericError */ .chroma .gr { color: #aa0000 }
|
||||||
|
/* GenericHeading */ .chroma .gh { color: #333333 }
|
||||||
|
/* GenericInserted */ .chroma .gi { color: #000000; background-color: #ddffdd }
|
||||||
|
/* GenericOutput */ .chroma .go { color: #888888 }
|
||||||
|
/* GenericPrompt */ .chroma .gp { color: #555555 }
|
||||||
|
/* GenericStrong */ .chroma .gs { font-weight: bold }
|
||||||
|
/* GenericSubheading */ .chroma .gu { color: #666666 }
|
||||||
|
/* GenericTraceback */ .chroma .gt { color: #aa0000 }
|
||||||
|
/* GenericUnderline */ .chroma .gl { text-decoration: underline }
|
||||||
|
/* TextWhitespace */ .chroma .w { color: #bbbbbb }
|
|
@ -23,7 +23,10 @@
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||||
|
{{ $syntax := resources.Get "css/syntax.css" | resources.Minify | resources.Fingerprint }}
|
||||||
|
<link rel="stylesheet" href="{{ $syntax.RelPermalink }}" integrity="{{ $syntax.Data.Integrity }}">
|
||||||
|
|
||||||
|
</link>
|
||||||
<style>
|
<style>
|
||||||
.heading > .heading-link {
|
.heading > .heading-link {
|
||||||
opacity: 0
|
opacity: 0
|
||||||
|
|
Loading…
Reference in New Issue