8000 feat(minimald): track terminal meta, send in ListSessions RPC by twitchyliquid64 · Pull Request #421 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ clap_complete = { version = "4.6" }
codespan-reporting = { version = "0.13", features = ["serialization"] } # Keep in sync with nickel-lang-core
constcat = "0.6"
copy_dir = "0.1.3"
chrono = {version = "0.4", features = ["serde", "std"]}
dirs = "6"
fd-lock = "4"
either = { version = "1.16", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/minimald-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ publish.workspace = true

[dependencies]
constcat.workspace = true
chrono.workspace = true
serde.workspace = true

sessions.workspace = true
26 changes: 26 additions & 0 deletions crates/minimald-rpc/src/lib.rs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//!
//! The server-side serving glue lives in the `minimald` crate.

use chrono::Utc;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use sessions::SessionId;

Expand Down Expand Up @@ -97,11 +98,36 @@ impl OneshotSshRpc for GetVersion {
/// An RPC to list sessions managed by this minimald.
pub struct ListSessions;

/// Describes how many times a bell fired, as well as when it last fired.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Bell {
pub count: usize,
pub last: chrono::DateTime<Utc>,
}

/// Describes a terminal title
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Title {
pub value: String,
pub updated_at: chrono::DateTime<Utc>,
}

/// Describes attributes about a running session.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RunningSessionAttrs {
pub last_stdout: Option<chrono::DateTime<Utc>>,
pub last_stdin: Option<chrono::DateTime<Utc>>,
pub title: Option<Title>,
pub audible_bell: Option<Bell>,
pub visual_bell: Option<Bell>,
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/// An entry in the ListSessions response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ListSessionsEntry {
pub id: SessionId,
pub name: Option<String>,
pub attrs: Option<RunningSessionAttrs>,
}

/// The response to the [`ListSessions`] RPC.
Expand Down
1 change: 1 addition & 0 deletions crates/minimald/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ camino.workspace = true
clap.workspace = true
clap_complete.workspace = true
constcat.workspace = true
chrono.workspace = true
dirs.workspace = true
either.workspace = true
futures.workspace = true
Expand Down
17 changes: 17 additions & 0 deletions crates/minimald/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ async fn serve_list_sessions(s: ServerStateHandle, c: RuChannel<Msg>) {
.map(|i| ListSessionsEntry {
id: i.id,
name: i.name,
attrs: i.attrs.map(|a| minimald_rpc::RunningSessionAttrs {
last_stdout: a.stdout_last.map(|i| i.into()),
last_stdin: a.stdin_last.map(|i| i.into()),
title: a.title.map(|(value, set_at)| minimald_rpc::Title {
value,
updated_at: set_at.into(),
}),
visual_bell: a.visual_bell.1.map(|t| minimald_rpc::Bell {
count: a.visual_bell.0,
last: t.into(),
}),
audible_bell: a.audible_bell.1.map(|t| minimald_rpc::Bell {
count: a.audible_bell.0,
last: t.into(),
}),
}),
})
.collect(),
})
Expand Down Expand Up @@ -296,6 +312,7 @@ mod tests {
vec![ListSessionsEntry {
id: create_session.id,
name: Some("my session".to_string()),
attrs: None,
}]
);
}
Expand Down
16 changes: 15 additions & 1 deletion crates/minimald/src/session.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
ChannelConfig,
session_host::{self, WinSize},
session_host::{self, HostAttrs, WinSize},
};
use mctx::ConfigBuilder;
use paths::DaemonAbsPath;
Expand Down Expand Up @@ -40,6 +40,7 @@ enum SessionMessage {
Channel<Msg>,
ChannelConfig,
),
GetHostAttrs(oneshot::Sender<Option<HostAttrs>>),
}

/// Manages a running session.
Expand Down Expand Up @@ -98,6 +99,12 @@ impl<S: SessionObject> Session<S> {
SessionMessage::Attach(r, session_hnd, channel, config) => {
let _ = r.send(self.attach(session_hnd, channel, config).await);
}
SessionMessage::GetHostAttrs(r) => {
let _ = r.send(match self.host.as_ref() {
None => None,
Some(h) => h.get_attrs().await.ok(),
});
}
}
}

Expand Down Expand Up @@ -190,6 +197,13 @@ impl SessionHandle {
let _ = self.0.send(SessionMessage::GetWorkspacePath(send)).await;
recv.await.expect("corresponding session is dead")
}
/// Returns the host attributes of the running session, if any.
pub async fn get_attrs(&self) -> Option<HostAttrs> {
let (send, recv) = oneshot::channel();
// Ignore send errors - the recv will also fail.
let _ = self.0.send(SessionMessage::GetHostAttrs(send)).await;
recv.await.expect("corresponding session is dead")
}

/// Returns a minimal context initialized on this sessions' worktree.
pub async fn context(&self) -> Result<mctx::Context, String> {
Expand Down
Loading
Loading
0