From 0a7e0122fac5e3c4c0d35c52dea572cc099864ad Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 21 Nov 2019 07:23:17 -0500 Subject: move extracting term type out of the client so that we can use the client outside of a direct terminal context --- teleterm/src/client.rs | 17 ++++++++++++----- teleterm/src/cmd/stream.rs | 4 +++- teleterm/src/cmd/watch.rs | 8 +++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/teleterm/src/client.rs b/teleterm/src/client.rs index daabf7d..248433b 100644 --- a/teleterm/src/client.rs +++ b/teleterm/src/client.rs @@ -97,10 +97,12 @@ impl Client { pub fn stream( + term_type: &str, connect: Connector, auth: &crate::protocol::Auth, ) -> Self { Self::new( + term_type, connect, auth, &[crate::protocol::Message::start_streaming()], @@ -108,28 +110,33 @@ impl } pub fn watch( + term_type: &str, connect: Connector, auth: &crate::protocol::Auth, id: &str, ) -> Self { Self::new( + term_type, connect, auth, &[crate::protocol::Message::start_watching(id)], ) } - pub fn list(connect: Connector, auth: &crate::protocol::Auth) -> Self { - Self::new(connect, auth, &[]) + pub fn list( + term_type: &str, + connect: Connector, + auth: &crate::protocol::Auth, + ) -> Self { + Self::new(term_type, connect, auth, &[]) } fn new( + term_type: &str, connect: Connector, auth: &crate::protocol::Auth, on_login: &[crate::protocol::Message], ) -> Self { - let term_type = - std::env::var("TERM").unwrap_or_else(|_| "".to_string()); let heartbeat_timer = tokio::timer::Interval::new_interval(HEARTBEAT_DURATION); @@ -137,7 +144,7 @@ impl connect, auth: auth.clone(), - term_type, + term_type: term_type.to_string(), heartbeat_timer, reconnect_timer: None, diff --git a/teleterm/src/cmd/stream.rs b/teleterm/src/cmd/stream.rs index 0ca8dac..643b32a 100644 --- a/teleterm/src/cmd/stream.rs +++ b/teleterm/src/cmd/stream.rs @@ -141,7 +141,9 @@ impl connect: crate::client::Connector, auth: &crate::protocol::Auth, ) -> Self { - let client = crate::client::Client::stream(connect, auth); + let term_type = + std::env::var("TERM").unwrap_or_else(|_| "".to_string()); + let client = crate::client::Client::stream(&term_type, connect, auth); // TODO: tokio::io::stdin is broken (it's blocking) // see https://github.com/tokio-rs/tokio/issues/589 diff --git a/teleterm/src/cmd/watch.rs b/teleterm/src/cmd/watch.rs index fa5fdd1..f156112 100644 --- a/teleterm/src/cmd/watch.rs +++ b/teleterm/src/cmd/watch.rs @@ -187,6 +187,7 @@ impl struct WatchSession< S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static, > { + term_type: String, make_connector: Box crate::client::Connector + Send>, auth: crate::protocol::Auth, @@ -208,9 +209,13 @@ impl make_connector: Box crate::client::Connector + Send>, auth: &crate::protocol::Auth, ) -> Self { - let list_client = crate::client::Client::list(make_connector(), auth); + let term_type = + std::env::var("TERM").unwrap_or_else(|_| "".to_string()); + let list_client = + crate::client::Client::list(&term_type, make_connector(), auth); Self { + term_type, make_connector, auth: auth.clone(), @@ -323,6 +328,7 @@ impl ) => { if let Some(id) = sessions.id_for(*c) { let client = crate::client::Client::watch( + &self.term_type, (self.make_connector)(), &self.auth, id, -- cgit v1.2.3-54-g00ecf