Skip to content

Commit

Permalink
Add spacing and change to DISTANT CONNECT from DISTANT DATA
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Oct 13, 2021
1 parent d431264 commit 4050a42
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion distant-core/src/client/lsp/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
10 changes: 5 additions & 5 deletions distant-core/src/client/session/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ impl FromStr for SessionInfo {
type Err = SessionInfoParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -138,10 +138,10 @@ impl SessionInfo {
}

/// Converts to unprotected string that exposes the key in the form of
/// `DISTANT DATA <host> <port> <key>`
/// `DISTANT CONNECT <host> <port> <key>`
pub fn to_unprotected_string(&self) -> String {
format!(
"DISTANT DATA {} {} {}",
"DISTANT CONNECT {} {} {}",
self.host,
self.port,
self.key.unprotected_to_hex_key()
Expand Down
8 changes: 4 additions & 4 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host> <port> <key>`
/// Session is in a file in the form of `DISTANT CONNECT <host> <port> <key>`
File,

/// Special scenario where the session is not shared but is instead kept within the
Expand All @@ -364,7 +364,7 @@ pub enum SessionOutput {
Keep,

/// Session is stored and retrieved over anonymous pipes (stdout/stdin)
/// in form of `DISTANT DATA <host> <port> <key>`
/// in form of `DISTANT CONNECT <host> <port> <key>`
Pipe,

/// Special scenario where the session is not shared but is instead kept within the
Expand Down Expand Up @@ -409,11 +409,11 @@ pub enum SessionInput {
/// * `DISTANT_KEY=<key>`
Environment,

/// Session is in a file in the form of `DISTANT DATA <host> <port> <key>`
/// Session is in a file in the form of `DISTANT CONNECT <host> <port> <key>`
File,

/// Session is stored and retrieved over anonymous pipes (stdout/stdin)
/// in form of `DISTANT DATA <host> <port> <key>`
/// in form of `DISTANT CONNECT <host> <port> <key>`
Pipe,

/// Session is stored and retrieved from the initializeOptions of the initialize request
Expand Down
11 changes: 9 additions & 2 deletions src/subcommand/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 4050a42

Please sign in to comment.