Skip to main content

Dialogs​

A script can open a modal dialog - the command palette's shape: a full-surface scrim, a top-centered panel, the keyboard held while it stands. One dialog at a time, one live seat: a second open replaces the first, and the log says so. An interpreter reload closes the standing dialog on the next drain (its script died with its interpreter).

dropterm.dialog({
title = 'Build finished',
body = { { text = 'release build done in 12.4s',
style = { color = 'green' } } },
buttons = {
{ id = 'restart', label = 'Restart', class = 'accent' },
{ id = 'dismiss', label = 'Dismiss' },
},
})
dropterm.on('slot-event', function(p)
if p.slot == 'dialog' and p.element_id == 'restart' then ... end
end)

The spec is closed - every key it declares:

KeyWhereMeaning
titlethe dialog tablethe panel's title bar text
bodythe dialog tableoptional; the message, styled spans under the typed-answers rules
buttonsthe dialog tableone to three, unique non-empty ids; a dialog with zero or four opens nothing
idinside each buttonthe press event's element_id, and the button's #id for the cascade
labelinside each buttonthe visible label
classinside each buttonoptional; the accent class marks the primary action - the host builtin rule on dialog-button.accent carries the look, and a plugin's own rule out-styling it replaces it by cascade
accent(removed)was a button flag; one dropterm: line and ignored - class = 'accent' instead

A wrong shape costs the call one dropterm: log line and opens nothing. A button press emits slot-event with { surface = 'dialog', slot = 'dialog', element_id = <the button's id>, kind = 'press' }; Escape, the scrim's press, and a focus escape each emit kind = 'dismiss' with no element id. The dialog holds the keyboard while it stands - Tab cycles the buttons, Enter presses the focused one.

The trust model, stated as plainly as the plugins page states it: a plugin dialog mimics app UI by design - read before binding. A script's dialog can look exactly like DropTerm's own prompts, so read what asks before you answer, the same way you read a shell rc before you paste into it.

Input and pick kinds​

A dialog asks with buttons by default. Two more kinds ask for an answer: kind = 'input' opens one text field, and kind = 'pick' opens a single-select list. No kind is the button dialog above, so every script written before parses as it did. Each kind has its own closed keyset: a key of another kind is an unknown key there - it costs one dropterm: line, and nothing opens.

dropterm.dialog({
kind = 'input',
title = 'New branch',
body = { { text = 'The branch will track origin/main.' } },
placeholder = 'feature/…',
request_id = 'new-branch',
})
dropterm.on('slot-event', function(p)
if p.request_id == 'new-branch' and p.kind == 'input:submit' then
print('creating branch ' .. p.value)
end
end)
dropterm.dialog({
kind = 'pick',
title = 'Deploy where?',
items = {
{ id = 'staging', label = 'Staging' },
{ id = 'prod', label = 'Production', class = 'danger' },
},
request_id = 'pick-target',
})
dropterm.on('slot-event', function(p)
if p.kind == 'pick:select' and p.element_id == 'prod' then
print('deploying to production')
end
end)

The keys, per kind (title, body, and request_id are common to all three):

KeyKindMeaning
kindinput, pickoptional; 'input' or 'pick' - absent is the button dialog, and any other word costs one dropterm: line
request_idall threeoptional; a non-empty string of at most 64 characters, echoed in every event the dialog emits; absent from the payload when the script gave none
placeholderinputoptional; the field's hint text
valueinputoptional; the text the field starts with
itemspickone to fifty, in the order you list them; zero or fifty-one opens nothing
idinside each itemthe select event's element_id, and the row's #id for the cascade; unique and non-empty
labelinside each itemthe row's text
classinside each itemoptional; space-separated class names - the highlighted row also carries the selected class
styleinside each itemoptional; the row's inline declarations table, under the typed-answers rules

The input kind takes no buttons: Enter submits, and the host's own OK and Cancel buttons serve the pointer. The field is single-line - a pasted line break is dropped, and the rest of the paste joins. The pick kind takes no buttons either: Up and Down move the highlight, Enter or a click selects, and a list longer than the card scrolls with the wheel (the highlight does not scroll it).

The answers arrive as slot-event under their own kind words, beside the button dialog's press and dismiss:

WordKeysMeaning
input:submitthe four, plus value, plus request_id when giventhe user pressed Enter or OK; value is the field's text, whole
input:dismissthe four, plus request_id when givenEscape, the scrim's press, Cancel, or a focus escape
pick:selectthe four, plus request_id when giventhe chosen row's id is the element_id
pick:dismissthe four, plus request_id when givenEscape, the scrim's press, or a focus escape

A pick addresses its choice through element_id; among these kinds value rides input:submit only (a panel field's two words carry it too - panel fields). One live seat stands for the input and pick kinds too: a second open replaces the first - one dropterm: line, and the replaced one emits nothing.

An input dialog can ask for anything, and what is typed there reaches the script as plain text. That is the read-before-you-answer rule above with more at stake: a plugin's dialog can look exactly like a prompt you trust, and nothing marks it as the plugin's.