diff options
author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-22 22:12:43 +0530 |
---|---|---|
committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-22 22:21:26 +0530 |
commit | 0621ba8f349a28d0f746f4c8349658025e5f64f5 (patch) | |
tree | bfe825e2987fdc3df35a12a380e1e0730757297e /zellij-client | |
parent | 1162d40ea00aec38907c7079e53c62a02c2c5eda (diff) |
Allow user to specify session name
Diffstat (limited to 'zellij-client')
-rw-r--r-- | zellij-client/Cargo.toml | 1 | ||||
-rw-r--r-- | zellij-client/src/lib.rs | 35 |
2 files changed, 23 insertions, 13 deletions
diff --git a/zellij-client/Cargo.toml b/zellij-client/Cargo.toml index 76a25c1c4..f9d0db086 100644 --- a/zellij-client/Cargo.toml +++ b/zellij-client/Cargo.toml @@ -9,7 +9,6 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -names = "0.11.0" termbg = "0.2.3" zellij-utils = { path = "../zellij-utils/", version = "0.12.0" } diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 45b60d44a..f3b0f11d3 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -76,11 +76,17 @@ fn spawn_server(socket_path: &Path) -> io::Result<()> { } } +#[derive(Debug, Clone)] +pub enum ClientInfo { + Attach(String, bool), + New(String), +} + pub fn start_client( mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: Config, - attach_to: Option<(String, bool)>, + info: ClientInfo, ) { let clear_client_terminal_attributes = "\u{1b}[?1l\u{1b}=\u{1b}[r\u{1b}12l\u{1b}[?1000l\u{1b}[?1002l\u{1b}[?1003l\u{1b}[?1005l\u{1b}[?1006l\u{1b}[?12l"; let take_snapshot = "\u{1b}[?1049h"; @@ -106,20 +112,25 @@ pub fn start_client( }; #[cfg(not(any(feature = "test", test)))] - let first_msg = if let Some((name, force)) = attach_to { - SESSION_NAME.set(name).unwrap(); - std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap()); + let first_msg = match info { + ClientInfo::Attach(name, force) => { + SESSION_NAME.set(name).unwrap(); + std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap()); - ClientToServerMsg::AttachClient(client_attributes, force) - } else { - SESSION_NAME - .set(names::Generator::default().next().unwrap()) - .unwrap(); - std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap()); + ClientToServerMsg::AttachClient(client_attributes, force) + } + ClientInfo::New(name) => { + SESSION_NAME.set(name).unwrap(); + std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap()); - spawn_server(&*ZELLIJ_IPC_PIPE).unwrap(); + spawn_server(&*ZELLIJ_IPC_PIPE).unwrap(); - ClientToServerMsg::NewClient(client_attributes, Box::new(opts), Box::new(config_options)) + ClientToServerMsg::NewClient( + client_attributes, + Box::new(opts), + Box::new(config_options), + ) + } }; #[cfg(any(feature = "test", test))] let first_msg = { |