summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-02-18 22:37:38 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-04-14 01:41:29 +0530
commit895dfc934cad160f5ecb7b02e32c9cf82f1d5d6b (patch)
tree420771ee3de8a6a994163aa0b056f0ae54e233a5
parent02dcad330874de3320a5accfc278e431481281e3 (diff)
Introduce DoneCLosingPane message to ensure atomicity in state change
-rw-r--r--src/common/errors.rs2
-rw-r--r--src/common/mod.rs20
-rw-r--r--src/main.rs2
-rw-r--r--src/server/mod.rs22
4 files changed, 30 insertions, 16 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs
index 63b9d190f..d30af844a 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -321,6 +321,7 @@ pub enum AppContext {
ToPty,
ToPlugin,
ToScreen,
+ DoneClosingPane,
}
impl From<&AppInstruction> for AppContext {
@@ -331,6 +332,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 8bbee6e24..5e5d04d47 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -9,7 +9,7 @@ pub mod screen;
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<ClientInstruction> for AppInstruction {
@@ -187,6 +190,7 @@ impl From<ClientInstruction> for AppInstruction {
ClientInstruction::ClosePluginPane(p) => {
AppInstruction::ToPlugin(PluginInstruction::Unload(p))
}
+ ClientInstruction::DoneClosingPane => AppInstruction::DoneClosingPane,
ClientInstruction::Exit => AppInstruction::Exit,
}
}
@@ -202,14 +206,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
.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 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);
@@ -366,7 +363,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
}
ScreenInstruction::CloseFocusedPane => {
screen.get_active_tab_mut().unwrap().close_focused_pane();
- command_is_executing.done_closing_pane();
screen.render();
}
ScreenInstruction::SetSelectable(id, selectable) => {
@@ -390,7 +386,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
}
ScreenInstruction::ClosePane(id) => {
screen.get_active_tab_mut().unwrap().close_pane(id);
- command_is_executing.done_closing_pane();
screen.render();
}
ScreenInstruction::ToggleActiveTerminalFullscreen => {
@@ -407,7 +402,6 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
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);
@@ -530,6 +524,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
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 || {
@@ -603,6 +598,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: CliArgs) {
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 17a56ee4c..3de198583 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,7 +8,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 e62aa7fc3..e71e91dac 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<dyn OsApi>, 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<dyn OsApi>, 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))