diff --git a/.gitignore b/.gitignore index 54137021..433d02d7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .vscode .vim .DS_Store -/assets/man/zellij.1 \ No newline at end of file +/assets/man/zellij.1 +**/target \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c925429..536e1012 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +* Remove unused imports (https://github.com/zellij-org/zellij/pull/504) +* More Infrastructure changes for the upcoming session detach feature: run server and client in separate processes (https://github.com/zellij-org/zellij/pull/499) + +## [0.11.0] - 2021-05-15 + +This version is mostly an installation hotfix. + * Add `check` flag to `setup` subcommand, move `generate-completions` subcommand to `setup` flag (https://github.com/zellij-org/zellij/pull/503) +* Change the asset installation from an opt-in to an opt-out (https://github.com/zellij-org/zellij/pull/512) ## [0.10.0] - 2021-05-14 * Change Switch default config loading order of `HOME` and system (https://github.com/zellij-org/zellij/pull/488) diff --git a/Cargo.lock b/Cargo.lock index 39c1dad2..92b2d0ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -248,6 +248,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "boxfnonce" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5988cb1d626264ac94100be357308f29ff7cbdd3b36bda27f450a4ee3f713426" + [[package]] name = "bumpalo" version = "3.6.1" @@ -467,6 +473,16 @@ dependencies = [ "syn", ] +[[package]] +name = "daemonize" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70c24513e34f53b640819f0ac9f705b673fcf4006d7aab8778bee72ebfc89815" +dependencies = [ + "boxfnonce", + "libc", +] + [[package]] name = "darling" version = "0.12.3" @@ -2254,13 +2270,14 @@ dependencies = [ [[package]] name = "zellij" -version = "0.11.0" +version = "0.12.0" dependencies = [ "ansi_term 0.12.1", "async-std", "backtrace", "bincode", "colors-transform", + "daemonize", "directories-next", "futures", "insta", @@ -2290,7 +2307,7 @@ dependencies = [ [[package]] name = "zellij-tile" -version = "0.11.0" +version = "0.12.0" dependencies = [ "serde", "serde_json", @@ -2300,7 +2317,7 @@ dependencies = [ [[package]] name = "zellij-tile-utils" -version = "0.11.0" +version = "0.12.0" dependencies = [ "ansi_term 0.12.1", ] diff --git a/Cargo.toml b/Cargo.toml index b2faa935..099d17f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij" -version = "0.11.0" +version = "0.12.0" authors = ["Aram Drevekenin "] edition = "2018" description = "A terminal workspace with batteries included" @@ -15,6 +15,7 @@ include = ["src/**/*", "assets/plugins/*", "assets/layouts/*", "assets/config/*" ansi_term = "0.12.1" backtrace = "0.3.55" bincode = "1.3.1" +daemonize = "0.4.1" directories-next = "2.0" futures = "0.3.5" libc = "0.2" @@ -38,7 +39,7 @@ wasmer-wasi = "1.0.0" interprocess = "1.1.1" names = "0.11.0" colors-transform = "0.2.5" -zellij-tile = { path = "zellij-tile/", version = "0.11.0" } +zellij-tile = { path = "zellij-tile/", version = "0.12.0" } [dependencies.async-std] version = "1.3.0" @@ -80,5 +81,4 @@ assets = [ ] [features] -default = [ "enable_automatic_asset_installation", ] -enable_automatic_asset_installation = [] +disable_automatic_asset_installation = [] diff --git a/Makefile.toml b/Makefile.toml index c02ba1cc..75f78b25 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -122,9 +122,22 @@ args = ["install", "cross"] [tasks.publish] clear = true workspace = false -dependencies = ["build-plugins-release", "wasm-opt-plugins", "build-release", "publish-zellij-tile", "publish-zellij-tile-utils"] +dependencies = ["build-plugins-release", "wasm-opt-plugins", "release-commit", "build-release", "publish-zellij-tile", "publish-zellij-tile-utils"] run_task = "publish-zellij" +[tasks.release-commit] +dependencies = ["commit-all", "tag-release"] +command = "git" +args = ["push", "--atomic", "origin", "main", "v${CARGO_MAKE_CRATE_VERSION}"] + +[tasks.commit-all] +command = "git" +args = ["commit", "-aem", "chore(release): v${CARGO_MAKE_CRATE_VERSION}"] + +[tasks.tag-release] +command = "git" +args = ["tag", "v${CARGO_MAKE_CRATE_VERSION}"] + [tasks.publish-zellij-tile] ignore_errors = true cwd = "zellij-tile" diff --git a/assets/plugins/status-bar.wasm b/assets/plugins/status-bar.wasm index 47c2b6f2..8ca71ac6 100644 Binary files a/assets/plugins/status-bar.wasm and b/assets/plugins/status-bar.wasm differ diff --git a/assets/plugins/strider.wasm b/assets/plugins/strider.wasm index 80421c0d..f687db8d 100644 Binary files a/assets/plugins/strider.wasm and b/assets/plugins/strider.wasm differ diff --git a/assets/plugins/tab-bar.wasm b/assets/plugins/tab-bar.wasm index 3487df71..bb981a5b 100644 Binary files a/assets/plugins/tab-bar.wasm and b/assets/plugins/tab-bar.wasm differ diff --git a/src/cli.rs b/src/cli.rs index 206ebe9d..b8a61344 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,11 +13,15 @@ pub struct CliArgs { pub max_panes: Option, /// Change where zellij looks for layouts and plugins - #[structopt(long)] + #[structopt(long, parse(from_os_str))] pub data_dir: Option, - /// Name of a layout yaml file inside the plugin directory - #[structopt(short, long)] + /// Run server listening at the specified socket path + #[structopt(long, parse(from_os_str))] + pub server: Option, + + /// Path to a layout yaml file + #[structopt(short, long, parse(from_os_str))] pub layout: Option, /// Path to a layout yaml file @@ -25,11 +29,11 @@ pub struct CliArgs { pub layout_path: Option, /// Change where zellij looks for the configuration - #[structopt(short, long, env=ZELLIJ_CONFIG_FILE_ENV)] + #[structopt(short, long, env=ZELLIJ_CONFIG_FILE_ENV, parse(from_os_str))] pub config: Option, /// Change where zellij looks for the configuration - #[structopt(long, env=ZELLIJ_CONFIG_DIR_ENV)] + #[structopt(long, env=ZELLIJ_CONFIG_DIR_ENV, parse(from_os_str))] pub config_dir: Option, #[structopt(subcommand)] diff --git a/src/client/mod.rs b/src/client/mod.rs index 6f298615..862c13cc 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -4,30 +4,62 @@ pub mod pane_resizer; pub mod panes; pub mod tab; -use serde::{Deserialize, Serialize}; -use std::io::Write; +use std::env::current_exe; +use std::io::{self, Write}; +use std::path::Path; +use std::process::Command; use std::sync::mpsc; use std::thread; use crate::cli::CliArgs; use crate::common::{ command_is_executing::CommandIsExecuting, - errors::{ClientContext, ContextType}, + errors::ContextType, input::config::Config, input::handler::input_loop, input::options::Options, + ipc::{ClientToServerMsg, ServerToClientMsg}, os_input_output::ClientOsApi, thread_bus::{SenderType, SenderWithContext, SyncChannelWithContext}, + utils::consts::ZELLIJ_IPC_PIPE, }; -use crate::server::ServerInstruction; /// Instructions related to the client-side application and sent from server to client -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Debug, Clone)] pub enum ClientInstruction { Error(String), Render(Option), UnblockInputThread, Exit, + ServerError(String), +} + +impl From for ClientInstruction { + fn from(instruction: ServerToClientMsg) -> Self { + match instruction { + ServerToClientMsg::Exit => ClientInstruction::Exit, + ServerToClientMsg::Render(buffer) => ClientInstruction::Render(buffer), + ServerToClientMsg::UnblockInputThread => ClientInstruction::UnblockInputThread, + ServerToClientMsg::ServerError(backtrace) => ClientInstruction::ServerError(backtrace), + } + } +} + +fn spawn_server(socket_path: &Path) -> io::Result<()> { + let status = Command::new(current_exe()?) + .arg("--server") + .arg(socket_path) + .status()?; + if status.success() { + Ok(()) + } else { + let msg = "Process returned non-zero exit code"; + let err_msg = match status.code() { + Some(c) => format!("{}: {}", msg, c), + None => msg.to_string(), + }; + Err(io::Error::new(io::ErrorKind::Other, err_msg)) + } } pub fn start_client(mut os_input: Box, opts: CliArgs, config: Config) { @@ -45,13 +77,16 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C .unwrap(); std::env::set_var(&"ZELLIJ", "0"); + #[cfg(not(test))] + spawn_server(&*ZELLIJ_IPC_PIPE).unwrap(); + let mut command_is_executing = CommandIsExecuting::new(); let config_options = Options::from_cli(&config.options, opts.option.clone()); let full_screen_ws = os_input.get_terminal_size_using_fd(0); - os_input.connect_to_server(); - os_input.send_to_server(ServerInstruction::NewClient( + os_input.connect_to_server(&*ZELLIJ_IPC_PIPE); + os_input.send_to_server(ClientToServerMsg::NewClient( full_screen_ws, opts, config_options, @@ -97,15 +132,26 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C .name("signal_listener".to_string()) .spawn({ let os_input = os_input.clone(); + let send_client_instructions = send_client_instructions.clone(); move || { - os_input.receive_sigwinch(Box::new({ - let os_api = os_input.clone(); - move || { - os_api.send_to_server(ServerInstruction::TerminalResize( - os_api.get_terminal_size_using_fd(0), - )); - } - })); + os_input.handle_signals( + Box::new({ + let os_api = os_input.clone(); + move || { + os_api.send_to_server(ClientToServerMsg::TerminalResize( + os_api.get_terminal_size_using_fd(0), + )); + } + }), + Box::new({ + let send_client_instructions = send_client_instructions.clone(); + move || { + send_client_instructions + .send(ClientInstruction::Exit) + .unwrap() + } + }), + ); } }) .unwrap(); @@ -114,47 +160,53 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C .name("router".to_string()) .spawn({ let os_input = os_input.clone(); - move || { - loop { - let (instruction, mut err_ctx) = os_input.recv_from_server(); - err_ctx.add_call(ContextType::Client(ClientContext::from(&instruction))); - if let ClientInstruction::Exit = instruction { - break; + let mut should_break = false; + move || loop { + let (instruction, err_ctx) = os_input.recv_from_server(); + err_ctx.update_thread_ctx(); + match instruction { + ServerToClientMsg::Exit | ServerToClientMsg::ServerError(_) => { + should_break = true; } - send_client_instructions.send(instruction).unwrap(); + _ => {} + } + send_client_instructions.send(instruction.into()).unwrap(); + if should_break { + break; } - send_client_instructions - .send(ClientInstruction::Exit) - .unwrap(); } }) .unwrap(); - #[warn(clippy::never_loop)] + let handle_error = |backtrace: String| { + os_input.unset_raw_mode(0); + let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1); + let restore_snapshot = "\u{1b}[?1049l"; + let error = format!( + "{}\n{}{}", + goto_start_of_last_line, restore_snapshot, backtrace + ); + let _ = os_input + .get_stdout_writer() + .write(error.as_bytes()) + .unwrap(); + std::process::exit(1); + }; + loop { let (client_instruction, mut err_ctx) = receive_client_instructions .recv() .expect("failed to receive app instruction on channel"); - err_ctx.add_call(ContextType::Client(ClientContext::from( - &client_instruction, - ))); + err_ctx.add_call(ContextType::Client((&client_instruction).into())); match client_instruction { ClientInstruction::Exit => break, ClientInstruction::Error(backtrace) => { - let _ = os_input.send_to_server(ServerInstruction::ClientExit); - os_input.unset_raw_mode(0); - let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1); - let restore_snapshot = "\u{1b}[?1049l"; - let error = format!( - "{}\n{}{}", - goto_start_of_last_line, restore_snapshot, backtrace - ); - let _ = os_input - .get_stdout_writer() - .write(error.as_bytes()) - .unwrap(); - std::process::exit(1); + let _ = os_input.send_to_server(ClientToServerMsg::ClientExit); + handle_error(backtrace); + } + ClientInstruction::ServerError(backtrace) => { + handle_error(backtrace); } ClientInstruction::Render(output) => { if output.is_none() { @@ -172,7 +224,7 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C } } - let _ = os_input.send_to_server(ServerInstruction::ClientExit); + let _ = os_input.send_to_server(ClientToServerMsg::ClientExit); router_thread.join().unwrap(); // cleanup(); diff --git a/src/common/errors.rs b/src/common/errors.rs index c2caf19d..262dfd6b 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -19,12 +19,29 @@ const MAX_THREAD_CALL_STACK: usize = 6; use super::thread_bus::SenderWithContext; #[cfg(not(test))] use std::panic::PanicInfo; + +pub trait ErrorInstruction { + fn error(err: String) -> Self; +} + +impl ErrorInstruction for ClientInstruction { + fn error(err: String) -> Self { + ClientInstruction::Error(err) + } +} + +impl ErrorInstruction for ServerInstruction { + fn error(err: String) -> Self { + ServerInstruction::Error(err) + } +} + /// Custom panic handler/hook. Prints the [`ErrorContext`]. #[cfg(not(test))] -pub fn handle_panic( - info: &PanicInfo<'_>, - send_app_instructions: &SenderWithContext, -) { +pub fn handle_panic(info: &PanicInfo<'_>, sender: &SenderWithContext) +where + T: ErrorInstruction + Clone, +{ use backtrace::Backtrace; use std::{process, thread}; let backtrace = Backtrace::new(); @@ -70,7 +87,7 @@ pub fn handle_panic( println!("{}", backtrace); process::exit(1); } else { - let _ = send_app_instructions.send(ClientInstruction::Error(backtrace)); + let _ = sender.send(T::error(backtrace)); } } @@ -103,6 +120,11 @@ impl ErrorContext { break; } } + self.update_thread_ctx() + } + + /// Updates the thread local [`ErrorContext`]. + pub fn update_thread_ctx(&self) { ASYNCOPENCALLS .try_with(|ctx| *ctx.borrow_mut() = *self) .unwrap_or_else(|_| OPENCALLS.with(|ctx| *ctx.borrow_mut() = *self)); @@ -333,6 +355,7 @@ pub enum ClientContext { Error, UnblockInputThread, Render, + ServerError, } impl From<&ClientInstruction> for ClientContext { @@ -340,6 +363,7 @@ impl From<&ClientInstruction> for ClientContext { match *client_instruction { ClientInstruction::Exit => ClientContext::Exit, ClientInstruction::Error(_) => ClientContext::Error, + ClientInstruction::ServerError(_) => ClientContext::ServerError, ClientInstruction::Render(_) => ClientContext::Render, ClientInstruction::UnblockInputThread => ClientContext::UnblockInputThread, } @@ -350,22 +374,20 @@ impl From<&ClientInstruction> for ClientContext { #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum ServerContext { NewClient, - Action, Render, - TerminalResize, UnblockInputThread, ClientExit, + Error, } impl From<&ServerInstruction> for ServerContext { fn from(server_instruction: &ServerInstruction) -> Self { match *server_instruction { ServerInstruction::NewClient(..) => ServerContext::NewClient, - ServerInstruction::Action(_) => ServerContext::Action, - ServerInstruction::TerminalResize(_) => ServerContext::TerminalResize, ServerInstruction::Render(_) => ServerContext::Render, ServerInstruction::UnblockInputThread => ServerContext::UnblockInputThread, ServerInstruction::ClientExit => ServerContext::ClientExit, + ServerInstruction::Error(_) => ServerContext::Error, } } } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index b2f4d0a3..4ac2cf83 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -4,10 +4,10 @@ use super::actions::Action; use super::keybinds::Keybinds; use crate::client::ClientInstruction; use crate::common::input::config::Config; +use crate::common::ipc::ClientToServerMsg; use crate::common::thread_bus::{SenderWithContext, OPENCALLS}; use crate::errors::ContextType; use crate::os_input_output::ClientOsApi; -use crate::server::ServerInstruction; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; @@ -139,7 +139,7 @@ impl InputHandler { Action::SwitchToMode(mode) => { self.mode = mode; self.os_input - .send_to_server(ServerInstruction::Action(action)); + .send_to_server(ClientToServerMsg::Action(action)); } Action::CloseFocus | Action::NewPane(_) @@ -151,13 +151,13 @@ impl InputHandler { | Action::MoveFocusOrTab(_) => { self.command_is_executing.blocking_input_thread(); self.os_input - .send_to_server(ServerInstruction::Action(action)); + .send_to_server(ClientToServerMsg::Action(action)); self.command_is_executing .wait_until_input_thread_is_unblocked(); } _ => self .os_input - .send_to_server(ServerInstruction::Action(action)), + .send_to_server(ClientToServerMsg::Action(action)), } should_break diff --git a/src/common/ipc.rs b/src/common/ipc.rs index 190680dc..129727a1 100644 --- a/src/common/ipc.rs +++ b/src/common/ipc.rs @@ -1,10 +1,14 @@ //! IPC stuff for starting to split things into a client and server model. -use crate::common::errors::{get_current_ctx, ErrorContext}; +use crate::cli::CliArgs; +use crate::common::{ + errors::{get_current_ctx, ErrorContext}, + input::{actions::Action, options::Options}, +}; +use crate::panes::PositionAndSize; use interprocess::local_socket::LocalSocketStream; use nix::unistd::dup; use serde::{Deserialize, Serialize}; -use std::collections::HashSet; use std::io::{self, Write}; use std::marker::PhantomData; use std::os::unix::io::{AsRawFd, FromRawFd}; @@ -29,9 +33,9 @@ pub enum ClientType { } // Types of messages sent from the client to the server -#[derive(Serialize, Deserialize)] -pub enum _ClientToServerMsg { - // List which sessions are available +#[derive(Serialize, Deserialize, Debug, Clone)] +pub enum ClientToServerMsg { + /*// List which sessions are available ListSessions, // Create a new session CreateSession, @@ -40,16 +44,24 @@ pub enum _ClientToServerMsg { // Force detach DetachSession(SessionId), // Disconnect from the session we're connected to - DisconnectFromSession, + DisconnectFromSession,*/ + ClientExit, + TerminalResize(PositionAndSize), + NewClient(PositionAndSize, CliArgs, Options), + Action(Action), } // Types of messages sent from the server to the client -// @@@ Implement Serialize and Deserialize for this... -pub enum _ServerToClientMsg { - // Info about a particular session +#[derive(Serialize, Deserialize, Debug, Clone)] +pub enum ServerToClientMsg { + /*// Info about a particular session SessionInfo(Session), // A list of sessions - SessionList(HashSet), + SessionList(HashSet),*/ + Render(Option), + UnblockInputThread, + Exit, + ServerError(String), } /// Sends messages on a stream socket, along with an [`ErrorContext`]. diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index 6f891e0d..adde6fdf 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -1,11 +1,8 @@ -use crate::client::ClientInstruction; -use crate::common::{ - ipc::{IpcReceiverWithContext, IpcSenderWithContext}, - utils::consts::ZELLIJ_IPC_PIPE, +use crate::common::ipc::{ + ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg, }; use crate::errors::ErrorContext; use crate::panes::PositionAndSize; -use crate::server::ServerInstruction; use crate::utils::shared::default_palette; use interprocess::local_socket::LocalSocketStream; use nix::fcntl::{fcntl, FcntlArg, OFlag}; @@ -170,8 +167,8 @@ fn spawn_terminal(file_to_open: Option, orig_termios: termios::Termios) #[derive(Clone)] pub struct ServerOsInputOutput { orig_termios: Arc>, - receive_instructions_from_client: Option>>>, - send_instructions_to_client: Arc>>>, + receive_instructions_from_client: Option>>>, + send_instructions_to_client: Arc>>>, } /// The `ServerOsApi` trait represents an abstract interface to the features of an operating system that @@ -195,9 +192,9 @@ pub trait ServerOsApi: Send + Sync { /// Returns a [`Box`] pointer to this [`ServerOsApi`] struct. fn box_clone(&self) -> Box; /// Receives a message on server-side IPC channel - fn recv_from_client(&self) -> (ServerInstruction, ErrorContext); + fn recv_from_client(&self) -> (ClientToServerMsg, ErrorContext); /// Sends a message to client - fn send_to_client(&self, msg: ClientInstruction); + fn send_to_client(&self, msg: ServerToClientMsg); /// Adds a sender to client fn add_client_sender(&mut self); /// Update the receiver socket for the client @@ -236,7 +233,7 @@ impl ServerOsApi for ServerOsInputOutput { waitpid(Pid::from_raw(pid), None).unwrap(); Ok(()) } - fn recv_from_client(&self) -> (ServerInstruction, ErrorContext) { + fn recv_from_client(&self) -> (ClientToServerMsg, ErrorContext) { self.receive_instructions_from_client .as_ref() .unwrap() @@ -244,7 +241,7 @@ impl ServerOsApi for ServerOsInputOutput { .unwrap() .recv() } - fn send_to_client(&self, msg: ClientInstruction) { + fn send_to_client(&self, msg: ServerToClientMsg) { self.send_instructions_to_client .lock() .unwrap() @@ -291,8 +288,8 @@ pub fn get_server_os_input() -> ServerOsInputOutput { #[derive(Clone)] pub struct ClientOsInputOutput { orig_termios: Arc>, - send_instructions_to_server: Arc>>>, - receive_instructions_from_server: Arc>>>, + send_instructions_to_server: Arc>>>, + receive_instructions_from_server: Arc>>>, } /// The `ClientOsApi` trait represents an abstract interface to the features of an operating system that @@ -305,7 +302,7 @@ pub trait ClientOsApi: Send + Sync { fn set_raw_mode(&mut self, fd: RawFd); /// Set the terminal associated to file descriptor `fd` to /// [cooked mode](https://en.wikipedia.org/wiki/Terminal_mode). - fn unset_raw_mode(&mut self, fd: RawFd); + fn unset_raw_mode(&self, fd: RawFd); /// Returns the writer that allows writing to standard output. fn get_stdout_writer(&self) -> Box; /// Returns the raw contents of standard input. @@ -313,13 +310,13 @@ pub trait ClientOsApi: Send + Sync { /// Returns a [`Box`] pointer to this [`ClientOsApi`] struct. fn box_clone(&self) -> Box; /// Sends a message to the server. - fn send_to_server(&self, msg: ServerInstruction); + fn send_to_server(&self, msg: ClientToServerMsg); /// Receives a message on client-side IPC channel // This should be called from the client-side router thread only. - fn recv_from_server(&self) -> (ClientInstruction, ErrorContext); - fn receive_sigwinch(&self, cb: Box); + fn recv_from_server(&self) -> (ServerToClientMsg, ErrorContext); + fn handle_signals(&self, sigwinch_cb: Box, quit_cb: Box); /// Establish a connection with the server socket. - fn connect_to_server(&self); + fn connect_to_server(&self, path: &Path); } impl ClientOsApi for ClientOsInputOutput { @@ -329,7 +326,7 @@ impl ClientOsApi for ClientOsInputOutput { fn set_raw_mode(&mut self, fd: RawFd) { into_raw_mode(fd); } - fn unset_raw_mode(&mut self, fd: RawFd) { + fn unset_raw_mode(&self, fd: RawFd) { let orig_termios = self.orig_termios.lock().unwrap(); unset_raw_mode(fd, orig_termios.clone()); } @@ -349,7 +346,7 @@ impl ClientOsApi for ClientOsInputOutput { let stdout = ::std::io::stdout(); Box::new(stdout) } - fn send_to_server(&self, msg: ServerInstruction) { + fn send_to_server(&self, msg: ClientToServerMsg) { self.send_instructions_to_server .lock() .unwrap() @@ -357,7 +354,7 @@ impl ClientOsApi for ClientOsInputOutput { .unwrap() .send(msg); } - fn recv_from_server(&self) -> (ClientInstruction, ErrorContext) { + fn recv_from_server(&self) -> (ServerToClientMsg, ErrorContext) { self.receive_instructions_from_server .lock() .unwrap() @@ -365,28 +362,34 @@ impl ClientOsApi for ClientOsInputOutput { .unwrap() .recv() } - fn receive_sigwinch(&self, cb: Box) { - let mut signals = Signals::new(&[SIGWINCH, SIGTERM, SIGINT, SIGQUIT]).unwrap(); + fn handle_signals(&self, sigwinch_cb: Box, quit_cb: Box) { + let mut signals = Signals::new(&[SIGWINCH, SIGTERM, SIGINT, SIGQUIT, SIGHUP]).unwrap(); for signal in signals.forever() { match signal { SIGWINCH => { - cb(); + sigwinch_cb(); } - SIGTERM | SIGINT | SIGQUIT => { + SIGTERM | SIGINT | SIGQUIT | SIGHUP => { + quit_cb(); break; } _ => unreachable!(), } } } - fn connect_to_server(&self) { - let socket = match LocalSocketStream::connect(&**ZELLIJ_IPC_PIPE) { - Ok(sock) => sock, - Err(_) => { - std::thread::sleep(std::time::Duration::from_millis(20)); - LocalSocketStream::connect(&**ZELLIJ_IPC_PIPE).unwrap() + fn connect_to_server(&self, path: &Path) { + let socket; + loop { + match LocalSocketStream::connect(path) { + Ok(sock) => { + socket = sock; + break; + } + Err(_) => { + std::thread::sleep(std::time::Duration::from_millis(50)); + } } - }; + } let sender = IpcSenderWithContext::new(socket); let receiver = sender.get_receiver(); *self.send_instructions_to_server.lock().unwrap() = Some(sender); diff --git a/src/common/pty.rs b/src/common/pty.rs index 3c471d6a..5f5442b5 100644 --- a/src/common/pty.rs +++ b/src/common/pty.rs @@ -8,7 +8,7 @@ use std::pin::*; use std::time::{Duration, Instant}; use crate::client::panes::PaneId; -use crate::common::errors::{get_current_ctx, ContextType, PtyContext}; +use crate::common::errors::{get_current_ctx, ContextType}; use crate::common::screen::ScreenInstruction; use crate::common::thread_bus::{Bus, ThreadSenders}; use crate::layout::Layout; @@ -87,7 +87,7 @@ pub struct Pty { pub fn pty_thread_main(mut pty: Pty, maybe_layout: Option) { loop { let (event, mut err_ctx) = pty.bus.recv().expect("failed to receive event on channel"); - err_ctx.add_call(ContextType::Pty(PtyContext::from(&event))); + err_ctx.add_call(ContextType::Pty((&event).into())); match event { PtyInstruction::SpawnTerminal(file_to_open) => { let pid = pty.spawn_terminal(file_to_open); diff --git a/src/common/screen.rs b/src/common/screen.rs index bc99f953..62fcec19 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -7,7 +7,7 @@ use std::str; use crate::common::input::options::Options; use crate::common::pty::{PtyInstruction, VteBytes}; use crate::common::thread_bus::Bus; -use crate::errors::{ContextType, ScreenContext}; +use crate::errors::ContextType; use crate::layout::Layout; use crate::panes::PaneId; use crate::panes::PositionAndSize; @@ -353,7 +353,7 @@ pub fn screen_thread_main( .bus .recv() .expect("failed to receive event on channel"); - err_ctx.add_call(ContextType::Screen(ScreenContext::from(&event))); + err_ctx.add_call(ContextType::Screen((&event).into())); match event { ScreenInstruction::PtyBytes(pid, vte_bytes) => { let active_tab = screen.get_active_tab_mut().unwrap(); diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs index 479405c3..42843eb8 100644 --- a/src/common/utils/consts.rs +++ b/src/common/utils/consts.rs @@ -49,6 +49,6 @@ lazy_static! { } pub const FEATURES: &[&str] = &[ - #[cfg(feature = "enable_automatic_asset_installation")] - "enable_automatic_asset_installation", + #[cfg(feature = "disable_automatic_asset_installation")] + "disable_automatic_asset_installation", ]; diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index e5567285..51eb4ed8 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -15,7 +15,7 @@ use wasmer::{ use wasmer_wasi::{Pipe, WasiEnv, WasiState}; use zellij_tile::data::{Event, EventType, PluginIds}; -use crate::common::errors::{ContextType, PluginContext}; +use crate::common::errors::ContextType; use crate::common::pty::PtyInstruction; use crate::common::screen::ScreenInstruction; use crate::common::thread_bus::{Bus, ThreadSenders}; @@ -44,7 +44,7 @@ pub fn wasm_thread_main(bus: Bus, store: Store, data_dir: Pat let mut plugin_map = HashMap::new(); loop { let (event, mut err_ctx) = bus.recv().expect("failed to receive event on channel"); - err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event))); + err_ctx.add_call(ContextType::Plugin((&event).into())); match event { PluginInstruction::Load(pid_tx, path) => { let plugin_dir = data_dir.join("plugins/"); diff --git a/src/main.rs b/src/main.rs index c1f0f387..49e42ffb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,8 @@ use structopt::StructOpt; use crate::cli::CliArgs; use crate::command_is_executing::CommandIsExecuting; -use crate::common::input::{config::Config, options::Options}; -use crate::os_input_output::{get_client_os_input, get_server_os_input, ClientOsApi, ServerOsApi}; +use crate::common::input::config::Config; +use crate::os_input_output::{get_client_os_input, get_server_os_input}; use crate::utils::{ consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, logging::*, @@ -36,28 +36,14 @@ pub fn main() { std::process::exit(1); } }; - let config_options = Options::from_cli(&config.options, opts.option.clone()); atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap(); atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap(); - let server_os_input = get_server_os_input(); - let os_input = get_client_os_input(); - start( - Box::new(os_input), - opts, - Box::new(server_os_input), - config, - config_options, - ); + if let Some(path) = opts.server { + let os_input = get_server_os_input(); + start_server(Box::new(os_input), path); + } else { + let os_input = get_client_os_input(); + start_client(Box::new(os_input), opts, config); + } } } -pub fn start( - client_os_input: Box, - opts: CliArgs, - server_os_input: Box, - config: Config, - config_options: Options, -) { - let ipc_thread = start_server(server_os_input, config_options); - start_client(client_os_input, opts, config); - drop(ipc_thread.join()); -} diff --git a/src/server/mod.rs b/src/server/mod.rs index 076d232d..fdaeead1 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,25 +1,22 @@ pub mod route; -use interprocess::local_socket::LocalSocketListener; -use serde::{Deserialize, Serialize}; use std::sync::{Arc, RwLock}; use std::thread; -use std::{path::PathBuf, sync::mpsc::channel}; +use std::{path::PathBuf, sync::mpsc}; use wasmer::Store; use zellij_tile::data::PluginCapabilities; use crate::cli::CliArgs; -use crate::client::ClientInstruction; use crate::common::thread_bus::{Bus, ThreadSenders}; use crate::common::{ - errors::{ContextType, ServerContext}, - input::{actions::Action, options::Options}, - os_input_output::{set_permissions, ServerOsApi}, + errors::ContextType, + input::options::Options, + ipc::{ClientToServerMsg, ServerToClientMsg}, + os_input_output::ServerOsApi, pty::{pty_thread_main, Pty, PtyInstruction}, screen::{screen_thread_main, ScreenInstruction}, setup::{get_default_data_dir, install::populate_data_dir}, - thread_bus::{ChannelWithContext, SenderType, SenderWithContext}, - utils::consts::{ZELLIJ_IPC_PIPE, ZELLIJ_PROJ_DIR}, + thread_bus::{ChannelWithContext, SenderType, SenderWithContext, SyncChannelWithContext}, wasm_vm::{wasm_thread_main, PluginInstruction}, }; use crate::layout::Layout; @@ -28,18 +25,30 @@ use route::route_thread_main; /// Instructions related to server-side application including the /// ones sent by client to server -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Debug, Clone)] pub enum ServerInstruction { - TerminalResize(PositionAndSize), NewClient(PositionAndSize, CliArgs, Options), - Action(Action), Render(Option), UnblockInputThread, ClientExit, + Error(String), +} + +impl From for ServerInstruction { + fn from(instruction: ClientToServerMsg) -> Self { + match instruction { + ClientToServerMsg::ClientExit => ServerInstruction::ClientExit, + ClientToServerMsg::NewClient(pos, opts, options) => { + ServerInstruction::NewClient(pos, opts, options) + } + _ => unreachable!(), + } + } } pub struct SessionMetaData { pub senders: ThreadSenders, + pub capabilities: PluginCapabilities, screen_thread: Option>, pty_thread: Option>, wasm_thread: Option>, @@ -56,14 +65,30 @@ impl Drop for SessionMetaData { } } -pub fn start_server( - os_input: Box, - config_options: Options, -) -> thread::JoinHandle<()> { - let (to_server, server_receiver): ChannelWithContext = channel(); - let to_server = SenderWithContext::new(SenderType::Sender(to_server)); +pub fn start_server(os_input: Box, socket_path: PathBuf) { + #[cfg(not(test))] + daemonize::Daemonize::new() + .working_directory(std::env::var("HOME").unwrap()) + .umask(0o077) + .start() + .expect("could not daemonize the server process"); + + std::env::set_var(&"ZELLIJ", "0"); + + let (to_server, server_receiver): SyncChannelWithContext = + mpsc::sync_channel(50); + let to_server = SenderWithContext::new(SenderType::SyncSender(to_server)); let sessions: Arc>> = Arc::new(RwLock::new(None)); + #[cfg(not(test))] + std::panic::set_hook({ + use crate::errors::handle_panic; + let to_server = to_server.clone(); + Box::new(move |info| { + handle_panic(info, &to_server); + }) + }); + #[cfg(test)] thread::Builder::new() .name("server_router".to_string()) @@ -71,27 +96,25 @@ pub fn start_server( let sessions = sessions.clone(); let os_input = os_input.clone(); let to_server = to_server.clone(); - let capabilities = PluginCapabilities { - arrow_fonts: !config_options.simplified_ui, - }; - move || route_thread_main(sessions, os_input, to_server, capabilities) + move || route_thread_main(sessions, os_input, to_server) }) .unwrap(); #[cfg(not(test))] let _ = thread::Builder::new() .name("server_listener".to_string()) .spawn({ + use crate::common::os_input_output::set_permissions; + use interprocess::local_socket::LocalSocketListener; + let os_input = os_input.clone(); let sessions = sessions.clone(); let to_server = to_server.clone(); - let capabilities = PluginCapabilities { - arrow_fonts: config_options.simplified_ui, - }; + let socket_path = socket_path.clone(); move || { - drop(std::fs::remove_file(&*ZELLIJ_IPC_PIPE)); - let listener = LocalSocketListener::bind(&**ZELLIJ_IPC_PIPE).unwrap(); - set_permissions(&*ZELLIJ_IPC_PIPE).unwrap(); + drop(std::fs::remove_file(&socket_path)); + let listener = LocalSocketListener::bind(&*socket_path).unwrap(); + set_permissions(&socket_path).unwrap(); for stream in listener.incoming() { match stream { Ok(stream) => { @@ -106,14 +129,7 @@ pub fn start_server( let os_input = os_input.clone(); let to_server = to_server.clone(); - move || { - route_thread_main( - sessions, - os_input, - to_server, - capabilities, - ) - } + move || route_thread_main(sessions, os_input, to_server) }) .unwrap(); } @@ -125,48 +141,47 @@ pub fn start_server( } }); - thread::Builder::new() - .name("server_thread".to_string()) - .spawn({ - move || loop { - let (instruction, mut err_ctx) = server_receiver.recv().unwrap(); - err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction))); - match instruction { - ServerInstruction::NewClient(full_screen_ws, opts, config_options) => { - let session_data = init_session( - os_input.clone(), - opts, - config_options, - to_server.clone(), - full_screen_ws, - ); - *sessions.write().unwrap() = Some(session_data); - sessions - .read() - .unwrap() - .as_ref() - .unwrap() - .senders - .send_to_pty(PtyInstruction::NewTab) - .unwrap(); - } - ServerInstruction::UnblockInputThread => { - os_input.send_to_client(ClientInstruction::UnblockInputThread); - } - ServerInstruction::ClientExit => { - *sessions.write().unwrap() = None; - os_input.send_to_client(ClientInstruction::Exit); - drop(std::fs::remove_file(&*ZELLIJ_IPC_PIPE)); - break; - } - ServerInstruction::Render(output) => { - os_input.send_to_client(ClientInstruction::Render(output)) - } - _ => panic!("Received unexpected instruction."), - } + loop { + let (instruction, mut err_ctx) = server_receiver.recv().unwrap(); + err_ctx.add_call(ContextType::IPCServer((&instruction).into())); + match instruction { + ServerInstruction::NewClient(full_screen_ws, opts, config_options) => { + let session_data = init_session( + os_input.clone(), + opts, + config_options, + to_server.clone(), + full_screen_ws, + ); + *sessions.write().unwrap() = Some(session_data); + sessions + .read() + .unwrap() + .as_ref() + .unwrap() + .senders + .send_to_pty(PtyInstruction::NewTab) + .unwrap(); } - }) - .unwrap() + ServerInstruction::UnblockInputThread => { + os_input.send_to_client(ServerToClientMsg::UnblockInputThread); + } + ServerInstruction::ClientExit => { + *sessions.write().unwrap() = None; + os_input.send_to_client(ServerToClientMsg::Exit); + break; + } + ServerInstruction::Render(output) => { + os_input.send_to_client(ServerToClientMsg::Render(output)) + } + ServerInstruction::Error(backtrace) => { + os_input.send_to_client(ServerToClientMsg::ServerError(backtrace)); + break; + } + } + } + #[cfg(not(test))] + drop(std::fs::remove_file(&socket_path)); } fn init_session( @@ -176,20 +191,24 @@ fn init_session( to_server: SenderWithContext, full_screen_ws: PositionAndSize, ) -> SessionMetaData { - let (to_screen, screen_receiver): ChannelWithContext = channel(); + let (to_screen, screen_receiver): ChannelWithContext = mpsc::channel(); let to_screen = SenderWithContext::new(SenderType::Sender(to_screen)); - let (to_plugin, plugin_receiver): ChannelWithContext = channel(); + let (to_plugin, plugin_receiver): ChannelWithContext = mpsc::channel(); let to_plugin = SenderWithContext::new(SenderType::Sender(to_plugin)); - let (to_pty, pty_receiver): ChannelWithContext = channel(); + let (to_pty, pty_receiver): ChannelWithContext = mpsc::channel(); let to_pty = SenderWithContext::new(SenderType::Sender(to_pty)); // Determine and initialize the data directory let data_dir = opts.data_dir.unwrap_or_else(get_default_data_dir); - #[cfg(enable_automatic_assets_installation)] + #[cfg(not(disable_automatic_asset_installation))] populate_data_dir(&data_dir); + let capabilities = PluginCapabilities { + arrow_fonts: config_options.simplified_ui, + }; + // Don't use default layouts in tests, but do everywhere else #[cfg(not(test))] let default_layout = Some(PathBuf::from("default")); @@ -234,7 +253,6 @@ fn init_session( Some(os_input.clone()), ); let max_panes = opts.max_panes; - let config_options = config_options; move || { screen_thread_main(screen_bus, max_panes, full_screen_ws, config_options); @@ -265,6 +283,7 @@ fn init_session( to_plugin: Some(to_plugin), to_server: None, }, + capabilities, screen_thread: Some(screen_thread), pty_thread: Some(pty_thread), wasm_thread: Some(wasm_thread), diff --git a/src/server/route.rs b/src/server/route.rs index bd4b1b60..c435a0e6 100644 --- a/src/server/route.rs +++ b/src/server/route.rs @@ -1,10 +1,10 @@ use std::sync::{Arc, RwLock}; -use zellij_tile::data::{Event, PluginCapabilities}; +use zellij_tile::data::Event; -use crate::common::errors::{ContextType, ServerContext}; use crate::common::input::actions::{Action, Direction}; use crate::common::input::handler::get_mode_info; +use crate::common::ipc::ClientToServerMsg; use crate::common::os_input_output::ServerOsApi; use crate::common::pty::PtyInstruction; use crate::common::screen::ScreenInstruction; @@ -12,12 +12,7 @@ use crate::common::thread_bus::SenderWithContext; use crate::common::wasm_vm::PluginInstruction; use crate::server::{ServerInstruction, SessionMetaData}; -fn route_action( - action: Action, - session: &SessionMetaData, - os_input: &dyn ServerOsApi, - capabilities: PluginCapabilities, -) { +fn route_action(action: Action, session: &SessionMetaData, os_input: &dyn ServerOsApi) { match action { Action::Write(val) => { session @@ -35,7 +30,7 @@ fn route_action( .senders .send_to_plugin(PluginInstruction::Update( None, - Event::ModeUpdate(get_mode_info(mode, palette, capabilities)), + Event::ModeUpdate(get_mode_info(mode, palette, session.capabilities)), )) .unwrap(); session @@ -43,7 +38,7 @@ fn route_action( .send_to_screen(ScreenInstruction::ChangeMode(get_mode_info( mode, palette, - capabilities, + session.capabilities, ))) .unwrap(); session @@ -190,26 +185,20 @@ pub fn route_thread_main( sessions: Arc>>, mut os_input: Box, to_server: SenderWithContext, - capabilities: PluginCapabilities, ) { loop { - let (instruction, mut err_ctx) = os_input.recv_from_client(); - err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction))); + let (instruction, err_ctx) = os_input.recv_from_client(); + err_ctx.update_thread_ctx(); let rlocked_sessions = sessions.read().unwrap(); match instruction { - ServerInstruction::ClientExit => { - to_server.send(instruction).unwrap(); + ClientToServerMsg::ClientExit => { + to_server.send(instruction.into()).unwrap(); break; } - ServerInstruction::Action(action) => { - route_action( - action, - rlocked_sessions.as_ref().unwrap(), - &*os_input, - capabilities, - ); + ClientToServerMsg::Action(action) => { + route_action(action, rlocked_sessions.as_ref().unwrap(), &*os_input); } - ServerInstruction::TerminalResize(new_size) => { + ClientToServerMsg::TerminalResize(new_size) => { rlocked_sessions .as_ref() .unwrap() @@ -217,12 +206,9 @@ pub fn route_thread_main( .send_to_screen(ScreenInstruction::TerminalResize(new_size)) .unwrap(); } - ServerInstruction::NewClient(..) => { + ClientToServerMsg::NewClient(..) => { os_input.add_client_sender(); - to_server.send(instruction).unwrap(); - } - _ => { - to_server.send(instruction).unwrap(); + to_server.send(instruction.into()).unwrap(); } } } diff --git a/src/tests/fakes.rs b/src/tests/fakes.rs index eb0d14e8..98ec694a 100644 --- a/src/tests/fakes.rs +++ b/src/tests/fakes.rs @@ -7,11 +7,10 @@ use std::path::PathBuf; use std::sync::{mpsc, Arc, Condvar, Mutex}; use std::time::{Duration, Instant}; -use crate::client::ClientInstruction; +use crate::common::ipc::{ClientToServerMsg, ServerToClientMsg}; use crate::common::thread_bus::{ChannelWithContext, SenderType, SenderWithContext}; use crate::errors::ErrorContext; use crate::os_input_output::{ClientOsApi, ServerOsApi}; -use crate::server::ServerInstruction; use crate::tests::possible_tty_inputs::{get_possible_tty_inputs, Bytes}; use crate::tests::utils::commands::{QUIT, SLEEP}; use crate::utils::shared::default_palette; @@ -77,10 +76,10 @@ pub struct FakeInputOutput { win_sizes: Arc>>, possible_tty_inputs: HashMap, last_snapshot_time: Arc>, - send_instructions_to_client: SenderWithContext, - receive_instructions_from_server: Arc>>, - send_instructions_to_server: SenderWithContext, - receive_instructions_from_client: Arc>>, + send_instructions_to_client: SenderWithContext, + receive_instructions_from_server: Arc>>, + send_instructions_to_server: SenderWithContext, + receive_instructions_from_client: Arc>>, should_trigger_sigwinch: Arc<(Mutex, Condvar)>, sigwinch_event: Option, } @@ -90,10 +89,10 @@ impl FakeInputOutput { let mut win_sizes = HashMap::new(); let last_snapshot_time = Arc::new(Mutex::new(Instant::now())); let stdout_writer = FakeStdoutWriter::new(last_snapshot_time.clone()); - let (client_sender, client_receiver): ChannelWithContext = + let (client_sender, client_receiver): ChannelWithContext = mpsc::channel(); let send_instructions_to_client = SenderWithContext::new(SenderType::Sender(client_sender)); - let (server_sender, server_receiver): ChannelWithContext = + let (server_sender, server_receiver): ChannelWithContext = mpsc::channel(); let send_instructions_to_server = SenderWithContext::new(SenderType::Sender(server_sender)); win_sizes.insert(0, winsize); // 0 is the current terminal @@ -153,7 +152,7 @@ impl ClientOsApi for FakeInputOutput { .unwrap() .push(IoEvent::IntoRawMode(pid)); } - fn unset_raw_mode(&mut self, pid: RawFd) { + fn unset_raw_mode(&self, pid: RawFd) { self.io_events .lock() .unwrap() @@ -195,17 +194,17 @@ impl ClientOsApi for FakeInputOutput { fn get_stdout_writer(&self) -> Box { Box::new(self.stdout_writer.clone()) } - fn send_to_server(&self, msg: ServerInstruction) { + fn send_to_server(&self, msg: ClientToServerMsg) { self.send_instructions_to_server.send(msg).unwrap(); } - fn recv_from_server(&self) -> (ClientInstruction, ErrorContext) { + fn recv_from_server(&self) -> (ServerToClientMsg, ErrorContext) { self.receive_instructions_from_server .lock() .unwrap() .recv() .unwrap() } - fn receive_sigwinch(&self, cb: Box) { + fn handle_signals(&self, sigwinch_cb: Box, _quit_cb: Box) { if self.sigwinch_event.is_some() { let (lock, cvar) = &*self.should_trigger_sigwinch; { @@ -214,10 +213,10 @@ impl ClientOsApi for FakeInputOutput { should_trigger_sigwinch = cvar.wait(should_trigger_sigwinch).unwrap(); } } - cb(); + sigwinch_cb(); } } - fn connect_to_server(&self) {} + fn connect_to_server(&self, _path: &std::path::Path) {} } impl ServerOsApi for FakeInputOutput { @@ -278,14 +277,14 @@ impl ServerOsApi for FakeInputOutput { self.io_events.lock().unwrap().push(IoEvent::Kill(fd)); Ok(()) } - fn recv_from_client(&self) -> (ServerInstruction, ErrorContext) { + fn recv_from_client(&self) -> (ClientToServerMsg, ErrorContext) { self.receive_instructions_from_client .lock() .unwrap() .recv() .unwrap() } - fn send_to_client(&self, msg: ClientInstruction) { + fn send_to_client(&self, msg: ServerToClientMsg) { self.send_instructions_to_client.send(msg).unwrap(); } fn add_client_sender(&mut self) {} diff --git a/src/tests/integration/basic.rs b/src/tests/integration/basic.rs index 1ebcb922..bb581eb1 100644 --- a/src/tests/integration/basic.rs +++ b/src/tests/integration/basic.rs @@ -1,8 +1,9 @@ use crate::panes::PositionAndSize; use ::insta::assert_snapshot; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::commands::{ BRACKETED_PASTE_END, BRACKETED_PASTE_START, PANE_MODE, QUIT, SCROLL_DOWN_IN_SCROLL_MODE, SCROLL_MODE, SCROLL_PAGE_DOWN_IN_SCROLL_MODE, SCROLL_PAGE_UP_IN_SCROLL_MODE, @@ -10,7 +11,7 @@ use crate::tests::utils::commands::{ SPLIT_RIGHT_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, }; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) @@ -32,7 +33,6 @@ pub fn starts_with_one_terminal() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -61,7 +61,6 @@ pub fn split_terminals_vertically() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -90,7 +89,6 @@ pub fn split_terminals_horizontally() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -126,7 +124,6 @@ pub fn split_largest_terminal() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -155,7 +152,6 @@ pub fn cannot_split_terminals_vertically_when_active_terminal_is_too_small() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -184,7 +180,6 @@ pub fn cannot_split_terminals_horizontally_when_active_terminal_is_too_small() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -213,7 +208,6 @@ pub fn cannot_split_largest_terminal_when_there_is_no_room() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -250,7 +244,6 @@ pub fn scrolling_up_inside_a_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -289,7 +282,6 @@ pub fn scrolling_down_inside_a_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -325,7 +317,6 @@ pub fn scrolling_page_up_inside_a_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -364,7 +355,6 @@ pub fn scrolling_page_down_inside_a_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -404,7 +394,6 @@ pub fn max_panes() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -442,7 +431,6 @@ pub fn toggle_focused_pane_fullscreen() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -483,7 +471,6 @@ pub fn bracketed_paste() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer diff --git a/src/tests/integration/close_pane.rs b/src/tests/integration/close_pane.rs index d151f63d..cfb912ee 100644 --- a/src/tests/integration/close_pane.rs +++ b/src/tests/integration/close_pane.rs @@ -2,10 +2,11 @@ use crate::panes::PositionAndSize; use ::insta::assert_snapshot; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ CLOSE_PANE_IN_PANE_MODE, ESC, MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_DOWN_IN_RESIZE_MODE, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, RESIZE_UP_IN_RESIZE_MODE, @@ -45,7 +46,6 @@ pub fn close_pane_with_another_pane_above_it() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -89,7 +89,6 @@ pub fn close_pane_with_another_pane_below_it() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -130,7 +129,6 @@ pub fn close_pane_with_another_pane_to_the_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -172,7 +170,6 @@ pub fn close_pane_with_another_pane_to_the_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -219,7 +216,6 @@ pub fn close_pane_with_multiple_panes_above_it() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -264,7 +260,6 @@ pub fn close_pane_with_multiple_panes_below_it() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -311,7 +306,6 @@ pub fn close_pane_with_multiple_panes_to_the_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -356,7 +350,6 @@ pub fn close_pane_with_multiple_panes_to_the_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -423,7 +416,6 @@ pub fn close_pane_with_multiple_panes_above_it_away_from_screen_edges() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -486,7 +478,6 @@ pub fn close_pane_with_multiple_panes_below_it_away_from_screen_edges() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -551,7 +542,6 @@ pub fn close_pane_with_multiple_panes_to_the_left_away_from_screen_edges() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -616,7 +606,6 @@ pub fn close_pane_with_multiple_panes_to_the_right_away_from_screen_edges() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -654,7 +643,6 @@ pub fn closing_last_pane_exits_app() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/compatibility.rs b/src/tests/integration/compatibility.rs index b986b1de..06222a3a 100644 --- a/src/tests/integration/compatibility.rs +++ b/src/tests/integration/compatibility.rs @@ -4,10 +4,11 @@ use ::std::collections::HashMap; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; use crate::tests::possible_tty_inputs::Bytes; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::QUIT; /* @@ -48,7 +49,6 @@ pub fn run_bandwhich_from_fish_shell() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -78,7 +78,6 @@ pub fn fish_tab_completion_options() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -113,7 +112,6 @@ pub fn fish_select_tab_completion_options() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -152,7 +150,6 @@ pub fn vim_scroll_region_down() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -188,7 +185,6 @@ pub fn vim_ctrl_d() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -223,7 +219,6 @@ pub fn vim_ctrl_u() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -253,7 +248,6 @@ pub fn htop() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -283,7 +277,6 @@ pub fn htop_scrolling() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -313,7 +306,6 @@ pub fn htop_right_scrolling() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -351,7 +343,6 @@ pub fn vim_overwrite() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -384,7 +375,6 @@ pub fn clear_scroll_region() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -414,7 +404,6 @@ pub fn display_tab_characters_properly() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -444,7 +433,6 @@ pub fn neovim_insert_mode() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -476,7 +464,6 @@ pub fn bash_cursor_linewrap() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -508,7 +495,6 @@ pub fn fish_paste_multiline() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -538,7 +524,6 @@ pub fn git_log() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -570,7 +555,6 @@ pub fn git_diff_scrollup() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -600,7 +584,6 @@ pub fn emacs_longbuf() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -630,7 +613,6 @@ pub fn top_and_quit() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -666,7 +648,6 @@ pub fn exa_plus_omf_theme() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer diff --git a/src/tests/integration/layouts.rs b/src/tests/integration/layouts.rs index f3848461..fa46e9f7 100644 --- a/src/tests/integration/layouts.rs +++ b/src/tests/integration/layouts.rs @@ -1,12 +1,13 @@ use insta::assert_snapshot; use std::path::PathBuf; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::commands::QUIT; use crate::tests::utils::get_output_frame_snapshots; -use crate::{start, CliArgs}; +use crate::CliArgs; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) @@ -33,7 +34,6 @@ pub fn accepts_basic_layout() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer diff --git a/src/tests/integration/move_focus_down.rs b/src/tests/integration/move_focus_down.rs index e182acf9..b1032bd0 100644 --- a/src/tests/integration/move_focus_down.rs +++ b/src/tests/integration/move_focus_down.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_DOWN_IN_PANE_MODE, MOVE_FOCUS_UP_IN_PANE_MODE, PANE_MODE, QUIT, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, @@ -37,7 +38,6 @@ pub fn move_focus_down() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -75,7 +75,6 @@ pub fn move_focus_down_to_the_most_recently_used_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/move_focus_left.rs b/src/tests/integration/move_focus_left.rs index c991d1e8..4842f342 100644 --- a/src/tests/integration/move_focus_left.rs +++ b/src/tests/integration/move_focus_left.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ ENTER, MOVE_FOCUS_LEFT_IN_NORMAL_MODE, MOVE_FOCUS_LEFT_IN_PANE_MODE, MOVE_FOCUS_RIGHT_IN_PANE_MODE, NEW_TAB_IN_TAB_MODE, PANE_MODE, QUIT, SPLIT_DOWN_IN_PANE_MODE, @@ -37,7 +38,6 @@ pub fn move_focus_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -76,7 +76,6 @@ pub fn move_focus_left_to_the_most_recently_used_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -115,7 +114,6 @@ pub fn move_focus_left_changes_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/move_focus_right.rs b/src/tests/integration/move_focus_right.rs index ffc8cacf..6ff6e21a 100644 --- a/src/tests/integration/move_focus_right.rs +++ b/src/tests/integration/move_focus_right.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ ENTER, MOVE_FOCUS_LEFT_IN_PANE_MODE, MOVE_FOCUS_RIGHT_IN_NORMAL_MODE, MOVE_FOCUS_RIGHT_IN_PANE_MODE, NEW_TAB_IN_TAB_MODE, PANE_MODE, QUIT, SPLIT_DOWN_IN_PANE_MODE, @@ -38,7 +39,6 @@ pub fn move_focus_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -76,7 +76,6 @@ pub fn move_focus_right_to_the_most_recently_used_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -115,7 +114,6 @@ pub fn move_focus_right_changes_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/move_focus_up.rs b/src/tests/integration/move_focus_up.rs index 54bfef5e..068ded52 100644 --- a/src/tests/integration/move_focus_up.rs +++ b/src/tests/integration/move_focus_up.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_DOWN_IN_PANE_MODE, MOVE_FOCUS_UP_IN_PANE_MODE, PANE_MODE, QUIT, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, @@ -36,7 +37,6 @@ pub fn move_focus_up() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -75,7 +75,6 @@ pub fn move_focus_up_to_the_most_recently_used_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/resize_down.rs b/src/tests/integration/resize_down.rs index 0e710b4e..cc4b9ec4 100644 --- a/src/tests/integration/resize_down.rs +++ b/src/tests/integration/resize_down.rs @@ -2,10 +2,11 @@ use insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_DOWN_IN_RESIZE_MODE, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, @@ -48,7 +49,6 @@ pub fn resize_down_with_pane_above() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -94,7 +94,6 @@ pub fn resize_down_with_pane_below() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -146,7 +145,6 @@ pub fn resize_down_with_panes_above_and_below() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -197,7 +195,6 @@ pub fn resize_down_with_multiple_panes_above() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -250,7 +247,6 @@ pub fn resize_down_with_panes_above_aligned_left_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -302,7 +298,6 @@ pub fn resize_down_with_panes_below_aligned_left_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -352,7 +347,6 @@ pub fn resize_down_with_panes_above_aligned_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -403,7 +397,6 @@ pub fn resize_down_with_panes_below_aligned_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -457,7 +450,6 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -513,7 +505,6 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -586,7 +577,6 @@ pub fn resize_down_with_panes_above_aligned_left_and_right_with_panes_to_the_lef CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -661,7 +651,6 @@ pub fn resize_down_with_panes_below_aligned_left_and_right_with_to_the_left_and_ CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -704,7 +693,6 @@ pub fn cannot_resize_down_when_pane_below_is_at_minimum_height() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/resize_left.rs b/src/tests/integration/resize_left.rs index 5d498e96..c5ba5427 100644 --- a/src/tests/integration/resize_left.rs +++ b/src/tests/integration/resize_left.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, RESIZE_UP_IN_RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, @@ -44,7 +45,6 @@ pub fn resize_left_with_pane_to_the_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -88,7 +88,6 @@ pub fn resize_left_with_pane_to_the_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -134,7 +133,6 @@ pub fn resize_left_with_panes_to_the_left_and_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -183,7 +181,6 @@ pub fn resize_left_with_multiple_panes_to_the_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -234,7 +231,6 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -282,7 +278,6 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -332,7 +327,6 @@ pub fn resize_left_with_panes_to_the_left_aligned_bottom_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -381,7 +375,6 @@ pub fn resize_left_with_panes_to_the_right_aligned_bottom_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -435,7 +428,6 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_current_pa CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -491,7 +483,6 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_current_p CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -564,7 +555,6 @@ pub fn resize_left_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abov CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -640,7 +630,6 @@ pub fn resize_left_with_panes_to_the_right_aligned_top_and_bottom_with_panes_abo CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -683,7 +672,6 @@ pub fn cannot_resize_left_when_pane_to_the_left_is_at_minimum_width() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/resize_right.rs b/src/tests/integration/resize_right.rs index 8be15315..43409ec1 100644 --- a/src/tests/integration/resize_right.rs +++ b/src/tests/integration/resize_right.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_MODE, RESIZE_RIGHT_IN_RESIZE_MODE, RESIZE_UP_IN_RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, @@ -44,7 +45,6 @@ pub fn resize_right_with_pane_to_the_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -88,7 +88,6 @@ pub fn resize_right_with_pane_to_the_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -134,7 +133,6 @@ pub fn resize_right_with_panes_to_the_left_and_right() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -183,7 +181,6 @@ pub fn resize_right_with_multiple_panes_to_the_left() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -234,7 +231,6 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -282,7 +278,6 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -332,7 +327,6 @@ pub fn resize_right_with_panes_to_the_left_aligned_bottom_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -381,7 +375,6 @@ pub fn resize_right_with_panes_to_the_right_aligned_bottom_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -435,7 +428,6 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_current_p CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -491,7 +483,6 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_current_ CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -564,7 +555,6 @@ pub fn resize_right_with_panes_to_the_left_aligned_top_and_bottom_with_panes_abo CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -639,7 +629,6 @@ pub fn resize_right_with_panes_to_the_right_aligned_top_and_bottom_with_panes_ab CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -682,7 +671,6 @@ pub fn cannot_resize_right_when_pane_to_the_left_is_at_minimum_width() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/resize_up.rs b/src/tests/integration/resize_up.rs index ba810a9f..200fcc6e 100644 --- a/src/tests/integration/resize_up.rs +++ b/src/tests/integration/resize_up.rs @@ -2,10 +2,11 @@ use ::insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, RESIZE_LEFT_IN_RESIZE_MODE, RESIZE_MODE, RESIZE_UP_IN_RESIZE_MODE, SLEEP, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, @@ -46,7 +47,6 @@ pub fn resize_up_with_pane_above() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -92,7 +92,6 @@ pub fn resize_up_with_pane_below() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -143,7 +142,6 @@ pub fn resize_up_with_panes_above_and_below() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -193,7 +191,6 @@ pub fn resize_up_with_multiple_panes_above() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -244,7 +241,6 @@ pub fn resize_up_with_panes_above_aligned_left_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -296,7 +292,6 @@ pub fn resize_up_with_panes_below_aligned_left_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -346,7 +341,6 @@ pub fn resize_up_with_panes_above_aligned_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -397,7 +391,6 @@ pub fn resize_up_with_panes_below_aligned_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -451,7 +444,6 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -507,7 +499,6 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_current_pane() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -580,7 +571,6 @@ pub fn resize_up_with_panes_above_aligned_left_and_right_with_panes_to_the_left_ CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -655,7 +645,6 @@ pub fn resize_up_with_panes_below_aligned_left_and_right_with_to_the_left_and_ri CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -698,7 +687,6 @@ pub fn cannot_resize_up_when_pane_above_is_at_minimum_height() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/tabs.rs b/src/tests/integration/tabs.rs index 1d8a2c9d..0995d16c 100644 --- a/src/tests/integration/tabs.rs +++ b/src/tests/integration/tabs.rs @@ -1,11 +1,12 @@ use insta::assert_snapshot; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; +use crate::CliArgs; use crate::{panes::PositionAndSize, tests::utils::commands::CLOSE_PANE_IN_PANE_MODE}; -use crate::{start, CliArgs}; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ CLOSE_TAB_IN_TAB_MODE, NEW_TAB_IN_TAB_MODE, PANE_MODE, QUIT, SPLIT_DOWN_IN_PANE_MODE, SWITCH_NEXT_TAB_IN_TAB_MODE, SWITCH_PREV_TAB_IN_TAB_MODE, TAB_MODE, @@ -38,7 +39,6 @@ pub fn open_new_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -75,7 +75,6 @@ pub fn switch_to_prev_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -112,7 +111,6 @@ pub fn switch_to_next_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -149,7 +147,6 @@ pub fn close_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -187,7 +184,6 @@ pub fn close_last_pane_in_a_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -227,7 +223,6 @@ pub fn close_the_middle_tab() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -272,7 +267,6 @@ pub fn close_the_tab_that_has_a_pane_in_fullscreen() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -309,7 +303,6 @@ pub fn closing_last_tab_exits_the_app() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/integration/terminal_window_resize.rs b/src/tests/integration/terminal_window_resize.rs index 7c06609a..2e56300f 100644 --- a/src/tests/integration/terminal_window_resize.rs +++ b/src/tests/integration/terminal_window_resize.rs @@ -1,11 +1,12 @@ use crate::panes::PositionAndSize; use ::insta::assert_snapshot; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::commands::QUIT; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; fn get_fake_os_input(fake_win_size: &PositionAndSize) -> FakeInputOutput { FakeInputOutput::new(fake_win_size.clone()) @@ -35,7 +36,6 @@ pub fn window_width_decrease_with_one_pane() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -72,7 +72,6 @@ pub fn window_width_increase_with_one_pane() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -109,7 +108,6 @@ pub fn window_height_increase_with_one_pane() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer @@ -146,7 +144,6 @@ pub fn window_width_and_height_decrease_with_one_pane() { opts, Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output .stdout_writer diff --git a/src/tests/integration/toggle_fullscreen.rs b/src/tests/integration/toggle_fullscreen.rs index 8a63bbea..00d98170 100644 --- a/src/tests/integration/toggle_fullscreen.rs +++ b/src/tests/integration/toggle_fullscreen.rs @@ -2,10 +2,11 @@ use insta::assert_snapshot; use crate::panes::PositionAndSize; use crate::tests::fakes::FakeInputOutput; +use crate::tests::start; use crate::tests::utils::{get_next_to_last_snapshot, get_output_frame_snapshots}; -use crate::{start, CliArgs}; +use crate::CliArgs; -use crate::common::input::{config::Config, options::Options}; +use crate::common::input::config::Config; use crate::tests::utils::commands::{ MOVE_FOCUS_IN_PANE_MODE, PANE_MODE, QUIT, SPLIT_DOWN_IN_PANE_MODE, SPLIT_RIGHT_IN_PANE_MODE, TOGGLE_ACTIVE_TERMINAL_FULLSCREEN_IN_PANE_MODE, @@ -37,7 +38,6 @@ pub fn adding_new_terminal_in_fullscreen() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output @@ -73,7 +73,6 @@ pub fn move_focus_is_disabled_in_fullscreen() { CliArgs::default(), Box::new(fake_input_output.clone()), Config::default(), - Options::default(), ); let output_frames = fake_input_output diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 6e07c96d..7aaad79f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -3,3 +3,26 @@ pub mod integration; pub mod possible_tty_inputs; pub mod tty_inputs; pub mod utils; + +use crate::cli::CliArgs; +use crate::client::start_client; +use crate::common::input::config::Config; +use crate::os_input_output::{ClientOsApi, ServerOsApi}; +use crate::server::start_server; +use std::path::PathBuf; + +pub fn start( + client_os_input: Box, + opts: CliArgs, + server_os_input: Box, + config: Config, +) { + let server_thread = std::thread::Builder::new() + .name("server_thread".into()) + .spawn(move || { + start_server(server_os_input, PathBuf::from("")); + }) + .unwrap(); + start_client(client_os_input, opts, config); + let _ = server_thread.join(); +} diff --git a/zellij-tile-utils/Cargo.toml b/zellij-tile-utils/Cargo.toml index cee6df30..a69f53be 100644 --- a/zellij-tile-utils/Cargo.toml +++ b/zellij-tile-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij-tile-utils" -version = "0.11.0" +version = "0.12.0" authors = ["denis "] edition = "2018" description = "A utility library for Zellij plugins" diff --git a/zellij-tile/Cargo.toml b/zellij-tile/Cargo.toml index 60d30021..4728ec1e 100644 --- a/zellij-tile/Cargo.toml +++ b/zellij-tile/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zellij-tile" -version = "0.11.0" +version = "0.12.0" authors = ["Brooks J Rady "] edition = "2018" description = "A small client-side library for writing Zellij plugins"