Introduce DoneCLosingPane message to ensure atomicity in state change

This commit is contained in:
Kunal Mohan 2021-02-18 22:37:38 +05:30
parent 2111f95f33
commit ef1c902be6
4 changed files with 30 additions and 11 deletions

View file

@ -327,6 +327,7 @@ pub enum AppContext {
ToPty, ToPty,
ToPlugin, ToPlugin,
ToScreen, ToScreen,
DoneClosingPane,
} }
impl From<&AppInstruction> for AppContext { impl From<&AppInstruction> for AppContext {
@ -337,6 +338,7 @@ impl From<&AppInstruction> for AppContext {
AppInstruction::ToPty(_) => AppContext::ToPty, AppInstruction::ToPty(_) => AppContext::ToPty,
AppInstruction::ToPlugin(_) => AppContext::ToPlugin, AppInstruction::ToPlugin(_) => AppContext::ToPlugin,
AppInstruction::ToScreen(_) => AppContext::ToScreen, AppInstruction::ToScreen(_) => AppContext::ToScreen,
AppInstruction::DoneClosingPane => AppContext::DoneClosingPane,
} }
} }
} }

View file

@ -9,7 +9,7 @@ pub mod setup;
pub mod utils; pub mod utils;
pub mod wasm_vm; pub mod wasm_vm;
use std::io::{BufWriter, Write}; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::mpsc; use std::sync::mpsc;
use std::thread; use std::thread;
@ -51,6 +51,7 @@ pub enum ServerInstruction {
NewClient(String), NewClient(String),
ToPty(PtyInstruction), ToPty(PtyInstruction),
ToScreen(ScreenInstruction), ToScreen(ScreenInstruction),
DoneClosingPane,
ClosePluginPane(u32), ClosePluginPane(u32),
Exit, Exit,
} }
@ -60,6 +61,7 @@ pub enum ClientInstruction {
ToScreen(ScreenInstruction), ToScreen(ScreenInstruction),
ClosePluginPane(u32), ClosePluginPane(u32),
Error(String), Error(String),
DoneClosingPane,
Exit, Exit,
} }
@ -177,6 +179,7 @@ pub enum AppInstruction {
ToPty(PtyInstruction), ToPty(PtyInstruction),
ToScreen(ScreenInstruction), ToScreen(ScreenInstruction),
ToPlugin(PluginInstruction), ToPlugin(PluginInstruction),
DoneClosingPane,
} }
impl From<ClientInstruction> for AppInstruction { impl From<ClientInstruction> for AppInstruction {
@ -187,6 +190,7 @@ impl From<ClientInstruction> for AppInstruction {
ClientInstruction::ClosePluginPane(p) => { ClientInstruction::ClosePluginPane(p) => {
AppInstruction::ToPlugin(PluginInstruction::Unload(p)) AppInstruction::ToPlugin(PluginInstruction::Unload(p))
} }
ClientInstruction::DoneClosingPane => AppInstruction::DoneClosingPane,
ClientInstruction::Exit => AppInstruction::Exit, ClientInstruction::Exit => AppInstruction::Exit,
} }
} }
@ -202,9 +206,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
.write(take_snapshot.as_bytes()) .write(take_snapshot.as_bytes())
.unwrap(); .unwrap();
env::set_var(&"ZELLIJ", "0"); let mut command_is_executing = CommandIsExecuting::new();
let command_is_executing = CommandIsExecuting::new();
let full_screen_ws = os_input.get_terminal_size_using_fd(0); let full_screen_ws = os_input.get_terminal_size_using_fd(0);
os_input.set_raw_mode(0); os_input.set_raw_mode(0);
@ -379,7 +381,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
} }
ScreenInstruction::CloseFocusedPane => { ScreenInstruction::CloseFocusedPane => {
screen.get_active_tab_mut().unwrap().close_focused_pane(); screen.get_active_tab_mut().unwrap().close_focused_pane();
command_is_executing.done_closing_pane();
screen.render(); screen.render();
} }
ScreenInstruction::SetSelectable(id, selectable) => { ScreenInstruction::SetSelectable(id, selectable) => {
@ -403,7 +404,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
} }
ScreenInstruction::ClosePane(id) => { ScreenInstruction::ClosePane(id) => {
screen.get_active_tab_mut().unwrap().close_pane(id); screen.get_active_tab_mut().unwrap().close_pane(id);
command_is_executing.done_closing_pane();
screen.render(); screen.render();
} }
ScreenInstruction::ToggleActiveTerminalFullscreen => { ScreenInstruction::ToggleActiveTerminalFullscreen => {
@ -420,7 +420,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
ScreenInstruction::SwitchTabPrev => screen.switch_tab_prev(), ScreenInstruction::SwitchTabPrev => screen.switch_tab_prev(),
ScreenInstruction::CloseTab => { ScreenInstruction::CloseTab => {
screen.close_tab(); screen.close_tab();
command_is_executing.done_closing_pane();
} }
ScreenInstruction::ApplyLayout((layout, new_pane_pids)) => { ScreenInstruction::ApplyLayout((layout, new_pane_pids)) => {
screen.apply_layout(Layout::new(layout), new_pane_pids); screen.apply_layout(Layout::new(layout), new_pane_pids);
@ -539,6 +538,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
let send_screen_instructions = send_screen_instructions.clone(); let send_screen_instructions = send_screen_instructions.clone();
let send_plugin_instructions = send_plugin_instructions.clone(); let send_plugin_instructions = send_plugin_instructions.clone();
let send_app_instructions = send_app_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 os_input = os_input.clone();
let config = config; let config = config;
move || { move || {
@ -612,6 +612,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs, config: Config) {
AppInstruction::ToPty(instruction) => { AppInstruction::ToPty(instruction) => {
let _ = send_server_instructions.send(ServerInstruction::ToPty(instruction)); let _ = send_server_instructions.send(ServerInstruction::ToPty(instruction));
} }
AppInstruction::DoneClosingPane => command_is_executing.done_closing_pane(),
} }
} }

View file

@ -5,7 +5,7 @@ mod server;
use client::{boundaries, layout, panes, tab}; use client::{boundaries, layout, panes, tab};
use common::{ 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, IpcSenderWithContext, ServerInstruction,
}; };
use directories_next::ProjectDirs; use directories_next::ProjectDirs;

View file

@ -1,5 +1,4 @@
use crate::cli::CliArgs; use crate::cli::CliArgs;
use crate::command_is_executing::CommandIsExecuting;
use crate::common::{ use crate::common::{
ChannelWithContext, ClientInstruction, IpcSenderWithContext, SenderType, SenderWithContext, ChannelWithContext, ClientInstruction, IpcSenderWithContext, SenderType, SenderWithContext,
ServerInstruction, ServerInstruction,
@ -88,8 +87,20 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> thread::JoinHand
.unwrap(); .unwrap();
} }
} }
PtyInstruction::ClosePane(id) => pty_bus.close_pane(id), PtyInstruction::ClosePane(id) => {
PtyInstruction::CloseTab(ids) => pty_bus.close_tab(ids), 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 => { PtyInstruction::Exit => {
break; break;
} }
@ -149,6 +160,11 @@ pub fn start_server(os_input: Box<dyn OsApi>, opts: CliArgs) -> thread::JoinHand
.send(ClientInstruction::ToScreen(instr)) .send(ClientInstruction::ToScreen(instr))
.unwrap(); .unwrap();
} }
ServerInstruction::DoneClosingPane => {
send_client_instructions[0]
.send(ClientInstruction::DoneClosingPane)
.unwrap();
}
ServerInstruction::ClosePluginPane(pid) => { ServerInstruction::ClosePluginPane(pid) => {
send_client_instructions[0] send_client_instructions[0]
.send(ClientInstruction::ClosePluginPane(pid)) .send(ClientInstruction::ClosePluginPane(pid))