diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-04-14 01:41:40 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-04 20:48:15 +0530 |
| commit | fedb588330713b815bdd2380c00f8c0762f4e859 (patch) | |
| tree | 26dc04734b27582c25c91c6573b825e5e1733abc /src | |
| parent | fix terminal window resize tests by restricting lifetime of locks (diff) | |
| download | sl0ppij-fedb588330713b815bdd2380c00f8c0762f4e859.tar.gz sl0ppij-fedb588330713b815bdd2380c00f8c0762f4e859.tar.xz sl0ppij-fedb588330713b815bdd2380c00f8c0762f4e859.zip | |
Fix after rebase
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli.rs | 4 | ||||
| -rw-r--r-- | src/client/mod.rs | 36 | ||||
| -rw-r--r-- | src/client/panes/terminal_pane.rs | 1 | ||||
| -rw-r--r-- | src/client/tab.rs | 2 | ||||
| -rw-r--r-- | src/common/errors.rs | 2 | ||||
| -rw-r--r-- | src/common/input/handler.rs | 81 | ||||
| -rw-r--r-- | src/common/mod.rs | 13 | ||||
| -rw-r--r-- | src/common/os_input_output.rs | 8 | ||||
| -rw-r--r-- | src/common/pty_bus.rs | 112 | ||||
| -rw-r--r-- | src/common/screen.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 5 | ||||
| -rw-r--r-- | src/server/mod.rs | 85 | ||||
| -rw-r--r-- | src/tests/fakes.rs | 19 |
13 files changed, 150 insertions, 220 deletions
@@ -2,7 +2,7 @@ use super::common::utils::consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV use std::path::PathBuf; use structopt::StructOpt; -#[derive(StructOpt, Debug, Default, Clone)] +#[derive(StructOpt, Default, Debug, Clone)] #[structopt(name = "zellij")] pub struct CliArgs { /// Send "split (direction h == horizontal / v == vertical)" to active zellij session @@ -44,7 +44,7 @@ pub struct CliArgs { pub debug: bool, } -#[derive(Debug, StructOpt)] +#[derive(Debug, StructOpt, Clone)] pub enum ConfigCli { /// Change the behaviour of zellij #[structopt(name = "option")] diff --git a/src/client/mod.rs b/src/client/mod.rs index b6a0231a..6ba6df73 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -9,12 +9,14 @@ use std::io::Write; use std::sync::mpsc; use std::thread; +use crate::cli::CliArgs; use crate::common::{ command_is_executing::CommandIsExecuting, errors::{ClientContext, ContextType}, + input::config::Config, input::handler::input_loop, os_input_output::ClientOsApi, - SenderType, SenderWithContext, SyncChannelWithContext, OPENCALLS, + SenderType, SenderWithContext, SyncChannelWithContext, }; use crate::server::ServerInstruction; @@ -29,7 +31,7 @@ pub enum ClientInstruction { Exit, } -pub fn start_client(mut os_input: Box<dyn ClientOsApi>) { +pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs) { let take_snapshot = "\u{1b}[?1049h"; os_input.unset_raw_mode(0); let _ = os_input @@ -37,17 +39,23 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>) { .write(take_snapshot.as_bytes()) .unwrap(); + let config = Config::from_cli_config(opts.config) + .map_err(|e| { + eprintln!("There was an error in the config file:\n{}", e); + std::process::exit(1); + }) + .unwrap(); + let mut command_is_executing = CommandIsExecuting::new(); let full_screen_ws = os_input.get_terminal_size_using_fd(0); os_input.set_raw_mode(0); - let err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); let (send_client_instructions, receive_client_instructions): SyncChannelWithContext< ClientInstruction, > = mpsc::sync_channel(500); - let mut send_client_instructions = - SenderWithContext::new(err_ctx, SenderType::SyncSender(send_client_instructions)); + let send_client_instructions = + SenderWithContext::new(SenderType::SyncSender(send_client_instructions)); os_input.connect_to_server(full_screen_ws); @@ -66,7 +74,14 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>) { let send_client_instructions = send_client_instructions.clone(); let command_is_executing = command_is_executing.clone(); let os_input = os_input.clone(); - move || input_loop(os_input, command_is_executing, send_client_instructions) + move || { + input_loop( + os_input, + config, + command_is_executing, + send_client_instructions, + ) + } }); let _signal_thread = thread::Builder::new() @@ -92,8 +107,7 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>) { let os_input = os_input.clone(); move || { loop { - let (instruction, err_ctx) = os_input.client_recv(); - send_client_instructions.update(err_ctx); + let (instruction, _err_ctx) = os_input.client_recv(); if let ClientInstruction::Exit = instruction { break; } @@ -122,7 +136,11 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>) { 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 error = format!("{}\n{}", goto_start_of_last_line, backtrace); + 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()) diff --git a/src/client/panes/terminal_pane.rs b/src/client/panes/terminal_pane.rs index 9fcddc82..f58c3a27 100644 --- a/src/client/panes/terminal_pane.rs +++ b/src/client/panes/terminal_pane.rs @@ -1,7 +1,6 @@ use crate::tab::Pane; use ::nix::pty::Winsize; use ::std::os::unix::io::RawFd; -use ::vte::Perform; use serde::{Deserialize, Serialize}; use std::fmt::Debug; use std::time::Instant; diff --git a/src/client/tab.rs b/src/client/tab.rs index 3817a327..42e19388 100644 --- a/src/client/tab.rs +++ b/src/client/tab.rs @@ -7,7 +7,7 @@ use crate::common::{input::handler::parse_keys, SenderWithContext}; use crate::layout::Layout; use crate::os_input_output::ServerOsApi; use crate::panes::{PaneId, PositionAndSize, TerminalPane}; -use crate::pty_bus::{PtyInstruction, VteEvent}; +use crate::pty_bus::{PtyInstruction, VteBytes}; use crate::server::ServerInstruction; use crate::utils::shared::adjust_to_size; use crate::wasm_vm::PluginInstruction; diff --git a/src/common/errors.rs b/src/common/errors.rs index 10b2165a..5685f885 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -1,7 +1,7 @@ //! Error context system based on a thread-local representation of the call stack, itself based on //! the instructions that are sent between threads. -use super::{ServerInstruction, OPENCALLS}; +use super::{ServerInstruction, ASYNCOPENCALLS, OPENCALLS}; use crate::client::ClientInstruction; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 947a8d02..2fba8537 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -1,12 +1,14 @@ //! Main input logic. use super::actions::Action; -use super::keybinds::get_default_keybinds; +use super::keybinds::Keybinds; use crate::client::ClientInstruction; +use crate::common::input::config::Config; use crate::common::{SenderWithContext, OPENCALLS}; use crate::errors::ContextType; use crate::os_input_output::ClientOsApi; use crate::pty_bus::PtyInstruction; +use crate::screen::ScreenInstruction; use crate::server::ServerInstruction; use crate::CommandIsExecuting; @@ -19,8 +21,10 @@ struct InputHandler { /// The current input mode mode: InputMode, os_input: Box<dyn ClientOsApi>, + config: Config, command_is_executing: CommandIsExecuting, send_client_instructions: SenderWithContext<ClientInstruction>, + should_exit: bool, } impl InputHandler { @@ -28,6 +32,7 @@ impl InputHandler { fn new( os_input: Box<dyn ClientOsApi>, command_is_executing: CommandIsExecuting, + config: Config, send_client_instructions: SenderWithContext<ClientInstruction>, ) -> Self { InputHandler { @@ -36,6 +41,7 @@ impl InputHandler { config, command_is_executing, send_client_instructions, + should_exit: false, } } @@ -44,34 +50,26 @@ impl InputHandler { fn handle_input(&mut self) { let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); err_ctx.add_call(ContextType::StdinHandler); - self.send_client_instructions.update(err_ctx); - self.os_input.update_senders(err_ctx); - if let Ok(keybinds) = get_default_keybinds() { - 'input_loop: loop { - //@@@ I think this should actually just iterate over stdin directly - let stdin_buffer = self.os_input.read_from_stdin(); - for key_result in stdin_buffer.events_and_raw() { - match key_result { - Ok((event, raw_bytes)) => match event { - termion::event::Event::Key(key) => { - let key = cast_termion_key(key); - // FIXME this explicit break is needed because the current test - // framework relies on it to not create dead threads that loop - // and eat up CPUs. Do not remove until the test framework has - // been revised. Sorry about this (@categorille) - let mut should_break = false; - for action in key_to_actions(&key, raw_bytes, &self.mode, &keybinds) - { - should_break |= self.dispatch_action(action); - } - if should_break { - break 'input_loop; - } - } - termion::event::Event::Mouse(_) - | termion::event::Event::Unsupported(_) => { - // Mouse and unsupported events aren't implemented yet, - // use a NoOp untill then. + let keybinds = self.config.keybinds.clone(); + let alt_left_bracket = vec![27, 91]; + loop { + if self.should_exit { + break; + } + let stdin_buffer = self.os_input.read_from_stdin(); + for key_result in stdin_buffer.events_and_raw() { + match key_result { + Ok((event, raw_bytes)) => match event { + termion::event::Event::Key(key) => { + let key = cast_termion_key(key); + self.handle_key(&key, raw_bytes, &keybinds); + } + termion::event::Event::Unsupported(unsupported_key) => { + // we have to do this because of a bug in termion + // this should be a key event and not an unsupported event + if unsupported_key == alt_left_bracket { + let key = Key::Alt('['); + self.handle_key(&key, raw_bytes, &keybinds); } } termion::event::Event::Mouse(_) => { @@ -139,8 +137,19 @@ impl InputHandler { }; self.os_input.send_to_server(screen_instr); } - Action::SwitchFocus(_) => { - self.os_input.send_to_server(ServerInstruction::MoveFocus); + Action::SwitchFocus => { + self.os_input + .send_to_server(ServerInstruction::ToScreen(ScreenInstruction::SwitchFocus)); + } + Action::FocusNextPane => { + self.os_input.send_to_server(ServerInstruction::ToScreen( + ScreenInstruction::FocusNextPane, + )); + } + Action::FocusPreviousPane => { + self.os_input.send_to_server(ServerInstruction::ToScreen( + ScreenInstruction::FocusPreviousPane, + )); } Action::MoveFocus(direction) => { let screen_instr = match direction { @@ -299,11 +308,17 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { /// its [`InputHandler::handle_input()`] loop. pub fn input_loop( os_input: Box<dyn ClientOsApi>, + config: Config, command_is_executing: CommandIsExecuting, send_client_instructions: SenderWithContext<ClientInstruction>, ) { - let _handler = - InputHandler::new(os_input, command_is_executing, send_client_instructions).handle_input(); + let _handler = InputHandler::new( + os_input, + command_is_executing, + config, + send_client_instructions, + ) + .handle_input(); } pub fn parse_keys(input_bytes: &[u8]) -> Vec<Key> { diff --git a/src/common/mod.rs b/src/common/mod.rs index d9b5e6cf..6061f1a6 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -11,7 +11,8 @@ pub mod wasm_vm; use crate::panes::PaneId; use crate::server::ServerInstruction; -use errors::ErrorContext; +use async_std::task_local; +use errors::{get_current_ctx, ErrorContext}; use std::cell::RefCell; use std::sync::mpsc; @@ -43,8 +44,8 @@ pub struct SenderWithContext<T: Clone> { } impl<T: Clone> SenderWithContext<T> { - pub fn new(err_ctx: ErrorContext, sender: SenderType<T>) -> Self { - Self { err_ctx, sender } + pub fn new(sender: SenderType<T>) -> Self { + Self { sender } } /// Sends an event, along with the current [`ErrorContext`], on this @@ -66,3 +67,9 @@ thread_local!( /// stack in the form of an [`ErrorContext`]. pub static OPENCALLS: RefCell<ErrorContext> = RefCell::default() ); + +task_local! { + /// A key to some task local storage that holds a representation of the task's call + /// stack in the form of an [`ErrorContext`]. + static ASYNCOPENCALLS: RefCell<ErrorContext> = RefCell::default() +} diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index 66957a4a..3d7b8918 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -256,7 +256,13 @@ impl ServerOsApi for ServerOsInputOutput { Box::new((*self).clone()) } fn kill(&mut self, pid: RawFd) -> Result<(), nix::Error> { - kill(Pid::from_raw(pid), Some(Signal::SIGINT)).unwrap(); + // TODO: + // Ideally, we should be using SIGINT rather than SIGKILL here, but there are cases in which + // the terminal we're trying to kill hangs on SIGINT and so all the app gets stuck + // that's why we're sending SIGKILL here + // A better solution would be to send SIGINT here and not wait for it, and then have + // a background thread do the waitpid stuff and send SIGKILL if the process is stuck + kill(Pid::from_raw(pid), Some(Signal::SIGKILL)).unwrap(); waitpid(Pid::from_raw(pid), None).unwrap(); Ok(()) } diff --git a/src/common/pty_bus.rs b/src/common/pty_bus.rs index b9bb422b..b9f61d09 100644 --- a/src/common/pty_bus.rs +++ b/src/common/pty_bus.rs @@ -6,16 +6,15 @@ use ::std::os::unix::io::RawFd; use ::std::pin::*; use ::std::sync::mpsc::Receiver; use ::std::time::{Duration, Instant}; -use ::vte; use serde::{Deserialize, Serialize}; use std::path::PathBuf; -use super::{SenderWithContext, OPENCALLS}; +use super::SenderWithContext; use crate::layout::Layout; use crate::os_input_output::ServerOsApi; use crate::utils::logging::debug_to_file; use crate::{ - errors::{ContextType, ErrorContext}, + errors::{get_current_ctx, ContextType, ErrorContext}, panes::PaneId, screen::ScreenInstruction, wasm_vm::PluginInstruction, @@ -67,99 +66,7 @@ impl Stream for ReadFromPid { } } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum VteEvent { - // TODO: try not to allocate Vecs - Print(char), - Execute(u8), // byte - Hook(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char - Put(u8), // byte - Unhook, - OscDispatch(Vec<Vec<u8>>, bool), // params, bell_terminated - CsiDispatch(Vec<i64>, Vec<u8>, bool, char), // params, intermediates, ignore, char - EscDispatch(Vec<u8>, bool, u8), // intermediates, ignore, byte -} - -struct VteEventSender { - id: RawFd, - send_screen_instructions: SenderWithContext<ScreenInstruction>, -} - -impl VteEventSender { - pub fn new(id: RawFd, send_screen_instructions: SenderWithContext<ScreenInstruction>) -> Self { - VteEventSender { - id, - send_screen_instructions, - } - } -} - -impl vte::Perform for VteEventSender { - fn print(&mut self, c: char) { - self.send_screen_instructions - .send(ScreenInstruction::Pty(self.id, VteEvent::Print(c))) - .unwrap(); - } - fn execute(&mut self, byte: u8) { - self.send_screen_instructions - .send(ScreenInstruction::Pty(self.id, VteEvent::Execute(byte))) - .unwrap(); - } - - fn hook(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) { - let params = params.iter().copied().collect(); - let intermediates = intermediates.iter().copied().collect(); - self.send_screen_instructions - .send(ScreenInstruction::Pty( - self.id, - VteEvent::Hook(params, intermediates, ignore, c), - )) - .unwrap(); - } - - fn put(&mut self, byte: u8) { - self.send_screen_instructions - .send(ScreenInstruction::Pty(self.id, VteEvent::Put(byte))) - .unwrap(); - } - - fn unhook(&mut self) { - self.send_screen_instructions - .send(ScreenInstruction::Pty(self.id, VteEvent::Unhook)) - .unwrap(); - } - - fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) { - let params = params.iter().map(|p| p.to_vec()).collect(); - self.send_screen_instructions - .send(ScreenInstruction::Pty( - self.id, - VteEvent::OscDispatch(params, bell_terminated), - )) - .unwrap(); - } - - fn csi_dispatch(&mut self, params: &[i64], intermediates: &[u8], ignore: bool, c: char) { - let params = params.iter().copied().collect(); - let intermediates = intermediates.iter().copied().collect(); - self.send_screen_instructions - .send(ScreenInstruction::Pty( - self.id, - VteEvent::CsiDispatch(params, intermediates, ignore, c), - )) - .unwrap(); - } - - fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) { - let intermediates = intermediates.iter().copied().collect(); - self.send_screen_instructions - .send(ScreenInstruction::Pty( - self.id, - VteEvent::EscDispatch(intermediates, ignore, byte), - )) - .unwrap(); - } -} +pub type VteBytes = Vec<u8>; /// Instructions related to PTYs (pseudoterminals). #[derive(Clone, Debug, Serialize, Deserialize)] @@ -185,18 +92,15 @@ pub struct PtyBus { fn stream_terminal_bytes( pid: RawFd, + send_screen_instructions: SenderWithContext<ScreenInstruction>, os_input: Box<dyn ServerOsApi>, - mut send_screen_instructions: SenderWithContext<ScreenInstruction>, debug: bool, ) -> JoinHandle<()> { - let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); + let mut err_ctx = get_current_ctx(); task::spawn({ async move { err_ctx.add_call(ContextType::AsyncTask); - send_screen_instructions.update(err_ctx); - let mut vte_parser = vte::Parser::new(); - let mut vte_event_sender = VteEventSender::new(pid, send_screen_instructions.clone()); - let mut terminal_bytes = ReadFromPid::new(&pid, os_input.clone()); + let mut terminal_bytes = ReadFromPid::new(&pid, os_input); let mut last_byte_receive_time: Option<Instant> = None; let mut pending_render = false; @@ -282,8 +186,8 @@ impl PtyBus { self.os_input.spawn_terminal(file_to_open); let task_handle = stream_terminal_bytes( pid_primary, - self.os_input.clone(), self.send_screen_instructions.clone(), + self.os_input.clone(), self.debug_to_file, ); self.task_handles.insert(pid_primary, task_handle); @@ -308,8 +212,8 @@ impl PtyBus { for id in new_pane_pids { let task_handle = stream_terminal_bytes( id, - self.os_input.clone(), self.send_screen_instructions.clone(), + self.os_input.clone(), self.debug_to_file, ); self.task_handles.insert(id, task_handle); diff --git a/src/common/screen.rs b/src/common/screen.rs index 92e1075c..8c83f59e 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -10,7 +10,7 @@ use std::sync::mpsc::Receiver; use crate::common::SenderWithContext; use crate::os_input_output::ServerOsApi; use crate::panes::PositionAndSize; -use crate::pty_bus::{PtyInstruction, VteEvent}; +use crate::pty_bus::{PtyInstruction, VteBytes}; use crate::server::ServerInstruction; use crate::tab::Tab; use crate::{errors::ErrorContext, wasm_vm::PluginInstruction}; diff --git a/src/main.rs b/src/main.rs index d89ff577..b9a4575e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,6 @@ use structopt::StructOpt; use crate::cli::CliArgs; use crate::command_is_executing::CommandIsExecuting; use crate::os_input_output::{get_client_os_input, get_server_os_input, ClientOsApi, ServerOsApi}; -use crate::pty_bus::VteEvent; use crate::utils::{ consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, logging::*, @@ -89,7 +88,7 @@ pub fn start( opts: CliArgs, server_os_input: Box<dyn ServerOsApi>, ) { - let ipc_thread = start_server(server_os_input, opts); - start_client(client_os_input); + let ipc_thread = start_server(server_os_input, opts.clone()); + start_client(client_os_input, opts); drop(ipc_thread.join()); } diff --git a/src/server/mod.rs b/src/server/mod.rs index 2495c13d..d8640836 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -16,14 +16,13 @@ use zellij_tile::data::{Event, EventType, ModeInfo}; use crate::cli::CliArgs; use crate::client::ClientInstruction; -use crate::common::pty_bus::VteEvent; use crate::common::{ - errors::{ContextType, ErrorContext, PluginContext, PtyContext, ScreenContext, ServerContext}, + errors::{ContextType, PluginContext, PtyContext, ScreenContext, ServerContext}, os_input_output::ServerOsApi, - pty_bus::{PtyBus, PtyInstruction}, + pty_bus::{PtyBus, PtyInstruction, VteBytes}, screen::{Screen, ScreenInstruction}, wasm_vm::{wasi_stdout, wasi_write_string, zellij_imports, PluginEnv, PluginInstruction}, - ChannelWithContext, SenderType, SenderWithContext, OPENCALLS, + ChannelWithContext, SenderType, SenderWithContext, }; use crate::layout::Layout; use crate::panes::PaneId; @@ -102,9 +101,6 @@ impl ServerInstruction { pub fn resize_up() -> Self { Self::ToScreen(ScreenInstruction::ResizeUp) } - pub fn move_focus() -> Self { - Self::ToScreen(ScreenInstruction::MoveFocus) - } pub fn move_focus_left() -> Self { Self::ToScreen(ScreenInstruction::MoveFocusLeft) } @@ -171,8 +167,8 @@ impl ServerInstruction { pub fn change_mode(mode_info: ModeInfo) -> Self { Self::ToScreen(ScreenInstruction::ChangeMode(mode_info)) } - pub fn pty(fd: RawFd, event: VteEvent) -> Self { - Self::ToScreen(ScreenInstruction::Pty(fd, event)) + pub fn pty(fd: RawFd, bytes: VteBytes) -> Self { + Self::ToScreen(ScreenInstruction::PtyBytes(fd, bytes)) } pub fn terminal_resize(new_size: PositionAndSize) -> Self { Self::ToScreen(ScreenInstruction::TerminalResize(new_size)) @@ -188,14 +184,6 @@ struct ClientMetaData { wasm_thread: Option<thread::JoinHandle<()>>, } -impl ClientMetaData { - fn update(&mut self, err_ctx: ErrorContext) { - self.send_plugin_instructions.update(err_ctx); - self.send_screen_instructions.update(err_ctx); - self.send_pty_instructions.update(err_ctx); - } -} - impl Drop for ClientMetaData { fn drop(&mut self) { let _ = self.send_pty_instructions.send(PtyInstruction::Exit); @@ -211,18 +199,15 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread let (send_server_instructions, receive_server_instructions): ChannelWithContext< ServerInstruction, > = channel(); - let send_server_instructions = SenderWithContext::new( - ErrorContext::new(), - SenderType::Sender(send_server_instructions), - ); + let send_server_instructions = + SenderWithContext::new(SenderType::Sender(send_server_instructions)); let router_thread = thread::Builder::new() .name("server_router".to_string()) .spawn({ let os_input = os_input.clone(); - let mut send_server_instructions = send_server_instructions.clone(); + let send_server_instructions = send_server_instructions.clone(); move || loop { - let (instruction, err_ctx) = os_input.server_recv(); - send_server_instructions.update(err_ctx); + let (instruction, _err_ctx) = os_input.server_recv(); match instruction { ServerInstruction::Exit => break, _ => { @@ -243,9 +228,6 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread let (instruction, mut err_ctx) = receive_server_instructions.recv().unwrap(); err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction))); os_input.update_senders(err_ctx); - if let Some(ref c) = client { - clients.get_mut(c).unwrap().update(err_ctx); - } match instruction { ServerInstruction::OpenFile(file_name) => { let path = PathBuf::from(file_name); @@ -269,7 +251,7 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread ServerInstruction::MoveFocus => { clients[client.as_ref().unwrap()] .send_screen_instructions - .send(ScreenInstruction::MoveFocus) + .send(ScreenInstruction::FocusNextPane) .unwrap(); } ServerInstruction::NewClient(buffer_path, full_screen_ws) => { @@ -340,22 +322,20 @@ fn init_client( send_server_instructions: SenderWithContext<ServerInstruction>, full_screen_ws: PositionAndSize, ) -> ClientMetaData { - let err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); let (send_screen_instructions, receive_screen_instructions): ChannelWithContext< ScreenInstruction, > = channel(); let send_screen_instructions = - SenderWithContext::new(err_ctx, SenderType::Sender(send_screen_instructions)); + SenderWithContext::new(SenderType::Sender(send_screen_instructions)); let (send_plugin_instructions, receive_plugin_instructions): ChannelWithContext< PluginInstruction, > = channel(); let send_plugin_instructions = - SenderWithContext::new(err_ctx, SenderType::Sender(send_plugin_instructions)); + SenderWithContext::new(SenderType::Sender(send_plugin_instructions)); let (send_pty_instructions, receive_pty_instructions): ChannelWithContext<PtyInstruction> = channel(); - let send_pty_instructions = - SenderWithContext::new(err_ctx, SenderType::Sender(send_pty_instructions)); + let send_pty_instructions = SenderWithContext::new(SenderType::Sender(send_pty_instructions)); // Don't use default layouts in tests, but do everywhere else #[cfg(not(test))] @@ -461,15 +441,24 @@ fn init_client( .recv() .expect("failed to receive event on channel"); err_ctx.add_call(ContextType::Screen(ScreenContext::from(&event))); - screen.send_server_instructions.update(err_ctx); - screen.send_pty_instructions.update(err_ctx); - screen.send_plugin_instructions.update(err_ctx); match event { - ScreenInstruction::Pty(pid, vte_event) => { - screen - .get_active_tab_mut() - .unwrap() - .handle_pty_event(pid, vte_event); + ScreenInstruction::PtyBytes(pid, vte_bytes) => { + let active_tab = screen.get_active_tab_mut().unwrap(); + if active_tab.has_terminal_pid(pid) { + // it's most likely that this event is directed at the active tab + // look there first + active_tab.handle_pty_bytes(pid, vte_bytes); + } else { + // if this event wasn't directed at the active tab, start looking + // in other tabs + let all_tabs = screen.get_tabs_mut(); + for tab in all_tabs.values_mut() { + if tab.has_terminal_pid(pid) { + tab.handle_pty_bytes(pid, vte_bytes); + break; + } + } + } } ScreenInstruction::Render => { screen.render(); @@ -513,9 +502,15 @@ fn init_client( ScreenInstruction::ResizeUp => { screen.get_active_tab_mut().unwrap().resize_up(); } - ScreenInstruction::MoveFocus => { + ScreenInstruction::SwitchFocus => { screen.get_active_tab_mut().unwrap().move_focus(); } + ScreenInstruction::FocusNextPane => { + screen.get_active_tab_mut().unwrap().focus_next_pane(); + } + ScreenInstruction::FocusPreviousPane => { + screen.get_active_tab_mut().unwrap().focus_previous_pane(); + } ScreenInstruction::MoveFocusLeft => { screen.get_active_tab_mut().unwrap().move_focus_left(); } @@ -646,8 +641,8 @@ fn init_client( let wasm_thread = thread::Builder::new() .name("wasm".to_string()) .spawn({ - let mut send_screen_instructions = send_screen_instructions.clone(); - let mut send_pty_instructions = send_pty_instructions.clone(); + let send_screen_instructions = send_screen_instructions.clone(); + let send_pty_instructions = send_pty_instructions.clone(); let store = Store::default(); let mut plugin_id = 0; @@ -657,8 +652,6 @@ fn init_client( .recv() .expect("failed to receive event on channel"); err_ctx.add_call(ContextType::Plugin(PluginContext::from(&event))); - send_screen_instructions.update(err_ctx); - send_pty_instructions.update(err_ctx); match event { PluginInstruction::Load(pid_tx, path) => { let project_dirs = diff --git a/src/tests/fakes.rs b/src/tests/fakes.rs index 79511743..271edde0 100644 --- a/src/tests/fakes.rs +++ b/src/tests/fakes.rs @@ -89,12 +89,10 @@ impl FakeInputOutput { let stdout_writer = FakeStdoutWriter::new(last_snapshot_time.clone()); let (client_sender, client_receiver): ChannelWithContext<ClientInstruction> = mpsc::channel(); - let client_sender = - SenderWithContext::new(ErrorContext::new(), SenderType::Sender(client_sender)); + let client_sender = SenderWithContext::new(SenderType::Sender(client_sender)); let (server_sender, server_receiver): ChannelWithContext<ServerInstruction> = mpsc::channel(); - let server_sender = - SenderWithContext::new(ErrorContext::new(), SenderType::Sender(server_sender)); + let server_sender = SenderWithContext::new(SenderType::Sender(server_sender)); win_sizes.insert(0, winsize); // 0 is the current terminal FakeInputOutput { @@ -198,10 +196,7 @@ impl ClientOsApi for FakeInputOutput { fn send_to_server(&self, msg: ServerInstruction) { self.server_sender.send(msg).unwrap(); } - fn update_senders(&mut self, new_ctx: ErrorContext) { - self.server_sender.update(new_ctx); - self.client_sender.update(new_ctx); - } + fn update_senders(&mut self, new_ctx: ErrorContext) {} fn connect_to_server(&mut self, full_screen_ws: PositionAndSize) { ClientOsApi::send_to_server( self, @@ -293,11 +288,5 @@ impl ServerOsApi for FakeInputOutput { self.client_sender.send(msg).unwrap(); } fn add_client_sender(&mut self, _buffer_path: String) {} - fn update_senders(&mut self, new_ctx: ErrorContext) { - self.server_sender.update(new_ctx); - self.client_sender.update(new_ctx); - } - fn load_palette(&self) -> Palette { - default_palette() - } + fn update_senders(&mut self, new_ctx: ErrorContext) {} } |
