From ef1c902be6c9d004f2f4124f7aa5b7d53fe22f17 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Thu, 18 Feb 2021 22:37:38 +0530 Subject: [PATCH] Introduce DoneCLosingPane message to ensure atomicity in state change --- src/common/errors.rs | 2 ++ src/common/mod.rs | 15 ++++++++------- src/main.rs | 2 +- src/server/mod.rs | 22 +++++++++++++++++++--- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/common/errors.rs b/src/common/errors.rs index 1cdff574..fcb37482 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -327,6 +327,7 @@ pub enum AppContext { ToPty, ToPlugin, ToScreen, + DoneClosingPane, } impl From<&AppInstruction> for AppContext { @@ -337,6 +338,7 @@ impl From<&AppInstruction> for AppContext { AppInstruction::ToPty(_) => AppContext::ToPty, AppInstruction::ToPlugin(_) => AppContext::ToPlugin, AppInstruction::ToScreen(_) => AppContext::ToScreen, + AppInstruction::DoneClosingPane => AppContext::DoneClosingPane, } } } diff --git a/src/common/mod.rs b/src/common/mod.rs index fc060e4d..c0c35565 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -9,7 +9,7 @@ pub mod setup; pub mod utils; pub mod wasm_vm; -use std::io::{BufWriter, Write}; +use std::io::Write; use std::path::{Path, PathBuf}; use std::sync::mpsc; use std::thread; @@ -51,6 +51,7 @@ pub enum ServerInstruction { NewClient(String), ToPty(PtyInstruction), ToScreen(ScreenInstruction), + DoneClosingPane, ClosePluginPane(u32), Exit, } @@ -60,6 +61,7 @@ pub enum ClientInstruction { ToScreen(ScreenInstruction), ClosePluginPane(u32), Error(String), + DoneClosingPane, Exit, } @@ -177,6 +179,7 @@ pub enum AppInstruction { ToPty(PtyInstruction), ToScreen(ScreenInstruction), ToPlugin(PluginInstruction), + DoneClosingPane, } impl From for AppInstruction { @@ -187,6 +190,7 @@ impl From for AppInstruction { ClientInstruction::ClosePluginPane(p) => { AppInstruction::ToPlugin(PluginInstruction::Unload(p)) } + ClientInstruction::DoneClosingPane => AppInstruction::DoneClosingPane, ClientInstruction::Exit => AppInstruction::Exit, } } @@ -202,9 +206,7 @@ pub fn start(mut os_input: Box, opts: CliArgs, config: Config) { .write(take_snapshot.as_bytes()) .unwrap(); - env::set_var(&"ZELLIJ", "0"); - - let command_is_executing = CommandIsExecuting::new(); + 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); @@ -379,7 +381,6 @@ pub fn start(mut os_input: Box, opts: CliArgs, config: Config) { } ScreenInstruction::CloseFocusedPane => { screen.get_active_tab_mut().unwrap().close_focused_pane(); - command_is_executing.done_closing_pane(); screen.render(); } ScreenInstruction::SetSelectable(id, selectable) => { @@ -403,7 +404,6 @@ pub fn start(mut os_input: Box, opts: CliArgs, config: Config) { } ScreenInstruction::ClosePane(id) => { screen.get_active_tab_mut().unwrap().close_pane(id); - command_is_executing.done_closing_pane(); screen.render(); } ScreenInstruction::ToggleActiveTerminalFullscreen => { @@ -420,7 +420,6 @@ pub fn start(mut os_input: Box, opts: CliArgs, config: Config) { ScreenInstruction::SwitchTabPrev => screen.switch_tab_prev(), ScreenInstruction::CloseTab => { screen.close_tab(); - command_is_executing.done_closing_pane(); } ScreenInstruction::ApplyLayout((layout, new_pane_pids)) => { screen.apply_layout(Layout::new(layout), new_pane_pids); @@ -539,6 +538,7 @@ pub fn start(mut os_input: Box, opts: CliArgs, config: Config) { let send_screen_instructions = send_screen_instructions.clone(); let send_plugin_instructions = send_plugin_instructions.clone(); let send_app_instructions = send_app_instructions.clone(); + let command_is_executing = command_is_executing.clone(); let os_input = os_input.clone(); let config = config; move || { @@ -612,6 +612,7 @@ pub fn start(mut os_input: Box, opts: CliArgs, config: Config) { AppInstruction::ToPty(instruction) => { let _ = send_server_instructions.send(ServerInstruction::ToPty(instruction)); } + AppInstruction::DoneClosingPane => command_is_executing.done_closing_pane(), } } diff --git a/src/main.rs b/src/main.rs index 2ad38135..e5cdbe53 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ mod server; use client::{boundaries, layout, panes, tab}; use common::{ - command_is_executing, errors, ipc, os_input_output, pty_bus, screen, start, utils, wasm_vm, + command_is_executing, errors, os_input_output, pty_bus, screen, start, utils, wasm_vm, IpcSenderWithContext, ServerInstruction, }; use directories_next::ProjectDirs; diff --git a/src/server/mod.rs b/src/server/mod.rs index e62aa7fc..e71e91da 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,5 +1,4 @@ use crate::cli::CliArgs; -use crate::command_is_executing::CommandIsExecuting; use crate::common::{ ChannelWithContext, ClientInstruction, IpcSenderWithContext, SenderType, SenderWithContext, ServerInstruction, @@ -88,8 +87,20 @@ pub fn start_server(os_input: Box, opts: CliArgs) -> thread::JoinHand .unwrap(); } } - PtyInstruction::ClosePane(id) => pty_bus.close_pane(id), - PtyInstruction::CloseTab(ids) => pty_bus.close_tab(ids), + PtyInstruction::ClosePane(id) => { + pty_bus.close_pane(id); + pty_bus + .send_server_instructions + .send(ServerInstruction::DoneClosingPane) + .unwrap(); + } + PtyInstruction::CloseTab(ids) => { + pty_bus.close_tab(ids); + pty_bus + .send_server_instructions + .send(ServerInstruction::DoneClosingPane) + .unwrap(); + } PtyInstruction::Exit => { break; } @@ -149,6 +160,11 @@ pub fn start_server(os_input: Box, opts: CliArgs) -> thread::JoinHand .send(ClientInstruction::ToScreen(instr)) .unwrap(); } + ServerInstruction::DoneClosingPane => { + send_client_instructions[0] + .send(ClientInstruction::DoneClosingPane) + .unwrap(); + } ServerInstruction::ClosePluginPane(pid) => { send_client_instructions[0] .send(ClientInstruction::ClosePluginPane(pid))