Synchronize update tabs actions using command_is_executing
This commit is contained in:
parent
965cc71918
commit
bbcea31988
3 changed files with 56 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ use std::sync::{Arc, Condvar, Mutex};
|
|||
pub struct CommandIsExecuting {
|
||||
opening_new_pane: Arc<(Mutex<bool>, Condvar)>,
|
||||
closing_pane: Arc<(Mutex<bool>, Condvar)>,
|
||||
updating_tabs: Arc<(Mutex<bool>, Condvar)>,
|
||||
}
|
||||
|
||||
impl CommandIsExecuting {
|
||||
|
|
@ -12,6 +13,7 @@ impl CommandIsExecuting {
|
|||
CommandIsExecuting {
|
||||
opening_new_pane: Arc::new((Mutex::new(false), Condvar::new())),
|
||||
closing_pane: Arc::new((Mutex::new(false), Condvar::new())),
|
||||
updating_tabs: Arc::new((Mutex::new(false), Condvar::new())),
|
||||
}
|
||||
}
|
||||
pub fn closing_pane(&mut self) {
|
||||
|
|
@ -36,6 +38,17 @@ impl CommandIsExecuting {
|
|||
*opening_new_pane = false;
|
||||
cvar.notify_all();
|
||||
}
|
||||
pub fn updating_tabs(&mut self) {
|
||||
let (lock, _cvar) = &*self.updating_tabs;
|
||||
let mut updating_tabs = lock.lock().unwrap();
|
||||
*updating_tabs = true;
|
||||
}
|
||||
pub fn done_updating_tabs(&self) {
|
||||
let (lock, cvar) = &*self.updating_tabs;
|
||||
let mut updating_tabs = lock.lock().unwrap();
|
||||
*updating_tabs = false;
|
||||
cvar.notify_one();
|
||||
}
|
||||
pub fn wait_until_pane_is_closed(&self) {
|
||||
let (lock, cvar) = &*self.closing_pane;
|
||||
let mut closing_pane = lock.lock().unwrap();
|
||||
|
|
@ -50,4 +63,11 @@ impl CommandIsExecuting {
|
|||
opening_new_pane = cvar.wait(opening_new_pane).unwrap();
|
||||
}
|
||||
}
|
||||
pub fn wait_until_tabs_are_updated(&self) {
|
||||
let (lock, cvar) = &*self.updating_tabs;
|
||||
let mut updating_tabs = lock.lock().unwrap();
|
||||
while *updating_tabs {
|
||||
updating_tabs = cvar.wait(updating_tabs).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,21 +238,25 @@ impl InputHandler {
|
|||
self.command_is_executing.wait_until_pane_is_closed();
|
||||
}
|
||||
Action::NewTab => {
|
||||
self.command_is_executing.opening_new_pane();
|
||||
self.command_is_executing.updating_tabs();
|
||||
self.send_app_instructions
|
||||
.send(AppInstruction::ToPty(PtyInstruction::NewTab))
|
||||
.unwrap();
|
||||
self.command_is_executing.wait_until_new_pane_is_opened();
|
||||
self.command_is_executing.wait_until_tabs_are_updated();
|
||||
}
|
||||
Action::GoToNextTab => {
|
||||
self.command_is_executing.updating_tabs();
|
||||
self.send_screen_instructions
|
||||
.send(ScreenInstruction::SwitchTabNext)
|
||||
.unwrap();
|
||||
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.command_is_executing.wait_until_tabs_are_updated();
|
||||
}
|
||||
Action::ToggleActiveSyncPanes => {
|
||||
self.send_screen_instructions
|
||||
|
|
@ -260,22 +264,37 @@ impl InputHandler {
|
|||
.unwrap();
|
||||
}
|
||||
Action::CloseTab => {
|
||||
self.command_is_executing.closing_pane();
|
||||
self.command_is_executing.updating_tabs();
|
||||
self.send_screen_instructions
|
||||
.send(ScreenInstruction::CloseTab)
|
||||
.unwrap();
|
||||
self.command_is_executing.wait_until_pane_is_closed();
|
||||
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.command_is_executing.wait_until_tabs_are_updated();
|
||||
}
|
||||
Action::TabNameInput(c) => {
|
||||
self.send_screen_instructions
|
||||
.send(ScreenInstruction::UpdateTabName(c))
|
||||
.unwrap();
|
||||
}
|
||||
Action::SaveTabName => {
|
||||
self.command_is_executing.updating_tabs();
|
||||
self.send_plugin_instructions
|
||||
.send(PluginInstruction::Input(
|
||||
PluginInputType::Event(EventType::Tab),
|
||||
vec![b'\n'],
|
||||
))
|
||||
.unwrap();
|
||||
self.send_screen_instructions
|
||||
.send(ScreenInstruction::UpdateTabName(vec![b'\n']))
|
||||
.unwrap();
|
||||
self.command_is_executing.wait_until_tabs_are_updated();
|
||||
}
|
||||
Action::NoOp => {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -386,22 +386,31 @@ pub fn start(
|
|||
}
|
||||
ScreenInstruction::NewTab(pane_id) => {
|
||||
screen.new_tab(pane_id);
|
||||
command_is_executing.done_opening_new_pane();
|
||||
command_is_executing.done_updating_tabs();
|
||||
}
|
||||
ScreenInstruction::SwitchTabNext => {
|
||||
screen.switch_tab_next();
|
||||
command_is_executing.done_updating_tabs();
|
||||
}
|
||||
ScreenInstruction::SwitchTabPrev => {
|
||||
screen.switch_tab_prev();
|
||||
command_is_executing.done_updating_tabs();
|
||||
}
|
||||
ScreenInstruction::SwitchTabNext => screen.switch_tab_next(),
|
||||
ScreenInstruction::SwitchTabPrev => screen.switch_tab_prev(),
|
||||
ScreenInstruction::CloseTab => {
|
||||
screen.close_tab();
|
||||
command_is_executing.done_updating_tabs();
|
||||
}
|
||||
ScreenInstruction::ApplyLayout((layout, new_pane_pids)) => {
|
||||
screen.apply_layout(Layout::new(layout), new_pane_pids);
|
||||
command_is_executing.done_opening_new_pane();
|
||||
}
|
||||
ScreenInstruction::GoToTab(tab_index) => {
|
||||
screen.go_to_tab(tab_index as usize)
|
||||
screen.go_to_tab(tab_index as usize);
|
||||
command_is_executing.done_updating_tabs();
|
||||
}
|
||||
ScreenInstruction::UpdateTabName(c) => {
|
||||
screen.update_active_tab_name(c);
|
||||
command_is_executing.done_updating_tabs();
|
||||
}
|
||||
ScreenInstruction::Exit => {
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue