Skip to content

Commit

Permalink
docs: 0.3 update
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Aug 5, 2024
1 parent 5011a8e commit a3a6107
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
24 changes: 12 additions & 12 deletions docs/dds.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ It deeply integrates with a publish-subscribe model based on the Lua API.

- Local: the current instance, that is, the current Yazi process.
- Remote: instances other than the current instance.
- Static message: A message with a kind that starts with `@` will be persistently stored and automatically restored when a new instance starts. To un-persist, send `nil` to that kind.

## Usage {#usage}

Expand All @@ -34,8 +35,7 @@ The DDS has three usage:
### Command-line tool {#cli}

If you're in a Yazi subshell where the `$YAZI_ID` environment variable is set, you can send a message to the current instance using `ya pub`.

It requires a `<kind>` argument, which is consistent with [`ps.pub()`](/docs/plugins/utils#ps.pub):
It requires a `kind` argument, which is consistent with [`ps.pub()`](/docs/plugins/utils#ps.pub):

```sh
ya pub <kind> --str "string body"
Expand All @@ -46,12 +46,12 @@ ya pub <kind> --json '{"key":"json body"}'
ya pub extract --list "/root/a.zip" "/root/b.7z"
```

You can also send a message to a specified remote instance(s) using `ya pub-to`, with the required `<severity>` and `<kind>` arguments, consistent with [`ps.pub_to()`](/docs/plugins/utils#ps.pub_to):
You can also send a message to a specified remote instance(s) using `ya pub-to`, with the required `receiver` and `kind` arguments, consistent with [`ps.pub_to()`](/docs/plugins/utils#ps.pub_to):

```sh
ya pub-to <severity> <kind> --str "string body"
ya pub-to <severity> <kind> --list "a" "b" "c"
ya pub-to <severity> <kind> --json '{"key":"json body"}'
ya pub-to <receiver> <kind> --str "string body"
ya pub-to <receiver> <kind> --list "a" "b" "c"
ya pub-to <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`.
Expand Down Expand Up @@ -88,12 +88,12 @@ 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](/docs/plugins/utils#ps.pub_static) |
| body | The body of this message, which is a JSON string |
| Field | Description |
| -------- | ------------------------------------------------------------------------------------------------- |
| kind | The kind of the message |
| receiver | The remote instance ID that receives the message; if it's `0`, broadcasts to all remote instances |
| sender | The sender of the message |
| body | The body of the 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.

Expand Down
19 changes: 0 additions & 19 deletions docs/plugins/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,6 @@ With:
- `kind` - The same as `pub()`
- `value` - The same as `pub()`

### `pub_static(severity, kind, value)` {#ps.pub_static}

```lua
-- Broadcast and store a static message
ps.pub_static(10, "greeting", "Hello, World!")
-- Broadcast and remove a static message
ps.pub_static(10, "greeting", nil)
```

Broadcast a static message to all remote instances subscribed to this `kind` through `sub_remote()`:

- `severity` - Required, the severity of the message, which is an integer with a range of 0 to 65535
- `kind` - The same as `pub()`
- `value` - The same as `pub()`. If the value is `nil`, the static message will be unpersisted.

The message will be stored as static data to achieve state persistence, and when a new instance is created, it will receive all static messages broadcasted by `sub_remote()` before in descending order of `severity` to restore its state from the data.

If you simply want to broadcast a message to all remote instances, without the need for the message to be persisted, use `ps.pub_to()` with receiver `0` instead.

### `sub(kind, callback)` {#ps.sub}

```lua
Expand Down

0 comments on commit a3a6107

Please sign in to comment.