DDS
This is a new feature that will be released in Yazi 0.2.5 and currently requires the latest code.
Document is still being written...
DDS (Data Distribution Service) is designed to achieve communication and state synchronization between multiple Yazi instances, as well as state persistence. It is built on a client-server architecture but does not require running additional server processes.
It deeply integrates with a publish-subscribe model based on the Lua API.
Concept
- Local: the current instance, that is, the current Yazi process.
- Remote: instances other than the current instance.
Usage
The DDS has three usage:
- Plugin API: Using Lua-based publish-subscribe model as the carrier.
- Command-line tool: Using
ya
command-line tool as the carrier. - Real-time
stdout
reporting: Usingstdout
as the carrier.
Command-line tool
You can send a message to the remote instance(s) using ya pub
, with the two required receiver
and kind
arguments consistent with ps.pub_to()
:
ya pub <receiver> <kind> --str "string body"
ya pub <receiver> <kind> --json '{"key": "json body"}'
# If you're in a Yazi subshell,
# you can obtain the ID of the current instance through `$YAZI_ID`.
ya pub "$YAZI_ID" dds-cd --str "/root"
You can also send a static message to all remote instances using ya pub-static
, with its severity
and kind
arguments consistent with ps.pub_static()
:
ya pub-static <severity> <kind> --str "string body"
ya pub-static <severity> <kind> --json '{"key": "json body"}'
For greater convenience in integrating within the command-line environment, they support two body formats:
- String: a straightforward format, suitable for most scenarios, without the need for additional tools for encoding
- JSON: for advanced needs, support for types and more complex data can be represented through the JSON format
Note that ya
is a standalone CLI program introduced since Yazi 0.2.5, it might conflict with the shell wrapper you setup before, see Introduce a standalone CLI program for details.
Real-time stdout
reporting
You can specify the --local-events
and --remote-events
options when starting Yazi:
# Local events
yazi --local-events=kind1,kind2
# Remote events
yazi --remote-events=kind1,kind2
# Both local and remote events
yazi --local-events=kind1,kind2 --remote-events=kind1,kind2
When an event of the specified kind is received, it will be output to stdout
:
hover,0,200,{"tab":0,"url":"/root/Downloads"}
cd,0,100,{"tab":0,"url":"/root/Downloads"}
One payload per line, each payload contains the following fields separated by commas:
Field | Description |
---|---|
kind | The kind of this message |
receiver | The remote instance ID that receives this message; if it's 0 , broadcasts to all remote instances |
sender / severity | The sender of this message if greater than 65535 ; otherwise, the severity of this static message |
body | The body of this message, which is a JSON string |
This provides the ability to report Yazi's internal events in real-time, which is useful for external tool integration (such as Neovim), as they will be able to subscribe to the events triggered by the user behavior.