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
18 changes: 9 additions & 9 deletions cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ impl App {
let span = error_span!("Recieved Daemon Event");
let _guard = span.enter();
match &event {
DaemonEvent::Raw(..) => {
trace!(event=?event);
DaemonEvent::Raw(bytes) => {
trace!(event=?event, num_bytes=bytes.len());
}
_ => {
info!(event=?event);
Expand All @@ -192,8 +192,8 @@ impl App {
DaemonEvent::ActiveSession(session_id) => {
self.state.daemon.set_active_session(session_id);
}
DaemonEvent::NewSession(session_id) => {
self.state.daemon.add_session(session_id);
DaemonEvent::NewSession(session_id, session_name) => {
self.state.daemon.add_session(session_id, session_name);
}
_ => {
todo!();
Expand All @@ -202,7 +202,7 @@ impl App {
}
Err(e) => {
error!(error=%e, "Error receiving daemon event");
break;
// break;
}
}
}
Expand Down Expand Up @@ -241,8 +241,8 @@ impl App {
match selection {
ui::traits::Selection::Index(i) => match self.state.mode {
AppMode::SelectingSession => {
let session = self.state.daemon.session_ids[i];
comm::send_event(&mut self.stream, CliEvent::SwitchSession(session)).await?;
let session = &self.state.daemon.sessions[i];
comm::send_event(&mut self.stream, CliEvent::SwitchSession(session.name.clone())).await?;
}
AppMode::Normal => {}
},
Expand Down Expand Up @@ -275,12 +275,12 @@ impl App {
self.state.mode = AppMode::SelectingSession;
self.state.ui.selector.query.clear();
self.state.ui.selector.list_state.select(Some(0));
self.state.ui.selector.selector_type = SelectorType::Fuzzy;
self.state.ui.selector.selector_type = SelectorType::Basic;
self.state
.ui
.selector
.list
.extend(self.state.daemon.session_ids.iter().map(|x| x.to_string()));
.extend(self.state.daemon.sessions.iter().map(|x| x.name.clone()));
self.state.ui.selector.displaying_list = self
.state
.ui
Expand Down
2 changes: 1 addition & 1 deletion cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Args {
pub enum Commands {
Attach {
#[arg(short = 's', long = "session")]
session_id: u32,
session_name: String,
},
Session {
#[command(subcommand)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ async fn run(command: Commands) -> Result<()> {
let stream = connect().await?;
debug!("Running command");
match command {
Commands::Attach { session_id } => {
Commands::Attach { session_name } => {
attach(
stream,
RequestBuilder::default()
.body(request::Attach {
id: Uuid::new_v4(),
session_id,
session_name,
create: true,
})
.build(),
Expand Down
11 changes: 9 additions & 2 deletions cli/src/states/status_line_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ impl StatusLineState {
pub fn apply_built_ins(&mut self, state: &AppState) {
for item in self.a.iter_mut().chain(self.b.iter_mut()).chain(self.c.iter_mut()) {
if item.as_str() == "active-session" {
if let Some(s) = state.daemon.active_session.map(|s| s.to_string()) {
*item = s;
if let Some(name) = state.daemon.active_session.and_then(|id| {
state
.daemon
.sessions
.iter()
.find(|session_info| session_info.id == id)
.map(|session_info| &session_info.name)
}) {
*item = name.clone();
} else {
*item = "".to_owned();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod test {

let attach = request::Attach {
id: Uuid::new_v4(),
session_id: 1,
session_name: "session".to_owned(),
create: true,
};
let cli_req = RequestBuilder::default().body(attach.clone()).build();
Expand Down
4 changes: 2 additions & 2 deletions core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum CliEvent {
SplitPaneHorizontal,
PrevPane,

SwitchSession(u32), // switch session - does nothing if session does not exist
SwitchSession(String), // switch session - does nothing if session does not exist

TerminalResize { rows: u16, cols: u16 },

Expand All @@ -26,7 +26,7 @@ pub enum DaemonEvent {
// session events
CurrentSessions(Vec<u32>),
ActiveSession(u32),
NewSession(u32),
NewSession(u32, String),
DeletedSession(u32),
// TODO: for window id
Disconnected,
Expand Down
2 changes: 1 addition & 1 deletion core/src/messages/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Message for DaemonRequestMessage {}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct Attach {
pub id: Uuid,
pub session_id: u32,
pub session_name: String,
pub create: bool,
}
impl RequestBody for Attach {
Expand Down
24 changes: 18 additions & 6 deletions core/src/states.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
/// comprehensive summary of the state of the daemon
use serde::{Deserialize, Serialize};

#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct SessionInfo {
pub id: u32,
pub name: String,
}

#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct DaemonState {
pub session_ids: Vec<u32>,
pub sessions: Vec<SessionInfo>,
pub active_session: Option<u32>,
// window_ids: Vec<u32>,
// pub active_window: Option<u32>,
}

impl DaemonState {
pub fn set_sessions(&mut self, session_ids: Vec<u32>) {
self.session_ids = session_ids;
pub fn set_sessions(&mut self, sessions: Vec<(u32, String)>) {
self.sessions = sessions
.into_iter()
.map(|(id, name)| SessionInfo { id, name })
.collect();
}
pub fn add_session(&mut self, session_id: u32) {
let i = self.session_ids.binary_search(&session_id).unwrap_or_else(|i| i);
self.session_ids.insert(i, session_id);
pub fn add_session(&mut self, id: u32, name: String) {
let i = self
.sessions
.binary_search_by_key(&id, |info| info.id)
.unwrap_or_else(|i| i);
self.sessions.insert(i, SessionInfo { id, name });
}
// pub fn remove_session(&mut self, session_id: u32) {
// self.session_ids.retain(|s| s != &session_id);
Expand Down
23 changes: 12 additions & 11 deletions daemon/src/actors/client_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum ClientConnectionEvent {
Disconnect,

// client side state update events
NewSession(u32),
NewSession(u32, String),

// variants related to initialization phase
InitialAttach(u32), // invoked directly by the daemon
Expand Down Expand Up @@ -51,10 +51,10 @@ impl ClientConnection {
id: Uuid,
stream: UnixStream,
session_manager_handle: SessionManagerHandle,
connecting_session_id: u32,
initial_session_name: &str,
) -> Result<ClientConnectionHandle> {
let client = Self::new(id, stream, session_manager_handle);
client.run(connecting_session_id)
client.run(initial_session_name)
}
fn new(id: Uuid, stream: UnixStream, session_manager_handle: SessionManagerHandle) -> Self {
let (tx, rx) = mpsc::channel(10);
Expand All @@ -69,21 +69,22 @@ impl ClientConnection {
state: ClientConnectionState::Unattached,
}
}
fn run(mut self, initial_session_id: u32) -> Result<ClientConnectionHandle> {
fn run(mut self, initial_session_name: &str) -> Result<ClientConnectionHandle> {
let handle_clone = self.handle.clone();
let session_name = initial_session_name.to_owned();
let _task = tokio::spawn(
async move {
let handle = self.handle.clone();
self.session_manager_handle.client_connect(self.id, handle.clone(), initial_session_id, true).await?;
self.session_manager_handle.client_connect(self.id, handle.clone(), Some(session_name), true).await?;
loop {
use remux_core::events::CliEvent;
tokio::select! {
Some(event) = self.rx.recv() => {
let span = error_span!("Recieved Client Connection Event");
let _guard = span.enter();
match &event {
SessionOutput(..) => {
trace!(event=?event);
SessionOutput(bytes) => {
trace!(event=?event, num_bytes=bytes.len());
}
_ => {
info!(event=?event);
Expand Down Expand Up @@ -119,8 +120,8 @@ impl ClientConnection {
SessionOutput(bytes) => {
comm::send_event(&mut self.stream, DaemonEvent::Raw(bytes)).await.unwrap();
}
NewSession(session_id) => {
comm::send_event(&mut self.stream, DaemonEvent::NewSession(session_id)).await.unwrap();
NewSession(session_id, session_name) => {
comm::send_event(&mut self.stream, DaemonEvent::NewSession(session_id, session_name)).await.unwrap();
}
_ => {
error!(event=?event, state=?self.state, "Unhandled or invalid event for current state");
Expand Down Expand Up @@ -165,8 +166,8 @@ impl ClientConnection {
CliEvent::PrevPane => {
self.session_manager_handle.user_iterate_pane(self.id, false).await.unwrap();
},
CliEvent::SwitchSession(session_id) => {
self.session_manager_handle.client_switch_session(self.id, session_id).await.unwrap();
CliEvent::SwitchSession(session_name) => {
self.session_manager_handle.client_switch_session(self.id, session_name).await.unwrap();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/actors/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Pane {

async fn handle_pty_output(&mut self, bytes: Bytes) -> Result<()> {
self.vte.process(&bytes);
self.handle.rerender().await
self.handle_rerender().await
}

// TODO: below code is bad and unused, need better diffing solution
Expand Down
17 changes: 13 additions & 4 deletions daemon/src/actors/session.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bytes::Bytes;
use handle_macro::Handle;
use tokio::sync::mpsc;
use tracing::Instrument;
use tracing::{Instrument, Span};

use crate::{
actors::{
Expand All @@ -26,6 +26,8 @@ pub enum SessionEvent {
UserKillPane,
Redraw,

RenameSession(String),

// output
WindowOutput(Bytes),
TerminalResize { rows: u16, cols: u16 },
Expand All @@ -35,23 +37,25 @@ use SessionEvent::*;

pub struct Session {
id: u32,
name: String,
handle: SessionHandle,
session_manager_handle: SessionManagerHandle,
rx: mpsc::Receiver<SessionEvent>,
window_handle: WindowHandle,
}
impl Session {
#[instrument(parent=None, skip(session_manager_handle), name="Session")]
pub fn spawn(id: u32, session_manager_handle: SessionManagerHandle) -> Result<SessionHandle> {
let session = Session::new(id, session_manager_handle);
pub fn spawn(id: u32, name: String, session_manager_handle: SessionManagerHandle) -> Result<SessionHandle> {
let session = Session::new(id, name, session_manager_handle);
session.run()
}
fn new(id: u32, session_manager_handle: SessionManagerHandle) -> Self {
fn new(id: u32, name: String, session_manager_handle: SessionManagerHandle) -> Self {
let (tx, rx) = mpsc::channel(10);
let handle = SessionHandle { tx };
let window_handle = Window::spawn(handle.clone()).unwrap();
Self {
id,
name,
session_manager_handle,
handle,
rx,
Expand Down Expand Up @@ -101,6 +105,11 @@ impl Session {
TerminalResize { rows, cols } => {
self.window_handle.terminal_resize(rows, cols).await.unwrap();
}
RenameSession(name) => {
let span = Span::current();
self.name = name.clone();
span.record("name", name);
}
}
}
}
Expand Down
Loading