Output channels
dropterm.output(name) gives a plugin its own visible log: one titled
section in the right rail, below the panel views unless the
panel_rail_sections config key orders the rail otherwise. The
section stands in the right rail alone - a channel never stands on the
left, whatever left_rail_enabled says. output is the factory verb,
and the rail's panel_rail_enabled container is the target. A
script's lines in the shared dropterm: log interleave with every
other plugin's. A channel is the plugin's own.
local build = dropterm.output('build')
build:line('compile started')
build:line('compile done in 12.4s')
build:clear()
| Method | Does |
|---|---|
line | handle:line(text) appends one row: a string verbatim, a number as tostring renders it; anything else costs one dropterm: line and writes nothing |
clear | handle:clear() empties the channel; its section stands |
The name is a slug - lowercase letters, digits, hyphens, up to 64
characters, the rule every script id follows. A bad name costs one
dropterm: line and returns nil.
A channel is scoped to its plugin: its identity is the pair (plugin,
name), so two plugins may both open build and each keeps its own
lines. The section's title is the name alone - two same-named channels
are two sections that style alike. Calling dropterm.output again
with the same name, from anywhere in the plugin, returns a handle to
the same channel.
A channel opened inside a handler belongs to the plugin that registered the handler - even when another plugin's handler called it:
dropterm.command('build', 'Run the build', function()
local log = dropterm.output('build')
log:line('compile started')
end)
The caps: a channel keeps its newest 200 lines (the oldest leave
first), and a line keeps its first 4,096 bytes (a longer line is cut
on a character boundary, one dropterm: line). Lines are plain wrapping
text, one output-line row each inside an output-channel section -
the style engine's names for them.
The rail's gate stands: panel_rail_enabled (default off) decides
whether the sections show, and a script never flips the key. The host
fills the channels either way. The first channel to open while the
rail is off costs one dropterm: line saying so, once a session.
The content lives in the host, never in the interpreter: a hot reload
or a hard-cap teardown keeps every line. The script itself starts
over - its load-time lines append to what is already there, so a
script that wants a clean log calls clear() as it loads. Nothing
survives a restart - a channel is a view, not storage. Removing a
plugin's directory drops its channels.
A channel shows whatever a plugin writes, under a title the plugin chooses. That is the full-trust model again, with nothing at stake beyond the rail's space.
Progress
A plugin running a long job across dispatches can show it in the
chips band and offer a way to stop it. dropterm.progress
is one seat: while an item is open, the chip leads the chips band -
◐ Deploying 30% with a total, ◐ Deploying … without one.
local dropterm = require('dropterm')
dropterm.progress.open('deploy', { title = 'Deploying', total = 10, cancellable = true })
dropterm.progress.advance('deploy', 3)
dropterm.progress.finish('deploy')
dropterm.on('slot-event', function(p)
if p.kind == 'cancel' and p.element_id == 'deploy' then
-- the user clicked the chip: stop the work, then finish it
dropterm.progress.finish('deploy')
end
end)
The example shows each call's shape in turn. A real handler opens the item once, advances it from each dispatch as the job moves, and finishes it when the job ends, on its own or because the user clicked.
progress has three calls, and the id addresses the item across them:
| Call | Does |
|---|---|
open | progress.open(id, opts) stands one item; the chip appears |
advance | progress.advance(id, by) moves it forward. by is a positive whole number, 1 when left out, and the item stops at its total |
finish | progress.finish(id) removes the item; the chip leaves |
The options are a closed set:
| Option | Holds |
|---|---|
title | a string; the id when absent |
total | a positive whole number; absent means the work cannot be measured, and the chip shows … |
cancellable | true or false; false when absent |
The id is a slug - lowercase letters, digits, hyphens, up to 64 characters, the rule every script id follows. Anything else in a call
- an unknown option, an empty
titleor one that is not a string, a zero or fractionaltotal, abythat is not a positive whole number - costs onedropterm:line and changes nothing; the handler runs on.
One item is live at a time. An open naming the id already standing
costs one line and changes nothing. An open naming another id
replaces the standing item, at the cost of one line naming both. An
advance or finish naming an id nothing stands for costs one line.
Advancing an item with no total is quiet: no line, no change.
Reaching the total does not finish the item. The chip reads 100%
until the script calls finish, because wrap-up work is still work.
The cancel is an intent. Clicking a cancellable chip emits
slot-event with { surface = 'band', slot = 'progress', element_id = <the item's id>, kind = 'cancel' } - exactly the four
keys. The chip stays where it is: the script decides what stopping
means, and calls finish once the work has stopped. A chip that is not
cancellable copies its text on click, the way a copy chip does.
The chip never outlives its interpreter. A hot reload or a hard-cap
teardown clears it, at the cost of one dropterm: line naming the
item, and the reloaded script starts with an empty seat. Each call is
its own dispatch: the host holds the item between them, so nothing has
to keep running.
No key hides the chip: Ctrl+Shift+B hides and shows the whole
chips band, and the plugin's item stands meanwhile, so showing it
again shows whatever still stands.