Skip to content

Commit

Permalink
docs: merge the sender and severity in the DDS payload into the s…
Browse files Browse the repository at this point in the history
…ame field to simplify the protocol
  • Loading branch information
sxyazi committed Apr 4, 2024
1 parent 88bf032 commit 4ac8340
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
33 changes: 16 additions & 17 deletions docs/dds.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@ yazi --local-events=kind1,kind2 --remote-events=kind1,kind2
When an event of the specified kind is triggered, it will be output to `stdout`:

```sh
hover,0,30,1711957283332834,{"tab":0,"url":"/root/Downloads"}
cd,0,20,1711957542289249,{"tab":0,"url":"/root/Downloads"}
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 |
| severity | The severity of this message; if it's non-zero, indicates a [static message](/docs/plugins/utils#ps.pub_static) |
| sender | The sender ID of this message |
| body | The body of this message, which is a JSON string |
| 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 |

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 Expand Up @@ -83,13 +82,13 @@ This provides the ability to report Yazi's internal events in real-time, which i
`--local-events` stdout payload:

```sh
cd,1711957542289249,0,1711957542289249,{"tab":0,"url":"/root/Downloads"}
cd,1711957542289249,1711957542289249,{"tab":0,"url":"/root/Downloads"}
```

`--remote-events` stdout payload:

```sh
cd,0,10,1711957542289249,{"tab":0,"url":"/root/Downloads"}
cd,0,100,{"tab":0,"url":"/root/Downloads"}
```

### `hover`
Expand All @@ -114,13 +113,13 @@ cd,0,10,1711957542289249,{"tab":0,"url":"/root/Downloads"}
`--local-events` stdout payload:

```sh
hover,1711957283332834,0,1711957283332834,{"tab":0,"url":"/root/foo.txt"}
hover,1711957283332834,1711957283332834,{"tab":0,"url":"/root/foo.txt"}
```

`--remote-events` stdout payload:

```sh
hover,0,20,1711957283332834,{"tab":0,"url":"/root/foo.txt"}
hover,0,200,{"tab":0,"url":"/root/foo.txt"}
```

### `rename`
Expand Down Expand Up @@ -148,13 +147,13 @@ hover,0,20,1711957283332834,{"tab":0,"url":"/root/foo.txt"}
`--local-events` stdout payload:

```sh
rename,1711957878076791,0,1711957878076791,{"tab":0,"from":"/root/foo.txt","to":"/root/bar.txt"}
rename,1711957878076791,1711957878076791,{"tab":0,"from":"/root/foo.txt","to":"/root/bar.txt"}
```

`--remote-events` stdout payload:

```sh
rename,0,0,1711957878076791,{"tab":0,"from":"/root/foo.txt","to":"/root/bar.txt"}
rename,0,1711957878076791,{"tab":0,"from":"/root/foo.txt","to":"/root/bar.txt"}
```

### `bulk`
Expand Down Expand Up @@ -188,13 +187,13 @@ Iterator {
`--local-events` stdout payload:

```sh
yank,1711960311454247,0,1711960311454247,{"cut":false,"urls":["/root/foo.txt","/root/bar.txt"]}
yank,1711960311454247,1711960311454247,{"cut":false,"urls":["/root/foo.txt","/root/bar.txt"]}
```

`--remote-events` stdout payload:

```sh
yank,0,30,1711960311454247,{"cut":false,"urls":["/root/foo.txt","/root/bar.txt"]}
yank,0,300,{"cut":false,"urls":["/root/foo.txt","/root/bar.txt"]}
```

### `hi`
Expand Down
2 changes: 1 addition & 1 deletion docs/flavors/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ These flavors are placed in the `flavors` subdirectory of the Yazi configuration
Each flavor is a directory with a hyphen-separated name, ending in `.yazi`, and containing at least the following files:

```
bar.yazi/
~/.config/yazi/flavors/bar.yazi/
├── flavor.toml
├── tmtheme.xml
├── README.md
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You can extend Yazi's functionality through Lua plugins, which need to be placed
Each plugin is a directory with a hyphen-separated name, ending in `.yazi`, and containing at least the following files:

```
bar.yazi/
~/.config/yazi/plugins/bar.yazi/
├── init.lua
├── README.md
└── LICENSE
Expand Down
7 changes: 5 additions & 2 deletions docs/plugins/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,17 @@ With:
### `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 1 to 255
- `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()`
- `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.

Expand Down

0 comments on commit 4ac8340

Please sign in to comment.