Deduplicate code in zellij-server screen (#1453)
This commit is contained in:
parent
88757d16a9
commit
13d9110280
1 changed files with 145 additions and 381 deletions
|
|
@ -791,6 +791,36 @@ impl Screen {
|
||||||
self.update_tabs();
|
self.update_tabs();
|
||||||
self.render();
|
self.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unblock_input(&self) -> () {
|
||||||
|
self.bus
|
||||||
|
.senders
|
||||||
|
.send_to_server(ServerInstruction::UnblockInputThread)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the active tab and call a closure on it
|
||||||
|
///
|
||||||
|
/// If no active tab can be found, an error is logged instead.
|
||||||
|
///
|
||||||
|
/// # Parameters
|
||||||
|
///
|
||||||
|
/// - screen: An instance of `Screen` to operate on
|
||||||
|
/// - client_id: The client_id, usually taken from the `ScreenInstruction` that's being processed
|
||||||
|
/// - closure: A closure satisfying `|tab: &mut Tab| -> ()`
|
||||||
|
macro_rules! active_tab {
|
||||||
|
($screen:ident, $client_id:ident, $closure:expr) => {
|
||||||
|
if let Some(active_tab) = $screen.get_active_tab_mut($client_id) {
|
||||||
|
// This could be made more ergonomic by declaring the type of 'active_tab' in the
|
||||||
|
// closure, known as "Type Ascription". Then we could hint the type here and forego the
|
||||||
|
// "&mut Tab" in all the closures below...
|
||||||
|
// See: https://github.com/rust-lang/rust/issues/23416
|
||||||
|
$closure(active_tab);
|
||||||
|
} else {
|
||||||
|
log::error!("Active tab not found for client id: {:?}", $client_id);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// The box is here in order to make the
|
// The box is here in order to make the
|
||||||
|
|
@ -827,12 +857,14 @@ pub(crate) fn screen_thread_main(
|
||||||
session_is_mirrored,
|
session_is_mirrored,
|
||||||
copy_options,
|
copy_options,
|
||||||
);
|
);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (event, mut err_ctx) = screen
|
let (event, mut err_ctx) = screen
|
||||||
.bus
|
.bus
|
||||||
.recv()
|
.recv()
|
||||||
.expect("failed to receive event on channel");
|
.expect("failed to receive event on channel");
|
||||||
err_ctx.add_call(ContextType::Screen((&event).into()));
|
err_ctx.add_call(ContextType::Screen((&event).into()));
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
ScreenInstruction::PtyBytes(pid, vte_bytes) => {
|
ScreenInstruction::PtyBytes(pid, vte_bytes) => {
|
||||||
let all_tabs = screen.get_tabs_mut();
|
let all_tabs = screen.get_tabs_mut();
|
||||||
|
|
@ -849,11 +881,8 @@ pub(crate) fn screen_thread_main(
|
||||||
ScreenInstruction::NewPane(pid, client_or_tab_index) => {
|
ScreenInstruction::NewPane(pid, client_or_tab_index) => {
|
||||||
match client_or_tab_index {
|
match client_or_tab_index {
|
||||||
ClientOrTabIndex::ClientId(client_id) => {
|
ClientOrTabIndex::ClientId(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.new_pane(pid, Some(client_id));
|
.new_pane(pid, Some(client_id)));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
ClientOrTabIndex::TabIndex(tab_index) => {
|
ClientOrTabIndex::TabIndex(tab_index) => {
|
||||||
if let Some(active_tab) = screen.tabs.get_mut(&tab_index) {
|
if let Some(active_tab) = screen.tabs.get_mut(&tab_index) {
|
||||||
|
|
@ -863,393 +892,217 @@ pub(crate) fn screen_thread_main(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::OpenInPlaceEditor(pid, client_id) => {
|
ScreenInstruction::OpenInPlaceEditor(pid, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.suppress_active_pane(pid, client_id);
|
.suppress_active_pane(pid, client_id));
|
||||||
} else {
|
screen.unblock_input();
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
screen
|
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::TogglePaneEmbedOrFloating(client_id) => {
|
ScreenInstruction::TogglePaneEmbedOrFloating(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.toggle_pane_embed_or_floating(client_id);
|
.toggle_pane_embed_or_floating(client_id));
|
||||||
} else {
|
screen.unblock_input();
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen
|
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
screen.update_tabs(); // update tabs so that the ui indication will be send to the plugins
|
screen.update_tabs(); // update tabs so that the ui indication will be send to the plugins
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ToggleFloatingPanes(client_id, default_shell) => {
|
ScreenInstruction::ToggleFloatingPanes(client_id, default_shell) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.toggle_floating_panes(client_id, default_shell);
|
.toggle_floating_panes(client_id, default_shell));
|
||||||
} else {
|
screen.unblock_input();
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen
|
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
screen.update_tabs(); // update tabs so that the ui indication will be send to the plugins
|
screen.update_tabs(); // update tabs so that the ui indication will be send to the plugins
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::HorizontalSplit(pid, client_id) => {
|
ScreenInstruction::HorizontalSplit(pid, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.horizontal_split(pid, client_id);
|
.horizontal_split(pid, client_id));
|
||||||
} else {
|
screen.unblock_input();
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen
|
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::VerticalSplit(pid, client_id) => {
|
ScreenInstruction::VerticalSplit(pid, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.vertical_split(pid, client_id);
|
.vertical_split(pid, client_id));
|
||||||
} else {
|
screen.unblock_input();
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen
|
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::WriteCharacter(bytes, client_id) => {
|
ScreenInstruction::WriteCharacter(bytes, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| {
|
||||||
match active_tab.is_sync_panes_active() {
|
match tab.is_sync_panes_active() {
|
||||||
true => active_tab.write_to_terminals_on_current_tab(bytes),
|
true => tab.write_to_terminals_on_current_tab(bytes),
|
||||||
false => active_tab.write_to_active_terminal(bytes, client_id),
|
false => tab.write_to_active_terminal(bytes, client_id),
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
ScreenInstruction::ResizeLeft(client_id) => {
|
ScreenInstruction::ResizeLeft(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.resize_left(client_id);
|
.resize_left(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ResizeRight(client_id) => {
|
ScreenInstruction::ResizeRight(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.resize_right(client_id);
|
.resize_right(client_id));
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ResizeDown(client_id) => {
|
ScreenInstruction::ResizeDown(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.resize_down(client_id);
|
.resize_down(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ResizeUp(client_id) => {
|
ScreenInstruction::ResizeUp(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab.resize_up(client_id));
|
||||||
active_tab.resize_up(client_id);
|
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ResizeIncrease(client_id) => {
|
ScreenInstruction::ResizeIncrease(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.resize_increase(client_id);
|
.resize_increase(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ResizeDecrease(client_id) => {
|
ScreenInstruction::ResizeDecrease(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.resize_decrease(client_id);
|
.resize_decrease(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::SwitchFocus(client_id) => {
|
ScreenInstruction::SwitchFocus(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.focus_next_pane(client_id);
|
.focus_next_pane(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::FocusNextPane(client_id) => {
|
ScreenInstruction::FocusNextPane(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.focus_next_pane(client_id);
|
.focus_next_pane(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::FocusPreviousPane(client_id) => {
|
ScreenInstruction::FocusPreviousPane(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.focus_previous_pane(client_id);
|
.focus_previous_pane(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MoveFocusLeft(client_id) => {
|
ScreenInstruction::MoveFocusLeft(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_focus_left(client_id);
|
.move_focus_left(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MoveFocusLeftOrPreviousTab(client_id) => {
|
ScreenInstruction::MoveFocusLeftOrPreviousTab(client_id) => {
|
||||||
screen.move_focus_left_or_previous_tab(client_id);
|
screen.move_focus_left_or_previous_tab(client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MoveFocusDown(client_id) => {
|
ScreenInstruction::MoveFocusDown(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_focus_down(client_id);
|
.move_focus_down(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MoveFocusRight(client_id) => {
|
ScreenInstruction::MoveFocusRight(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_focus_right(client_id);
|
.move_focus_right(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MoveFocusRightOrNextTab(client_id) => {
|
ScreenInstruction::MoveFocusRightOrNextTab(client_id) => {
|
||||||
screen.move_focus_right_or_next_tab(client_id);
|
screen.move_focus_right_or_next_tab(client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MoveFocusUp(client_id) => {
|
ScreenInstruction::MoveFocusUp(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_focus_up(client_id);
|
.move_focus_up(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::DumpScreen(file, client_id) => {
|
ScreenInstruction::DumpScreen(file, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.dump_active_terminal_screen(Some(file.to_string()), client_id);
|
.dump_active_terminal_screen(Some(file.to_string()), client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::EditScrollback(client_id) => {
|
ScreenInstruction::EditScrollback(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.edit_scrollback(client_id);
|
.edit_scrollback(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ScrollUp(client_id) => {
|
ScreenInstruction::ScrollUp(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_up(client_id);
|
.scroll_active_terminal_up(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MovePane(client_id) => {
|
ScreenInstruction::MovePane(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_active_pane(client_id);
|
.move_active_pane(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MovePaneDown(client_id) => {
|
ScreenInstruction::MovePaneDown(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_active_pane_down(client_id);
|
.move_active_pane_down(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MovePaneUp(client_id) => {
|
ScreenInstruction::MovePaneUp(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_active_pane_up(client_id);
|
.move_active_pane_up(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MovePaneRight(client_id) => {
|
ScreenInstruction::MovePaneRight(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_active_pane_right(client_id);
|
.move_active_pane_right(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MovePaneLeft(client_id) => {
|
ScreenInstruction::MovePaneLeft(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.move_active_pane_left(client_id);
|
.move_active_pane_left(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ScrollUpAt(point, client_id) => {
|
ScreenInstruction::ScrollUpAt(point, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_terminal_up(&point, 3, client_id);
|
.scroll_terminal_up(&point, 3, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ScrollDown(client_id) => {
|
ScreenInstruction::ScrollDown(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_down(client_id);
|
.scroll_active_terminal_down(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ScrollDownAt(point, client_id) => {
|
ScreenInstruction::ScrollDownAt(point, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_terminal_down(&point, 3, client_id);
|
.scroll_terminal_down(&point, 3, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ScrollToBottom(client_id) => {
|
ScreenInstruction::ScrollToBottom(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_to_bottom(client_id);
|
.scroll_active_terminal_to_bottom(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::PageScrollUp(client_id) => {
|
ScreenInstruction::PageScrollUp(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_up_page(client_id);
|
.scroll_active_terminal_up_page(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::PageScrollDown(client_id) => {
|
ScreenInstruction::PageScrollDown(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_down_page(client_id);
|
.scroll_active_terminal_down_page(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::HalfPageScrollUp(client_id) => {
|
ScreenInstruction::HalfPageScrollUp(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_up_half_page(client_id);
|
.scroll_active_terminal_up_half_page(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::HalfPageScrollDown(client_id) => {
|
ScreenInstruction::HalfPageScrollDown(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.scroll_active_terminal_down_half_page(client_id);
|
.scroll_active_terminal_down_half_page(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ClearScroll(client_id) => {
|
ScreenInstruction::ClearScroll(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.clear_active_terminal_scroll(client_id);
|
.clear_active_terminal_scroll(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::CloseFocusedPane(client_id) => {
|
ScreenInstruction::CloseFocusedPane(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.close_focused_pane(client_id);
|
.close_focused_pane(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen.update_tabs(); // update_tabs eventually calls render through the plugin thread
|
screen.update_tabs(); // update_tabs eventually calls render through the plugin thread
|
||||||
},
|
},
|
||||||
ScreenInstruction::SetSelectable(id, selectable, tab_index) => {
|
ScreenInstruction::SetSelectable(id, selectable, tab_index) => {
|
||||||
|
|
@ -1269,13 +1122,7 @@ pub(crate) fn screen_thread_main(
|
||||||
ScreenInstruction::ClosePane(id, client_id) => {
|
ScreenInstruction::ClosePane(id, client_id) => {
|
||||||
match client_id {
|
match client_id {
|
||||||
Some(client_id) => {
|
Some(client_id) => {
|
||||||
screen
|
active_tab!(screen, client_id, |tab: &mut Tab| tab.close_pane(id, false));
|
||||||
.get_active_tab_mut(client_id)
|
|
||||||
.and_then(|active_tab| active_tab.close_pane(id, false))
|
|
||||||
.or_else(|| {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
None
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
for tab in screen.tabs.values_mut() {
|
for tab in screen.tabs.values_mut() {
|
||||||
|
|
@ -1289,22 +1136,14 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
},
|
},
|
||||||
ScreenInstruction::UpdatePaneName(c, client_id) => {
|
ScreenInstruction::UpdatePaneName(c, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.update_active_pane_name(c, client_id);
|
.update_active_pane_name(c, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ToggleActiveTerminalFullscreen(client_id) => {
|
ScreenInstruction::ToggleActiveTerminalFullscreen(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.toggle_active_pane_fullscreen(client_id);
|
.toggle_active_pane_fullscreen(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::TogglePaneFrames => {
|
ScreenInstruction::TogglePaneFrames => {
|
||||||
|
|
@ -1316,42 +1155,22 @@ pub(crate) fn screen_thread_main(
|
||||||
},
|
},
|
||||||
ScreenInstruction::SwitchTabNext(client_id) => {
|
ScreenInstruction::SwitchTabNext(client_id) => {
|
||||||
screen.switch_tab_next(client_id);
|
screen.switch_tab_next(client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::SwitchTabPrev(client_id) => {
|
ScreenInstruction::SwitchTabPrev(client_id) => {
|
||||||
screen.switch_tab_prev(client_id);
|
screen.switch_tab_prev(client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::CloseTab(client_id) => {
|
ScreenInstruction::CloseTab(client_id) => {
|
||||||
screen.close_tab(client_id);
|
screen.close_tab(client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::NewTab(layout, new_pane_pids, client_id) => {
|
ScreenInstruction::NewTab(layout, new_pane_pids, client_id) => {
|
||||||
screen.new_tab(layout, new_pane_pids, client_id);
|
screen.new_tab(layout, new_pane_pids, client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::GoToTab(tab_index, client_id) => {
|
ScreenInstruction::GoToTab(tab_index, client_id) => {
|
||||||
|
|
@ -1359,23 +1178,16 @@ pub(crate) fn screen_thread_main(
|
||||||
client_id.or_else(|| screen.active_tab_indices.keys().next().copied())
|
client_id.or_else(|| screen.active_tab_indices.keys().next().copied())
|
||||||
{
|
{
|
||||||
screen.go_to_tab(tab_index as usize, client_id);
|
screen.go_to_tab(tab_index as usize, client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ScreenInstruction::UpdateTabName(c, client_id) => {
|
ScreenInstruction::UpdateTabName(c, client_id) => {
|
||||||
screen.update_active_tab_name(c, client_id);
|
screen.update_active_tab_name(c, client_id);
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::TerminalResize(new_size) => {
|
ScreenInstruction::TerminalResize(new_size) => {
|
||||||
screen.resize_to_screen(new_size);
|
screen.resize_to_screen(new_size);
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::TerminalPixelDimensions(pixel_dimensions) => {
|
ScreenInstruction::TerminalPixelDimensions(pixel_dimensions) => {
|
||||||
|
|
@ -1389,64 +1201,39 @@ pub(crate) fn screen_thread_main(
|
||||||
},
|
},
|
||||||
ScreenInstruction::ChangeMode(mode_info, client_id) => {
|
ScreenInstruction::ChangeMode(mode_info, client_id) => {
|
||||||
screen.change_mode(mode_info, client_id);
|
screen.change_mode(mode_info, client_id);
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::ToggleActiveSyncTab(client_id) => {
|
ScreenInstruction::ToggleActiveSyncTab(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.toggle_sync_panes_is_active();
|
.toggle_sync_panes_is_active());
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::LeftClick(point, client_id) => {
|
ScreenInstruction::LeftClick(point, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.handle_left_click(&point, client_id);
|
.handle_left_click(&point, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::RightClick(point, client_id) => {
|
ScreenInstruction::RightClick(point, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.handle_right_click(&point, client_id);
|
.handle_right_click(&point, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MouseRelease(point, client_id) => {
|
ScreenInstruction::MouseRelease(point, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.handle_mouse_release(&point, client_id);
|
.handle_mouse_release(&point, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::MouseHold(point, client_id) => {
|
ScreenInstruction::MouseHold(point, client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.handle_mouse_hold(&point, client_id);
|
.handle_mouse_hold(&point, client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::Copy(client_id) => {
|
ScreenInstruction::Copy(client_id) => {
|
||||||
if let Some(active_tab) = screen.get_active_tab(client_id) {
|
active_tab!(screen, client_id, |tab: &mut Tab| tab
|
||||||
active_tab.copy_selection(client_id);
|
.copy_selection(client_id));
|
||||||
} else {
|
|
||||||
log::error!("Active tab not found for client id: {:?}", client_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::Exit => {
|
ScreenInstruction::Exit => {
|
||||||
|
|
@ -1454,42 +1241,27 @@ pub(crate) fn screen_thread_main(
|
||||||
},
|
},
|
||||||
ScreenInstruction::ToggleTab(client_id) => {
|
ScreenInstruction::ToggleTab(client_id) => {
|
||||||
screen.toggle_tab(client_id);
|
screen.toggle_tab(client_id);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::AddClient(client_id) => {
|
ScreenInstruction::AddClient(client_id) => {
|
||||||
screen.add_client(client_id);
|
screen.add_client(client_id);
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::RemoveClient(client_id) => {
|
ScreenInstruction::RemoveClient(client_id) => {
|
||||||
screen.remove_client(client_id);
|
screen.remove_client(client_id);
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
},
|
},
|
||||||
ScreenInstruction::AddOverlay(overlay, _client_id) => {
|
ScreenInstruction::AddOverlay(overlay, _client_id) => {
|
||||||
screen.get_active_overlays_mut().pop();
|
screen.get_active_overlays_mut().pop();
|
||||||
screen.get_active_overlays_mut().push(overlay);
|
screen.get_active_overlays_mut().push(overlay);
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
},
|
},
|
||||||
ScreenInstruction::RemoveOverlay(_client_id) => {
|
ScreenInstruction::RemoveOverlay(_client_id) => {
|
||||||
screen.get_active_overlays_mut().pop();
|
screen.get_active_overlays_mut().pop();
|
||||||
screen.render();
|
screen.render();
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
},
|
},
|
||||||
ScreenInstruction::ConfirmPrompt(_client_id) => {
|
ScreenInstruction::ConfirmPrompt(_client_id) => {
|
||||||
let overlay = screen.get_active_overlays_mut().pop();
|
let overlay = screen.get_active_overlays_mut().pop();
|
||||||
|
|
@ -1497,20 +1269,12 @@ pub(crate) fn screen_thread_main(
|
||||||
if let Some(instruction) = instruction {
|
if let Some(instruction) = instruction {
|
||||||
screen.bus.senders.send_to_server(*instruction).unwrap();
|
screen.bus.senders.send_to_server(*instruction).unwrap();
|
||||||
}
|
}
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
},
|
},
|
||||||
ScreenInstruction::DenyPrompt(_client_id) => {
|
ScreenInstruction::DenyPrompt(_client_id) => {
|
||||||
screen.get_active_overlays_mut().pop();
|
screen.get_active_overlays_mut().pop();
|
||||||
screen.render();
|
screen.render();
|
||||||
screen
|
screen.unblock_input();
|
||||||
.bus
|
|
||||||
.senders
|
|
||||||
.send_to_server(ServerInstruction::UnblockInputThread)
|
|
||||||
.unwrap();
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue