diff --git a/distant-core/src/client/lsp/data.rs b/distant-core/src/client/lsp/data.rs index 2dfc028..6591a51 100644 --- a/distant-core/src/client/lsp/data.rs +++ b/distant-core/src/client/lsp/data.rs @@ -397,7 +397,7 @@ impl LspContent { let key = key .as_str() .ok_or(LspSessionInfoError::InvalidSessionInfoParams)?; - Ok(format!("DISTANT DATA {} {} {}", host, port, key).parse()?) + Ok(format!("DISTANT CONNECT {} {} {}", host, port, key).parse()?) } _ => Err(LspSessionInfoError::MissingSessionInfoParams), } diff --git a/distant-core/src/client/session/info.rs b/distant-core/src/client/session/info.rs index 7c0ccb9..e12ea02 100644 --- a/distant-core/src/client/session/info.rs +++ b/distant-core/src/client/session/info.rs @@ -50,13 +50,13 @@ impl FromStr for SessionInfo { type Err = SessionInfoParseError; fn from_str(s: &str) -> Result { - let mut tokens = s.split(' ').take(5); + let mut tokens = s.trim().split(' ').take(5); // First, validate that we have the appropriate prefix if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "DISTANT" { return Err(SessionInfoParseError::BadPrefix); } - if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "DATA" { + if tokens.next().ok_or(SessionInfoParseError::BadPrefix)? != "CONNECT" { return Err(SessionInfoParseError::BadPrefix); } @@ -101,7 +101,7 @@ impl SessionInfo { let host = env::var("DISTANT_HOST").map_err(to_err)?; let port = env::var("DISTANT_PORT").map_err(to_err)?; let key = env::var("DISTANT_KEY").map_err(to_err)?; - Ok(format!("DISTANT DATA {} {} {}", host, port, key).parse()?) + Ok(format!("DISTANT CONNECT {} {} {}", host, port, key).parse()?) } /// Loads session from the next line available in this program's stdin @@ -138,10 +138,10 @@ impl SessionInfo { } /// Converts to unprotected string that exposes the key in the form of - /// `DISTANT DATA ` + /// `DISTANT CONNECT ` pub fn to_unprotected_string(&self) -> String { format!( - "DISTANT DATA {} {} {}", + "DISTANT CONNECT {} {} {}", self.host, self.port, self.key.unprotected_to_hex_key() diff --git a/src/opt.rs b/src/opt.rs index 6df74a7..93e9184 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -355,7 +355,7 @@ impl FromStr for BindAddress { )] #[strum(serialize_all = "snake_case")] pub enum SessionOutput { - /// Session is in a file in the form of `DISTANT DATA ` + /// Session is in a file in the form of `DISTANT CONNECT ` File, /// Special scenario where the session is not shared but is instead kept within the @@ -364,7 +364,7 @@ pub enum SessionOutput { Keep, /// Session is stored and retrieved over anonymous pipes (stdout/stdin) - /// in form of `DISTANT DATA ` + /// in form of `DISTANT CONNECT ` Pipe, /// Special scenario where the session is not shared but is instead kept within the @@ -409,11 +409,11 @@ pub enum SessionInput { /// * `DISTANT_KEY=` Environment, - /// Session is in a file in the form of `DISTANT DATA ` + /// Session is in a file in the form of `DISTANT CONNECT ` File, /// Session is stored and retrieved over anonymous pipes (stdout/stdin) - /// in form of `DISTANT DATA ` + /// in form of `DISTANT CONNECT ` Pipe, /// Session is stored and retrieved from the initializeOptions of the initialize request diff --git a/src/subcommand/listen.rs b/src/subcommand/listen.rs index 9b4f3b4..2c4234c 100644 --- a/src/subcommand/listen.rs +++ b/src/subcommand/listen.rs @@ -7,7 +7,10 @@ use distant_core::{ DistantServer, DistantServerOptions, SecretKey32, UnprotectedToHexKey, XChaCha20Poly1305Codec, }; use log::*; -use tokio::{io, task::JoinError}; +use tokio::{ + io::{self, AsyncWriteExt}, + task::JoinError, +}; #[derive(Debug, Display, Error, From)] pub enum Error { @@ -105,7 +108,11 @@ async fn run_async(cmd: ListenSubcommand, _opt: CommonOpt, is_forked: bool) -> R .await?; // Print information about port, key, etc. - println!("DISTANT DATA -- {} {}", port, key_hex_string); + // NOTE: Following mosh approach of printing to make sure there's no garbage floating around + println!("\r"); + println!("DISTANT CONNECT -- {} {}", port, key_hex_string); + println!("\r"); + io::stdout().flush().await?; // For the child, we want to fully disconnect it from pipes, which we do now #[cfg(unix)]