diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-21 07:23:17 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-21 07:23:17 -0500 |
commit | 0a7e0122fac5e3c4c0d35c52dea572cc099864ad (patch) | |
tree | 223fdaf48e447caa2f223db27cb556c8c60d0c91 /teleterm/src | |
parent | 4b4cad4f9c73e0f4ec6aa8e0242b4377fa995d82 (diff) | |
download | teleterm-0a7e0122fac5e3c4c0d35c52dea572cc099864ad.tar.gz teleterm-0a7e0122fac5e3c4c0d35c52dea572cc099864ad.zip |
move extracting term type out of the client
so that we can use the client outside of a direct terminal context
Diffstat (limited to 'teleterm/src')
-rw-r--r-- | teleterm/src/client.rs | 17 | ||||
-rw-r--r-- | teleterm/src/cmd/stream.rs | 4 | ||||
-rw-r--r-- | 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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> Client<S> { pub fn stream( + term_type: &str, connect: Connector<S>, auth: &crate::protocol::Auth, ) -> Self { Self::new( + term_type, connect, auth, &[crate::protocol::Message::start_streaming()], @@ -108,28 +110,33 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> } pub fn watch( + term_type: &str, connect: Connector<S>, auth: &crate::protocol::Auth, id: &str, ) -> Self { Self::new( + term_type, connect, auth, &[crate::protocol::Message::start_watching(id)], ) } - pub fn list(connect: Connector<S>, auth: &crate::protocol::Auth) -> Self { - Self::new(connect, auth, &[]) + pub fn list( + term_type: &str, + connect: Connector<S>, + auth: &crate::protocol::Auth, + ) -> Self { + Self::new(term_type, connect, auth, &[]) } fn new( + term_type: &str, connect: Connector<S>, 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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> 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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> connect: crate::client::Connector<S>, 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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> struct WatchSession< S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static, > { + term_type: String, make_connector: Box<dyn Fn() -> crate::client::Connector<S> + Send>, auth: crate::protocol::Auth, @@ -208,9 +209,13 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> make_connector: Box<dyn Fn() -> crate::client::Connector<S> + 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<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> ) => { if let Some(id) = sessions.id_for(*c) { let client = crate::client::Client::watch( + &self.term_type, (self.make_connector)(), &self.auth, id, |