Documentation
¶
Overview ¶
Package mods runs plugin mods (docs/mods.md) inside the terminal console.
Every mod gets a goja runtime of its own, which is its sandbox: the runtime has no require, file system, timers or network, only the $ object. A goja runtime is not goroutine-safe, so each one is owned by a loop goroutine and everything that touches it — a handler call, a promise settling, a button press — is a job queued on that loop. The chain of one event crosses runtimes through Go: next(e) in one mod resolves on another goroutine and comes back to the caller's loop as a job.
Index ¶
- func Denied(result any) (string, bool)
- func Signature(list []Mod) string
- type API
- type Command
- type Element
- type Host
- func (h *Host) Close()
- func (h *Host) ClosePane(p Pane)
- func (h *Host) Commands() []Command
- func (h *Host) Dispatch(ctx context.Context, event string, e map[string]any, ...) (any, error)
- func (h *Host) Handles(event string) bool
- func (h *Host) Load(list []Mod) bool
- func (h *Host) Loaded() int
- func (h *Host) Logs(key string) []string
- func (h *Host) Notices() <-chan Notice
- func (h *Host) OpenPanes() []Pane
- func (h *Host) Problems() []string
- func (h *Host) Render(component string, props map[string]any) (hidden bool, elems []Element)
- func (h *Host) RenderMany(component string, props []map[string]any) []Rendered
- func (h *Host) RenderPane(p Pane) []Element
- func (h *Host) RunCommand(ctx context.Context, id string, args map[string]any) (any, error)
- func (h *Host) SetViewport(width, height int)
- func (h *Host) Status() []string
- type Mod
- type Notice
- type NoticeKind
- type Options
- type Pane
- type Rendered
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
API is the part of console.Client the mods' $.api uses. It is called as the person running the console.
type Command ¶
type Command struct {
Mod string // Mod.Key()
Name string // the mod's display name
ID string
Title string
}
Command is a palette command a mod registered with $.command.register.
type Element ¶
type Element struct {
Type string // Box, Text, Badge, Button, Link
Text string // Text, Badge
Tone string // dim, accent, warn, danger, ok
Bold bool
Mono bool
Label string // Button, Link
Href string // Link
Hotkey string // Button
Direction string // Box: row or column
Gap int
Children []Element
// contains filtered or unexported fields
}
Element is a mod element ($.ui.resolve) as the console draws it. Props a terminal cannot show are dropped.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host owns the runtimes of the loaded mods, in install order.
func (*Host) Dispatch ¶
func (h *Host) Dispatch(ctx context.Context, event string, e map[string]any, def func(map[string]any) (any, error)) (any, error)
Dispatch runs event through every mod's handlers, in mod order, ending in def (Lectern's own behaviour; nil does nothing). It returns what the first handler returned, exported to plain Go values.
func (*Host) Handles ¶
Handles reports whether any running mod has a handler for event, so the console can skip work nobody listens to.
func (*Host) Load ¶
Load replaces the running mods with list. An unchanged mod keeps its runtime, state in memory, commands and panes; a new one is started and gets app.start. It reports whether anything changed.
func (*Host) Notices ¶
Notices delivers toasts and redraw requests. Sends never block: a console that falls behind loses redraw hints, not its own events.
func (*Host) Problems ¶
Problems lists what keeps mods from running: load errors, paused mods, and the most recent handler error of each mod.
func (*Host) Render ¶
Render asks the mods how to draw component. It waits at most the render budget (100 ms); handlers still running then are drawn without.
func (*Host) RenderMany ¶
RenderMany renders several instances of one component (every session row) under one shared budget, so a slow mod costs the console 100 ms per redraw, not 100 ms per row.
func (*Host) RenderPane ¶
RenderPane draws an open pane: the ui.render "pane" result's append.
func (*Host) RunCommand ¶
RunCommand runs a mod command through command.run; the end of the chain calls the command's own run($, args).
func (*Host) SetViewport ¶
SetViewport records the terminal size ui.render reports.
type Mod ¶
type Mod struct {
Plugin string `json:"plugin"`
ID string `json:"id"`
Name string `json:"name"`
API string `json:"api,omitempty"`
Hash string `json:"hash"`
Script string `json:"script,omitempty"`
Error string `json:"error,omitempty"`
}
Mod is one entry of GET /api/plugins/mods?surface=cli. Script is already the classic script pluginpkg.ModScript makes of the module.
type Notice ¶
type Notice struct {
Kind NoticeKind
Mod string // the mod's display name
Text string
}
Notice is something the console should react to between its own events.
type NoticeKind ¶
type NoticeKind int
NoticeKind says what changed.
const ( // NoticeRender: something a mod draws may have changed; render again. NoticeRender NoticeKind = iota // NoticeToast: Text is a notification from Mod. NoticeToast // NoticePanes: a pane was opened or closed. NoticePanes )
type Options ¶
type Options struct {
API API
// StateDir keeps each mod's $.state as JSON; empty keeps it in memory.
StateDir string
// Version is reported to app.start.
Version string
}
Options configure a Host.