Writing an integration
Ce contenu n’est pas encore disponible dans votre langue.
An integration is one JSON manifest. Make your own from the UI (Integrations → New…, then Save as preset from the Bindings page, Save the look in use for a theme, Save as template from the hub editor) or by hand in ~/.config/virgul/integrations/<id>.json (a file of a built-in’s id replaces it).
Skeleton
Section titled “Skeleton”{ "id": "obs", "name": "OBS Studio", "version": 1, "author": "you", "icon": "camera", "os": ["linux", "windows", "darwin"], "description": "Scenes, recording and streaming.", "url": "https://obsproject.com", "requires": [{ "command": "obs-cmd", "why": "talks to OBS", "install": "cargo install obs-cmd", "check": "obs-cmd --version" }], "servers": { "obs": "virgul state-server --every 2s" }, "strings": { "en": { "rec": "Record" }, "fr": { "rec": "Enregistrer" } }, "templates": [], "presets": [], "themes": []}os: the systems it works on (none: all).requires: programs looked up in PATH,check/expectfor the version,readyfor a warning.stringsper language, used as%{t.key}.
Templates
Section titled “Templates”{ "id": "record", "name": "Record", "version": 1, "kind": "item", "params": [{ "key": "name", "label": "Name", "kind": "text", "default": "%{t.rec}" }], "item": { "label": "%{name}", "icon": "lucide:circle-dot#ff4444", "action": "obs-cmd recording toggle", "state": "obs-cmd recording status", "state_server": "obs" } }kind:item(a bubble),hub,gesture,chord.- Params:
text,bool,number,choice(options, orsource— a state server query answering a JSON list),key;multiple,required,default,pattern,preselect. - Placeholders
%{key},%{key.field}, filters|q(shell-quoted — always for values going into commands),|json,|first,|count;"if": "path",{"each": …, "as": …, "do": …},{"use": "<template>", "with": {…}}. - Icons:
lucide:<name>[#rrggbb].
Actions
Section titled “Actions”An integration can bring actions that bindings run directly (Integration in the action editors), instead of a command written into each binding:
"actions": [{ "id": "scene", "name": "Switch scene", "os": ["linux", "windows"], "params": [{ "key": "scene", "label": "Scene", "kind": "choice", "source": { "server": "obs", "query": "obs-cmd scene list --json" } }], "program": "obs-cmd", "args": ["scene", "switch", "%{scene}"], "target": "pointer", "response": { "success": "ok", "error": "message" } }]programis a literal executable (looked up in PATH), eachargsentry one argument: no shell, so no|q(refused). Params are the templates’ ones;namemay be%{t.key}.- An entry that is only
%{key}of a multiple choice gives one argument per option chosen (none when nothing is); inside a text (--ids=%{key}) they are joined by spaces. - Bindings keep a reference —
{"integration_action": {"integration": "obs", "action": "scene", "values": {"scene": "Live"}}}— so updating the integration updates every binding; a disabled or missing integration leaves them saved but unavailable. - A chosen value is checked against the choices each time the action runs; a
source’s answer is reused for a minute while it holds the values. target:pointer(default: the window under the pointer gets the focus first) orfocus(left as is).response: stdout is a JSON object whose boolean field tells success.- Runs in order, outside the input loop, 3 s and 16 KiB of output at most, with the security settings — unless
"detach": true: the program is started and left running (an app, a terminal), with no time limit and noresponse. - Lists, overlay hints and wheel chips show the values chosen (their labels), else the action’s name. They count in the risk as commands.
Presets
Section titled “Presets”{ "id": "browser", "name": "Browser", "class": "firefox|chromium", "trigger": "mouse_right", "version": 1, "gestures": [{ "name": "back", "pattern": [[-1, 0]], "key_combo": "alt+Left", "key_combo_mac": "cmd+[" }], "chords": [], "hubs": [] }Each binding becomes a template; raising version offers Update to who turned it on. Actions may carry per_os (see Actions).
Themes
Section titled “Themes”See Themes: overlay keys, tokens, a palette and palette_files.
State servers
Section titled “State servers”virgul state-server runs each query as a shell command and answers its output (watched: again every --every). Write queries that print JSON: {"text": …, "value": 0.4, "on": true, "color": "#…"} for a state, a list of bubbles for a dynamic branch.
The installer shows what your integration runs (risk levels). Keep it honest and minimal: the fewer background programs, the fewer questions.
Publishing in the catalog
Section titled “Publishing in the catalog”- Put the manifest in the repository (
internal/integration/builtin/for built-ins, generated bygen_tools.pyfor the command line tool ones). - Add an entry to
integrations/index.jsonwith the same version; raise both on each change. - Run
go test ./internal/integration— it builds every template in every language and checks every command withsh -nand every icon.