difftreelog
feat remote editor
in: trunk
2 files changed
crates/remowt-link-shared/Cargo.tomldiffbeforeafterboth1[package]2name = "remowt-link-shared"3version = "0.1.0"4edition = "2021"56[dependencies]7bifrostlink.workspace = true8serde = { version = "1.0.208", features = ["derive"] }9serde_json = "1.0.125"10thiserror = "1.0.63"11tokio = "1.39.3"1[package]2name = "remowt-link-shared"3version = "0.1.0"4edition = "2021"56[dependencies]7bifrostlink.workspace = true8bytes.workspace = true9serde = { workspace = true, features = ["derive"] }10serde_json.workspace = true11thiserror = "1.0.63"12tokio = { workspace = true, features = ["fs"] }13remowt-fs.workspace = true14remowt-systemd.workspace = true15ui-prompt.workspace = true16camino = { workspace = true, features = ["serde1"] }17remowt-pty.workspace = truecrates/remowt-link-shared/src/editor.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/remowt-link-shared/src/editor.rs
@@ -0,0 +1,33 @@
+use std::future::Future;
+
+use bifrostlink::declarative::endpoints;
+use bifrostlink::{Config, Rpc};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
+pub enum Error {
+ #[error("editor failed: {0}")]
+ Failed(String),
+}
+
+pub trait EditorBackend: Send + Sync {
+ fn open_editor(&self, socket_path: String) -> impl Future<Output = Result<(), Error>> + Send;
+}
+
+pub struct EditorEndpoints<E>(pub E);
+
+#[endpoints(ns = 8)]
+impl<E: EditorBackend + 'static> EditorEndpoints<E> {
+ #[endpoints(id = 1)]
+ async fn open_editor(&self, socket_path: String) -> Result<(), Error> {
+ self.0.open_editor(socket_path).await
+ }
+}
+
+pub fn serve_editor<E, C>(rpc: &mut Rpc<C>, editor: E)
+where
+ E: EditorBackend + Send + Sync + 'static,
+ C: Config,
+{
+ EditorEndpoints(editor).register_endpoints(rpc);
+}