diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-04-01 22:40:40 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-05-04 20:48:15 +0530 |
| commit | 223ee743e1b503f7d81c06343c23b2c786b2dbee (patch) | |
| tree | 0b7a6a996c93c80328e327197816a28447f7b65a /src/common | |
| parent | wip: helper functions for ServerInstruction (diff) | |
| download | sl0ppij-223ee743e1b503f7d81c06343c23b2c786b2dbee.tar.gz sl0ppij-223ee743e1b503f7d81c06343c23b2c786b2dbee.tar.xz sl0ppij-223ee743e1b503f7d81c06343c23b2c786b2dbee.zip | |
Move screen and plugins to client side.
Remove AppInstruction enum
spawn pty thread, screen thread and plugin thread on demand
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/errors.rs | 83 | ||||
| -rw-r--r-- | src/common/input/handler.rs | 152 | ||||
| -rw-r--r-- | src/common/os_input_output.rs | 22 | ||||
| -rw-r--r-- | src/common/pty_bus.rs | 85 | ||||
| -rw-r--r-- | src/common/screen.rs | 36 | ||||
| -rw-r--r-- | src/common/wasm_vm.rs | 9 |
6 files changed, 159 insertions, 228 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs index 3ee36752..720341a4 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -1,8 +1,8 @@ //! 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::{os_input_output::ServerOsApiInstruction, ServerInstruction, OPENCALLS}; -use crate::client::AppInstruction; +use super::{ServerInstruction, OPENCALLS}; +use crate::client::ClientInstruction; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; use serde::{Deserialize, Serialize}; @@ -21,7 +21,7 @@ use std::panic::PanicInfo; #[cfg(not(test))] pub fn handle_panic( info: &PanicInfo<'_>, - send_app_instructions: &SenderWithContext<AppInstruction>, + send_app_instructions: &SenderWithContext<ClientInstruction>, ) { use backtrace::Backtrace; use std::{process, thread}; @@ -68,9 +68,7 @@ pub fn handle_panic( println!("{}", backtrace); process::exit(1); } else { - send_app_instructions - .send(AppInstruction::Error(backtrace)) - .unwrap(); + let _ = send_app_instructions.send(ClientInstruction::Error(backtrace)); } } @@ -132,19 +130,17 @@ impl Display for ErrorContext { /// /// Complex variants store a variant of a related enum, whose variants can be built from /// the corresponding Zellij MSPC instruction enum variants ([`ScreenInstruction`], -/// [`PtyInstruction`], [`AppInstruction`], etc). +/// [`PtyInstruction`], [`ClientInstruction`], etc). #[derive(Copy, Clone, PartialEq, Serialize, Deserialize)] pub enum ContextType { /// A screen-related call. Screen(ScreenContext), /// A PTY-related call. Pty(PtyContext), - /// An OS-related call. - Os(OsContext), /// A plugin-related call. Plugin(PluginContext), /// An app-related call. - App(AppContext), + Client(ClientContext), /// A server-related call. IPCServer(ServerContext), StdinHandler, @@ -162,9 +158,8 @@ impl Display for ContextType { match *self { ContextType::Screen(c) => write!(f, "{}screen_thread: {}{:?}", purple, green, c), ContextType::Pty(c) => write!(f, "{}pty_thread: {}{:?}", purple, green, c), - ContextType::Os(c) => write!(f, "{}os_thread: {}{:?}", purple, green, c), ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), - ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), + ContextType::Client(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), ContextType::IPCServer(c) => write!(f, "{}ipc_server: {}{:?}", purple, green, c), ContextType::StdinHandler => { write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) @@ -257,7 +252,7 @@ impl From<&ScreenInstruction> for ScreenContext { ScreenInstruction::SetInvisibleBorders(..) => ScreenContext::SetInvisibleBorders, ScreenInstruction::SetMaxHeight(..) => ScreenContext::SetMaxHeight, ScreenInstruction::ClosePane(_) => ScreenContext::ClosePane, - ScreenInstruction::ApplyLayout(_) => ScreenContext::ApplyLayout, + ScreenInstruction::ApplyLayout(..) => ScreenContext::ApplyLayout, ScreenInstruction::NewTab(_) => ScreenContext::NewTab, ScreenInstruction::SwitchTabNext => ScreenContext::SwitchTabNext, ScreenInstruction::SwitchTabPrev => ScreenContext::SwitchTabPrev, @@ -297,28 +292,6 @@ impl From<&PtyInstruction> for PtyContext { } } -/// Stack call representations corresponding to the different types of [`ServerOsApiInstruction`]s. -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum OsContext { - SetTerminalSizeUsingFd, - WriteToTtyStdin, - TcDrain, - Exit, -} - -impl From<&ServerOsApiInstruction> for OsContext { - fn from(os_instruction: &ServerOsApiInstruction) -> Self { - match *os_instruction { - ServerOsApiInstruction::SetTerminalSizeUsingFd(_, _, _) => { - OsContext::SetTerminalSizeUsingFd - } - ServerOsApiInstruction::WriteToTtyStdin(_, _) => OsContext::WriteToTtyStdin, - ServerOsApiInstruction::TcDrain(_) => OsContext::TcDrain, - ServerOsApiInstruction::Exit => OsContext::Exit, - } - } -} - // FIXME: This whole pattern *needs* a macro eventually, it's soul-crushing to write use crate::wasm_vm::PluginInstruction; @@ -345,22 +318,26 @@ impl From<&PluginInstruction> for PluginContext { } } -/// Stack call representations corresponding to the different types of [`AppInstruction`]s. +/// Stack call representations corresponding to the different types of [`ClientInstruction`]s. #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] -pub enum AppContext { +pub enum ClientContext { Exit, Error, DoneClosingPane, - ToPty, + DoneOpeningNewPane, + DoneUpdatingTabs, + Render, } -impl From<&AppInstruction> for AppContext { - fn from(app_instruction: &AppInstruction) -> Self { - match *app_instruction { - AppInstruction::Exit => AppContext::Exit, - AppInstruction::Error(_) => AppContext::Error, - AppInstruction::DoneClosingPane => AppContext::DoneClosingPane, - AppInstruction::ToPty(_) => AppContext::ToPty, +impl From<&ClientInstruction> for ClientContext { + fn from(client_instruction: &ClientInstruction) -> Self { + match *client_instruction { + ClientInstruction::Exit => ClientContext::Exit, + ClientInstruction::Error(_) => ClientContext::Error, + ClientInstruction::Render(_) => ClientContext::Render, + ClientInstruction::DoneClosingPane => ClientContext::DoneClosingPane, + ClientInstruction::DoneOpeningNewPane => ClientContext::DoneOpeningNewPane, + ClientInstruction::DoneUpdatingTabs => ClientContext::DoneUpdatingTabs, } } } @@ -375,10 +352,13 @@ pub enum ServerContext { NewClient, ToPty, ToScreen, - OsApi, + Render, + PluginUpdate, DoneClosingPane, - ClosePluginPane, + DoneOpeningNewPane, + DoneUpdatingTabs, ClientExit, + ClientShouldExit, Exit, } @@ -389,13 +369,16 @@ impl From<&ServerInstruction> for ServerContext { ServerInstruction::SplitHorizontally => ServerContext::SplitHorizontally, ServerInstruction::SplitVertically => ServerContext::SplitVertically, ServerInstruction::MoveFocus => ServerContext::MoveFocus, - ServerInstruction::NewClient(_) => ServerContext::NewClient, + ServerInstruction::NewClient(..) => ServerContext::NewClient, ServerInstruction::ToPty(_) => ServerContext::ToPty, ServerInstruction::ToScreen(_) => ServerContext::ToScreen, - ServerInstruction::OsApi(_) => ServerContext::OsApi, + ServerInstruction::PluginUpdate(..) => ServerContext::PluginUpdate, + ServerInstruction::Render(_) => ServerContext::Render, ServerInstruction::DoneClosingPane => ServerContext::DoneClosingPane, - ServerInstruction::ClosePluginPane(_) => ServerContext::ClosePluginPane, + ServerInstruction::DoneOpeningNewPane => ServerContext::DoneOpeningNewPane, + ServerInstruction::DoneUpdatingTabs => ServerContext::DoneUpdatingTabs, ServerInstruction::ClientExit => ServerContext::ClientExit, + ServerInstruction::ClientShouldExit => ServerContext::ClientShouldExit, ServerInstruction::Exit => ServerContext::Exit, } } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index d4ae3080..4015938a 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -2,14 +2,12 @@ use super::actions::Action; use super::keybinds::get_default_keybinds; -use crate::client::AppInstruction; +use crate::client::ClientInstruction; 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::wasm_vm::PluginInstruction; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; @@ -22,10 +20,7 @@ struct InputHandler { mode: InputMode, os_input: Box<dyn ClientOsApi>, command_is_executing: CommandIsExecuting, - send_screen_instructions: SenderWithContext<ScreenInstruction>, - send_plugin_instructions: SenderWithContext<PluginInstruction>, - send_app_instructions: SenderWithContext<AppInstruction>, - should_exit: bool, + send_client_instructions: SenderWithContext<ClientInstruction>, } impl InputHandler { @@ -33,20 +28,14 @@ impl InputHandler { fn new( os_input: Box<dyn ClientOsApi>, command_is_executing: CommandIsExecuting, - config: Config, - send_screen_instructions: SenderWithContext<ScreenInstruction>, - send_plugin_instructions: SenderWithContext<PluginInstruction>, - send_app_instructions: SenderWithContext<AppInstruction>, + send_client_instructions: SenderWithContext<ClientInstruction>, ) -> Self { InputHandler { mode: InputMode::Normal, os_input, config, command_is_executing, - send_screen_instructions, - send_plugin_instructions, - send_app_instructions, - should_exit: false, + send_client_instructions, } } @@ -55,8 +44,7 @@ impl InputHandler { fn handle_input(&mut self) { let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); err_ctx.add_call(ContextType::StdinHandler); - self.send_app_instructions.update(err_ctx); - self.send_screen_instructions.update(err_ctx); + self.send_client_instructions.update(err_ctx); self.os_input.update_senders(err_ctx); if let Ok(keybinds) = get_default_keybinds() { 'input_loop: loop { @@ -122,12 +110,10 @@ impl InputHandler { match action { Action::Write(val) => { - self.send_screen_instructions - .send(ScreenInstruction::ClearScroll) - .unwrap(); - self.send_screen_instructions - .send(ScreenInstruction::WriteCharacter(val)) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::clear_scroll()); + self.os_input + .send_to_server(ServerInstruction::write_character(val)); } Action::Quit => { self.exit(); @@ -135,64 +121,42 @@ impl InputHandler { } Action::SwitchToMode(mode) => { self.mode = mode; - self.send_plugin_instructions - .send(PluginInstruction::Update( + self.os_input + .send_to_server(ServerInstruction::PluginUpdate( None, - Event::ModeUpdate(get_mode_info(mode, self.os_input.load_palette())), - )) - .unwrap(); - self.send_screen_instructions - .send(ScreenInstruction::ChangeMode(get_mode_info( - mode, - self.os_input.load_palette(), - ))) - .unwrap(); - self.send_screen_instructions - .send(ScreenInstruction::Render) - .unwrap(); + Event::ModeUpdate(get_mode_info(mode)), + )); + self.os_input + .send_to_server(ServerInstruction::change_input_mode(mode)); + self.os_input.send_to_server(ServerInstruction::render()); } Action::Resize(direction) => { let screen_instr = match direction { - super::actions::Direction::Left => ScreenInstruction::ResizeLeft, - super::actions::Direction::Right => ScreenInstruction::ResizeRight, - super::actions::Direction::Up => ScreenInstruction::ResizeUp, - super::actions::Direction::Down => ScreenInstruction::ResizeDown, + super::actions::Direction::Left => ServerInstruction::resize_left(), + super::actions::Direction::Right => ServerInstruction::resize_right(), + super::actions::Direction::Up => ServerInstruction::resize_up(), + super::actions::Direction::Down => ServerInstruction::resize_down(), }; - self.send_screen_instructions.send(screen_instr).unwrap(); - } - Action::SwitchFocus => { - self.send_screen_instructions - .send(ScreenInstruction::SwitchFocus) - .unwrap(); - } - Action::FocusNextPane => { - self.send_screen_instructions - .send(ScreenInstruction::FocusNextPane) - .unwrap(); + self.os_input.send_to_server(screen_instr); } - Action::FocusPreviousPane => { - self.send_screen_instructions - .send(ScreenInstruction::FocusPreviousPane) - .unwrap(); + Action::SwitchFocus(_) => { + self.os_input.send_to_server(ServerInstruction::MoveFocus); } Action::MoveFocus(direction) => { let screen_instr = match direction { - super::actions::Direction::Left => ScreenInstruction::MoveFocusLeft, - super::actions::Direction::Right => ScreenInstruction::MoveFocusRight, - super::actions::Direction::Up => ScreenInstruction::MoveFocusUp, - super::actions::Direction::Down => ScreenInstruction::MoveFocusDown, + super::actions::Direction::Left => ServerInstruction::move_focus_left(), + super::actions::Direction::Right => ServerInstruction::move_focus_right(), + super::actions::Direction::Up => ServerInstruction::move_focus_up(), + super::actions::Direction::Down => ServerInstruction::move_focus_down(), }; - self.send_screen_instructions.send(screen_instr).unwrap(); + self.os_input.send_to_server(screen_instr); } Action::ScrollUp => { - self.send_screen_instructions - .send(ScreenInstruction::ScrollUp) - .unwrap(); + self.os_input.send_to_server(ServerInstruction::scroll_up()); } Action::ScrollDown => { - self.send_screen_instructions - .send(ScreenInstruction::ScrollDown) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::scroll_down()); } Action::PageScrollUp => { self.send_screen_instructions @@ -205,9 +169,8 @@ impl InputHandler { .unwrap(); } Action::ToggleFocusFullscreen => { - self.send_screen_instructions - .send(ScreenInstruction::ToggleActiveTerminalFullscreen) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::toggle_active_terminal_fullscreen()); } Action::NewPane(direction) => { let pty_instr = match direction { @@ -233,9 +196,8 @@ impl InputHandler { } Action::CloseFocus => { self.command_is_executing.closing_pane(); - self.send_screen_instructions - .send(ScreenInstruction::CloseFocusedPane) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::close_focused_pane()); self.command_is_executing.wait_until_pane_is_closed(); } Action::NewTab => { @@ -246,16 +208,14 @@ impl InputHandler { } Action::GoToNextTab => { self.command_is_executing.updating_tabs(); - self.send_screen_instructions - .send(ScreenInstruction::SwitchTabNext) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::switch_tab_next()); self.command_is_executing.wait_until_tabs_are_updated(); } Action::GoToPreviousTab => { self.command_is_executing.updating_tabs(); - self.send_screen_instructions - .send(ScreenInstruction::SwitchTabPrev) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::switch_tab_prev()); self.command_is_executing.wait_until_tabs_are_updated(); } Action::ToggleActiveSyncPanes => { @@ -265,22 +225,19 @@ impl InputHandler { } Action::CloseTab => { self.command_is_executing.updating_tabs(); - self.send_screen_instructions - .send(ScreenInstruction::CloseTab) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::screen_close_tab()); self.command_is_executing.wait_until_tabs_are_updated(); } Action::GoToTab(i) => { self.command_is_executing.updating_tabs(); - self.send_screen_instructions - .send(ScreenInstruction::GoToTab(i)) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::go_to_tab(i)); self.command_is_executing.wait_until_tabs_are_updated(); } Action::TabNameInput(c) => { - self.send_screen_instructions - .send(ScreenInstruction::UpdateTabName(c)) - .unwrap(); + self.os_input + .send_to_server(ServerInstruction::update_tab_name(c)); } Action::NoOp => {} } @@ -291,8 +248,8 @@ impl InputHandler { /// Routine to be called when the input handler exits (at the moment this is the /// same as quitting Zellij). fn exit(&mut self) { - self.send_app_instructions - .send(AppInstruction::Exit) + self.send_client_instructions + .send(ClientInstruction::Exit) .unwrap(); } } @@ -343,19 +300,10 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { pub fn input_loop( os_input: Box<dyn ClientOsApi>, command_is_executing: CommandIsExecuting, - send_screen_instructions: SenderWithContext<ScreenInstruction>, - send_plugin_instructions: SenderWithContext<PluginInstruction>, - send_app_instructions: SenderWithContext<AppInstruction>, + send_client_instructions: SenderWithContext<ClientInstruction>, ) { - let _handler = InputHandler::new( - os_input, - command_is_executing, - config, - send_screen_instructions, - send_plugin_instructions, - send_app_instructions, - ) - .handle_input(); + let _handler = + InputHandler::new(os_input, command_is_executing, send_client_instructions).handle_input(); } pub fn parse_keys(input_bytes: &[u8]) -> Vec<Key> { diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index 7cc43e27..53300424 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -6,7 +6,7 @@ use nix::sys::termios; use nix::sys::wait::waitpid; use nix::unistd; use nix::unistd::{ForkResult, Pid}; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use std::env; use std::io; use std::io::prelude::*; @@ -22,7 +22,7 @@ use crate::panes::PositionAndSize; use crate::server::ServerInstruction; use crate::utils::consts::ZELLIJ_IPC_PIPE; -const IPC_BUFFER_SIZE: u32 = 8192; +const IPC_BUFFER_SIZE: u32 = 8388608; fn into_raw_mode(pid: RawFd) { let mut tio = termios::tcgetattr(pid).expect("could not get terminal attribute"); @@ -300,15 +300,6 @@ pub fn get_server_os_input() -> ServerOsInputOutput { } } -/// OS Instructions sent to the Server by clients -#[derive(Serialize, Deserialize, Debug, Clone)] -pub enum ServerOsApiInstruction { - SetTerminalSizeUsingFd(RawFd, u16, u16), - WriteToTtyStdin(RawFd, Vec<u8>), - TcDrain(RawFd), - Exit, -} - #[derive(Clone)] pub struct ClientOsInputOutput { orig_termios: Arc<Mutex<termios::Termios>>, @@ -342,7 +333,7 @@ pub trait ClientOsApi: Send + Sync { // This should be called from the client-side router thread only. fn client_recv(&self) -> (ClientInstruction, ErrorContext); /// Setup the client IpcChannel and notify server of new client - fn connect_to_server(&mut self); + fn connect_to_server(&mut self, full_screen_ws: PositionAndSize); } impl ClientOsApi for ClientOsInputOutput { @@ -378,13 +369,16 @@ impl ClientOsApi for ClientOsInputOutput { fn update_senders(&mut self, new_ctx: ErrorContext) { self.server_sender.update(new_ctx); } - fn connect_to_server(&mut self) { + fn connect_to_server(&mut self, full_screen_ws: PositionAndSize) { let (client_buffer_path, client_buffer) = SharedRingBuffer::create_temp(IPC_BUFFER_SIZE).unwrap(); self.client_receiver = Some(Arc::new(Mutex::new(IpcReceiver::new( client_buffer.clone(), )))); - self.send_to_server(ServerInstruction::NewClient(client_buffer_path)); + self.send_to_server(ServerInstruction::NewClient( + client_buffer_path, + full_screen_ws, + )); } fn client_recv(&self) -> (ClientInstruction, ErrorContext) { self.client_receiver diff --git a/src/common/pty_bus.rs b/src/common/pty_bus.rs index bc49e9bd..b9bb422b 100644 --- a/src/common/pty_bus.rs +++ b/src/common/pty_bus.rs @@ -18,7 +18,7 @@ use crate::{ errors::{ContextType, ErrorContext}, panes::PaneId, screen::ScreenInstruction, - server::ServerInstruction, + wasm_vm::PluginInstruction, }; pub struct ReadFromPid { @@ -82,35 +82,35 @@ pub enum VteEvent { struct VteEventSender { id: RawFd, - send_server_instructions: SenderWithContext<ServerInstruction>, + send_screen_instructions: SenderWithContext<ScreenInstruction>, } impl VteEventSender { - pub fn new(id: RawFd, send_server_instructions: SenderWithContext<ServerInstruction>) -> Self { + pub fn new(id: RawFd, send_screen_instructions: SenderWithContext<ScreenInstruction>) -> Self { VteEventSender { id, - send_server_instructions, + send_screen_instructions, } } } impl vte::Perform for VteEventSender { fn print(&mut self, c: char) { - self.send_server_instructions - .send(ServerInstruction::pty(self.id, VteEvent::Print(c))) + self.send_screen_instructions + .send(ScreenInstruction::Pty(self.id, VteEvent::Print(c))) .unwrap(); } fn execute(&mut self, byte: u8) { - self.send_server_instructions - .send(ServerInstruction::pty(self.id, VteEvent::Execute(byte))) + 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_server_instructions - .send(ServerInstruction::pty( + self.send_screen_instructions + .send(ScreenInstruction::Pty( self.id, VteEvent::Hook(params, intermediates, ignore, c), )) @@ -118,21 +118,21 @@ impl vte::Perform for VteEventSender { } fn put(&mut self, byte: u8) { - self.send_server_instructions - .send(ServerInstruction::pty(self.id, VteEvent::Put(byte))) + self.send_screen_instructions + .send(ScreenInstruction::Pty(self.id, VteEvent::Put(byte))) .unwrap(); } fn unhook(&mut self) { - self.send_server_instructions - .send(ServerInstruction::pty(self.id, VteEvent::Unhook)) + 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_server_instructions - .send(ServerInstruction::pty( + self.send_screen_instructions + .send(ScreenInstruction::Pty( self.id, VteEvent::OscDispatch(params, bell_terminated), )) @@ -142,8 +142,8 @@ impl vte::Perform for VteEventSender { 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_server_instructions - .send(ServerInstruction::pty( + self.send_screen_instructions + .send(ScreenInstruction::Pty( self.id, VteEvent::CsiDispatch(params, intermediates, ignore, c), )) @@ -152,8 +152,8 @@ impl vte::Perform for VteEventSender { fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) { let intermediates = intermediates.iter().copied().collect(); - self.send_server_instructions - .send(ServerInstruction::pty( + self.send_screen_instructions + .send(ScreenInstruction::Pty( self.id, VteEvent::EscDispatch(intermediates, ignore, byte), )) @@ -176,7 +176,8 @@ pub enum PtyInstruction { pub struct PtyBus { pub receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>, pub id_to_child_pid: HashMap<RawFd, RawFd>, - pub send_server_instructions: SenderWithContext<ServerInstruction>, + pub send_screen_instructions: SenderWithContext<ScreenInstruction>, + send_plugin_instructions: SenderWithContext<PluginInstruction>, os_input: Box<dyn ServerOsApi>, debug_to_file: bool, task_handles: HashMap<RawFd, JoinHandle<()>>, @@ -185,16 +186,16 @@ pub struct PtyBus { fn stream_terminal_bytes( pid: RawFd, os_input: Box<dyn ServerOsApi>, - mut send_server_instructions: SenderWithContext<ServerInstruction>, + mut send_screen_instructions: SenderWithContext<ScreenInstruction>, debug: bool, ) -> JoinHandle<()> { let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); task::spawn({ async move { err_ctx.add_call(ContextType::AsyncTask); - send_server_instructions.update(err_ctx); + send_screen_instructions.update(err_ctx); let mut vte_parser = vte::Parser::new(); - let mut vte_event_sender = VteEventSender::new(pid, send_server_instructions.clone()); + let mut vte_event_sender = VteEventSender::new(pid, send_screen_instructions.clone()); let mut terminal_bytes = ReadFromPid::new(&pid, os_input.clone()); let mut last_byte_receive_time: Option<Instant> = None; @@ -220,8 +221,8 @@ fn stream_terminal_bytes( Some(receive_time) => { if receive_time.elapsed() > max_render_pause { pending_render = false; - send_server_instructions - .send(ServerInstruction::render()) + send_screen_instructions + .send(ScreenInstruction::Render) .unwrap(); last_byte_receive_time = Some(Instant::now()); } else { @@ -236,23 +237,23 @@ fn stream_terminal_bytes( } else { if pending_render { pending_render = false; - send_server_instructions - .send(ServerInstruction::render()) + send_screen_instructions + .send(ScreenInstruction::Render) .unwrap(); } last_byte_receive_time = None; task::sleep(::std::time::Duration::from_millis(10)).await; } } - send_server_instructions - .send(ServerInstruction::render()) + send_screen_instructions + .send(ScreenInstruction::Render) .unwrap(); #[cfg(not(test))] // this is a little hacky, and is because the tests end the file as soon as // we read everything, rather than hanging until there is new data // a better solution would be to fix the test fakes, but this will do for now - send_server_instructions - .send(ServerInstruction::screen_close_pane(PaneId::Terminal(pid))) + send_screen_instructions + .send(ScreenInstruction::ClosePane(PaneId::Terminal(pid))) .unwrap(); } }) @@ -262,14 +263,16 @@ impl PtyBus { pub fn new( receive_pty_instructions: Receiver<(PtyInstruction, ErrorContext)>, os_input: Box<dyn ServerOsApi>, - send_server_instructions: SenderWithContext<ServerInstruction>, + send_screen_instructions: SenderWithContext<ScreenInstruction>, + send_plugin_instructions: SenderWithContext<PluginInstruction>, debug_to_file: bool, ) -> Self { PtyBus { receive_pty_instructions, os_input, id_to_child_pid: HashMap::new(), - send_server_instructions, + send_screen_instructions, + send_plugin_instructions, debug_to_file, task_handles: HashMap::new(), } @@ -280,7 +283,7 @@ impl PtyBus { let task_handle = stream_terminal_bytes( pid_primary, self.os_input.clone(), - self.send_server_instructions.clone(), + self.send_screen_instructions.clone(), self.debug_to_file, ); self.task_handles.insert(pid_primary, task_handle); @@ -296,17 +299,17 @@ impl PtyBus { self.id_to_child_pid.insert(pid_primary, pid_secondary); new_pane_pids.push(pid_primary); } - self.send_server_instructions - .send(ServerInstruction::apply_layout(( + self.send_screen_instructions + .send(ScreenInstruction::ApplyLayout( layout_path, new_pane_pids.clone(), - ))) + )) .unwrap(); for id in new_pane_pids { let task_handle = stream_terminal_bytes( id, self.os_input.clone(), - self.send_server_instructions.clone(), + self.send_screen_instructions.clone(), self.debug_to_file, ); self.task_handles.insert(id, task_handle); @@ -323,8 +326,8 @@ impl PtyBus { }); } PaneId::Plugin(pid) => self - .send_server_instructions - .send(ServerInstruction::ClosePluginPane(pid)) + .send_plugin_instructions + .send(PluginInstruction::Unload(pid)) .unwrap(), } } diff --git a/src/common/screen.rs b/src/common/screen.rs index 549eccd1..8868febb 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -7,9 +7,8 @@ use std::path::PathBuf; use std::str; use std::sync::mpsc::Receiver; -use crate::client::AppInstruction; use crate::common::SenderWithContext; -use crate::os_input_output::ClientOsApi; +use crate::os_input_output::ServerOsApi; use crate::panes::PositionAndSize; use crate::pty_bus::{PtyInstruction, VteEvent}; use crate::server::ServerInstruction; @@ -51,7 +50,7 @@ pub enum ScreenInstruction { SetMaxHeight(PaneId, usize), SetInvisibleBorders(PaneId, bool), ClosePane(PaneId), - ApplyLayout((PathBuf, Vec<RawFd>)), + ApplyLayout(PathBuf, Vec<RawFd>), NewTab(RawFd), SwitchTabNext, SwitchTabPrev, @@ -74,14 +73,16 @@ pub struct Screen { tabs: BTreeMap<usize, Tab>, /// A [`PluginInstruction`] and [`ErrorContext`] sender. pub send_plugin_instructions: SenderWithContext<PluginInstruction>, - /// An [`AppInstruction`] and [`ErrorContext`] sender. - pub send_app_instructions: SenderWithContext<AppInstruction>, + /// An [`PtyInstruction`] and [`ErrorContext`] sender. + pub send_pty_instructions: SenderWithContext<PtyInstruction>, + /// An [`ServerInstruction`] and [`ErrorContext`] sender. + pub send_server_instructions: SenderWithContext<ServerInstruction>, /// The full size of this [`Screen`]. full_screen_ws: PositionAndSize, /// The index of this [`Screen`]'s active [`Tab`]. active_tab_index: Option<usize>, /// The [`ClientOsApi`] this [`Screen`] uses. - pub os_api: Box<dyn ClientOsApi>, + os_api: Box<dyn ServerOsApi>, input_mode: InputMode, } @@ -92,9 +93,10 @@ impl Screen { pub fn new( receive_screen_instructions: Receiver<(ScreenInstruction, ErrorContext)>, send_plugin_instructions: SenderWithContext<PluginInstruction>, - send_app_instructions: SenderWithContext<AppInstruction>, + send_pty_instructions: SenderWithContext<PtyInstruction>, + send_server_instructions: SenderWithContext<ServerInstruction>, full_screen_ws: &PositionAndSize, - os_api: Box<dyn ClientOsApi>, + os_api: Box<dyn ServerOsApi>, max_panes: Option<usize>, mode_info: ModeInfo, input_mode: InputMode, @@ -104,7 +106,8 @@ impl Screen { receiver: receive_screen_instructions, max_panes, send_plugin_instructions, - send_app_instructions, + send_pty_instructions, + send_server_instructions, full_screen_ws: *full_screen_ws, active_tab_index: None, tabs: BTreeMap::new(), @@ -127,7 +130,8 @@ impl Screen { &self.full_screen_ws, self.os_api.clone(), self.send_plugin_instructions.clone(), - self.send_app_instructions.clone(), + self.send_pty_instructions.clone(), + self.send_server_instructions.clone(), self.max_panes, Some(PaneId::Terminal(pane_id)), self.mode_info.clone(), @@ -211,12 +215,13 @@ impl Screen { // below we don't check the result of sending the CloseTab instruction to the pty thread // because this might be happening when the app is closing, at which point the pty thread // has already closed and this would result in an error - self.os_api - .send_to_server(ServerInstruction::pty_close_tab(pane_ids)); + self.send_pty_instructions + .send(PtyInstruction::CloseTab(pane_ids)) + .unwrap(); if self.tabs.is_empty() { self.active_tab_index = None; - self.send_app_instructions - .send(AppInstruction::Exit) + self.send_server_instructions + .send(ServerInstruction::ClientShouldExit) .unwrap(); } else { for t in self.tabs.values_mut() { @@ -282,7 +287,8 @@ impl Screen { &self.full_screen_ws, self.os_api.clone(), self.send_plugin_instructions.clone(), - self.send_app_instructions.clone(), + self.send_pty_instructions.clone(), + self.send_server_instructions.clone(), self.max_panes, None, self.mode_info.clone(), diff --git a/src/common/wasm_vm.rs b/src/common/wasm_vm.rs index a7cd7543..5c234403 100644 --- a/src/common/wasm_vm.rs +++ b/src/common/wasm_vm.rs @@ -12,7 +12,6 @@ use wasmer_wasi::WasiEnv; use zellij_tile::data::{Event, EventType, PluginIds}; use super::{pty_bus::PtyInstruction, screen::ScreenInstruction, PaneId, SenderWithContext}; -use crate::client::AppInstruction; #[derive(Clone, Debug)] pub enum PluginInstruction { @@ -28,7 +27,7 @@ pub struct PluginEnv { pub plugin_id: u32, // FIXME: This should be a big bundle of all of the channels pub send_screen_instructions: SenderWithContext<ScreenInstruction>, - pub send_app_instructions: SenderWithContext<AppInstruction>, // FIXME: This should be a big bundle of all of the channels + pub send_pty_instructions: SenderWithContext<PtyInstruction>, // FIXME: This should be a big bundle of all of the channels pub wasi_env: WasiEnv, pub subscriptions: Arc<Mutex<HashSet<EventType>>>, } @@ -74,10 +73,8 @@ fn host_unsubscribe(plugin_env: &PluginEnv) { fn host_open_file(plugin_env: &PluginEnv) { let path = PathBuf::from(wasi_stdout(&plugin_env.wasi_env).lines().next().unwrap()); plugin_env - .send_app_instructions - .send(AppInstruction::ToPty(PtyInstruction::SpawnTerminal(Some( - path, - )))) + .send_pty_instructions + .send(PtyInstruction::SpawnTerminal(Some(path))) .unwrap(); } |
