From a3a6107ebbed162caa97a9f70cecc87d214d2e1c Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 5 Aug 2024 09:23:34 +0800 Subject: [PATCH] docs: 0.3 update --- docs/dds.md | 24 ++++++++++++------------ docs/plugins/utils.md | 19 ------------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/docs/dds.md b/docs/dds.md index 56290ed3..9dcdf74e 100644 --- a/docs/dds.md +++ b/docs/dds.md @@ -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} @@ -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 `` 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 --str "string body" @@ -46,12 +46,12 @@ ya pub --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 `` and `` 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 --str "string body" -ya pub-to --list "a" "b" "c" -ya pub-to --json '{"key":"json body"}' +ya pub-to --str "string body" +ya pub-to --list "a" "b" "c" +ya pub-to --json '{"key":"json body"}' # If you're in a Yazi subshell, # you can obtain the ID of the current instance through `$YAZI_ID`. @@ -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. diff --git a/docs/plugins/utils.md b/docs/plugins/utils.md index ed5f54c2..a37d4dfc 100644 --- a/docs/plugins/utils.md +++ b/docs/plugins/utils.md @@ -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