|
| 1 | +# plugin |
| 2 | + |
| 3 | +Lua-based plugin system for extending Matcha. Plugins are loaded from `~/.config/matcha/plugins/` and run inside a sandboxed Lua VM (no `os`, `io`, or `debug` libraries). |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +The `Manager` creates a Lua VM at startup, registers the `matcha` module, and loads all plugins from the user's plugins directory. Plugins can be either a single `.lua` file or a directory with an `init.lua` entry point. |
| 8 | + |
| 9 | +Plugins interact with Matcha by registering callbacks on hooks: |
| 10 | + |
| 11 | +```lua |
| 12 | +local matcha = require("matcha") |
| 13 | + |
| 14 | +matcha.on("email_received", function(email) |
| 15 | + matcha.log("New email from: " .. email.from) |
| 16 | + matcha.notify("New mail!", 3) |
| 17 | +end) |
| 18 | +``` |
| 19 | + |
| 20 | +## Lua API (`matcha` module) |
| 21 | + |
| 22 | +| Function | Description | |
| 23 | +|----------|-------------| |
| 24 | +| `matcha.on(event, callback)` | Register a callback for a hook event | |
| 25 | +| `matcha.log(msg)` | Log a message to stderr | |
| 26 | +| `matcha.notify(msg [, seconds])` | Show a temporary notification in the TUI (default 2s) | |
| 27 | +| `matcha.set_status(area, text)` | Set a persistent status string for a view area (`"inbox"`, `"composer"`, `"email_view"`) | |
| 28 | + |
| 29 | +## Hook events |
| 30 | + |
| 31 | +| Event | Callback argument | Description | |
| 32 | +|-------|-------------------|-------------| |
| 33 | +| `startup` | — | Matcha has started | |
| 34 | +| `shutdown` | — | Matcha is exiting | |
| 35 | +| `email_received` | Lua table with `uid`, `from`, `to`, `subject`, `date`, `is_read`, `account_id`, `folder` | New email arrived | |
| 36 | +| `email_viewed` | Same as `email_received` | User opened an email | |
| 37 | +| `email_send_before` | Table with `to`, `cc`, `subject`, `account_id` | About to send an email | |
| 38 | +| `email_send_after` | Same as `email_send_before` | Email sent successfully | |
| 39 | +| `folder_changed` | Folder name (string) | User switched folders | |
| 40 | +| `composer_updated` | Table with `body`, `body_len`, `subject`, `to` | Composer content changed | |
| 41 | + |
| 42 | +## Available plugins |
| 43 | + |
| 44 | +The following example plugins ship in `~/.config/matcha/plugins/`: |
| 45 | + |
| 46 | +- `email_age.lua` |
| 47 | +- `recipient_counter.lua` |
| 48 | + |
| 49 | +## Files |
| 50 | + |
| 51 | +| File | Description | |
| 52 | +|------|-------------| |
| 53 | +| `plugin.go` | Plugin manager — Lua VM setup, plugin discovery and loading, notification/status state | |
| 54 | +| `hooks.go` | Hook definitions, callback registration, and hook invocation helpers | |
| 55 | +| `api.go` | `matcha` Lua module registration (`on`, `log`, `notify`, `set_status`) | |
0 commit comments