fix(screen): handle various edge cases rather than crashing (#1269)
* fix(screen): handle various edge cases rather than crashing * style(fmt): rustfmt * fix(logging): add error logs when unable to find tab * style(fmt): rustfmt
This commit is contained in:
parent
4ba3a70f9a
commit
bf4f90d694
1 changed files with 309 additions and 241 deletions
|
|
@ -312,60 +312,71 @@ impl Screen {
|
||||||
/// A helper function to switch to a new tab at specified position.
|
/// A helper function to switch to a new tab at specified position.
|
||||||
fn switch_active_tab(&mut self, new_tab_pos: usize, client_id: ClientId) {
|
fn switch_active_tab(&mut self, new_tab_pos: usize, client_id: ClientId) {
|
||||||
if let Some(new_tab) = self.tabs.values().find(|t| t.position == new_tab_pos) {
|
if let Some(new_tab) = self.tabs.values().find(|t| t.position == new_tab_pos) {
|
||||||
let current_tab = self.get_active_tab(client_id).unwrap();
|
if let Some(current_tab) = self.get_active_tab(client_id) {
|
||||||
|
// If new active tab is same as the current one, do nothing.
|
||||||
|
if current_tab.position == new_tab_pos {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If new active tab is same as the current one, do nothing.
|
let current_tab_index = current_tab.index;
|
||||||
if current_tab.position == new_tab_pos {
|
let new_tab_index = new_tab.index;
|
||||||
return;
|
if self.session_is_mirrored {
|
||||||
}
|
self.move_clients_between_tabs(current_tab_index, new_tab_index, None);
|
||||||
|
let all_connected_clients: Vec<ClientId> =
|
||||||
let current_tab_index = current_tab.index;
|
self.connected_clients.borrow().iter().copied().collect();
|
||||||
let new_tab_index = new_tab.index;
|
for client_id in all_connected_clients {
|
||||||
if self.session_is_mirrored {
|
self.update_client_tab_focus(client_id, new_tab_index);
|
||||||
self.move_clients_between_tabs(current_tab_index, new_tab_index, None);
|
}
|
||||||
let all_connected_clients: Vec<ClientId> =
|
} else {
|
||||||
self.connected_clients.borrow().iter().copied().collect();
|
self.move_clients_between_tabs(
|
||||||
for client_id in all_connected_clients {
|
current_tab_index,
|
||||||
|
new_tab_index,
|
||||||
|
Some(vec![client_id]),
|
||||||
|
);
|
||||||
self.update_client_tab_focus(client_id, new_tab_index);
|
self.update_client_tab_focus(client_id, new_tab_index);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
self.move_clients_between_tabs(
|
|
||||||
current_tab_index,
|
|
||||||
new_tab_index,
|
|
||||||
Some(vec![client_id]),
|
|
||||||
);
|
|
||||||
self.update_client_tab_focus(client_id, new_tab_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(current_tab) = self.get_indexed_tab_mut(current_tab_index) {
|
if let Some(current_tab) = self.get_indexed_tab_mut(current_tab_index) {
|
||||||
if current_tab.has_no_connected_clients() {
|
if current_tab.has_no_connected_clients() {
|
||||||
current_tab.visible(false);
|
current_tab.visible(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Tab index: {:?} not found", current_tab_index);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.update_tabs();
|
self.update_tabs();
|
||||||
self.render();
|
self.render();
|
||||||
|
} else {
|
||||||
|
log::error!("Active tab not found for client_id: {:?}", client_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this [`Screen`]'s active [`Tab`] to the next tab.
|
/// Sets this [`Screen`]'s active [`Tab`] to the next tab.
|
||||||
pub fn switch_tab_next(&mut self, client_id: ClientId) {
|
pub fn switch_tab_next(&mut self, client_id: ClientId) {
|
||||||
let active_tab_pos = self.get_active_tab(client_id).unwrap().position;
|
if let Some(active_tab) = self.get_active_tab(client_id) {
|
||||||
let new_tab_pos = (active_tab_pos + 1) % self.tabs.len();
|
let active_tab_pos = active_tab.position;
|
||||||
|
let new_tab_pos = (active_tab_pos + 1) % self.tabs.len();
|
||||||
self.switch_active_tab(new_tab_pos, client_id);
|
self.switch_active_tab(new_tab_pos, client_id);
|
||||||
|
} else {
|
||||||
|
log::error!("Active tab not found for client_id: {:?}", client_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets this [`Screen`]'s active [`Tab`] to the previous tab.
|
/// Sets this [`Screen`]'s active [`Tab`] to the previous tab.
|
||||||
pub fn switch_tab_prev(&mut self, client_id: ClientId) {
|
pub fn switch_tab_prev(&mut self, client_id: ClientId) {
|
||||||
let active_tab_pos = self.get_active_tab(client_id).unwrap().position;
|
if let Some(active_tab) = self.get_active_tab(client_id) {
|
||||||
let new_tab_pos = if active_tab_pos == 0 {
|
let active_tab_pos = active_tab.position;
|
||||||
self.tabs.len() - 1
|
let new_tab_pos = if active_tab_pos == 0 {
|
||||||
} else {
|
self.tabs.len() - 1
|
||||||
active_tab_pos - 1
|
} else {
|
||||||
};
|
active_tab_pos - 1
|
||||||
|
};
|
||||||
|
|
||||||
self.switch_active_tab(new_tab_pos, client_id);
|
self.switch_active_tab(new_tab_pos, client_id);
|
||||||
|
} else {
|
||||||
|
log::error!("Active tab not found for client_id: {:?}", client_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn go_to_tab(&mut self, tab_index: usize, client_id: ClientId) {
|
pub fn go_to_tab(&mut self, tab_index: usize, client_id: ClientId) {
|
||||||
|
|
@ -623,23 +634,26 @@ impl Screen {
|
||||||
|
|
||||||
pub fn update_active_tab_name(&mut self, buf: Vec<u8>, client_id: ClientId) {
|
pub fn update_active_tab_name(&mut self, buf: Vec<u8>, client_id: ClientId) {
|
||||||
let s = str::from_utf8(&buf).unwrap();
|
let s = str::from_utf8(&buf).unwrap();
|
||||||
let active_tab = self.get_active_tab_mut(client_id).unwrap();
|
if let Some(active_tab) = self.get_active_tab_mut(client_id) {
|
||||||
match s {
|
match s {
|
||||||
"\0" => {
|
"\0" => {
|
||||||
active_tab.name = String::new();
|
active_tab.name = String::new();
|
||||||
}
|
}
|
||||||
"\u{007F}" | "\u{0008}" => {
|
"\u{007F}" | "\u{0008}" => {
|
||||||
// delete and backspace keys
|
// delete and backspace keys
|
||||||
active_tab.name.pop();
|
active_tab.name.pop();
|
||||||
}
|
}
|
||||||
c => {
|
c => {
|
||||||
// It only allows printable unicode
|
// It only allows printable unicode
|
||||||
if buf.iter().all(|u| matches!(u, 0x20..=0x7E)) {
|
if buf.iter().all(|u| matches!(u, 0x20..=0x7E)) {
|
||||||
active_tab.name.push_str(c);
|
active_tab.name.push_str(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.update_tabs();
|
||||||
|
} else {
|
||||||
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
}
|
}
|
||||||
self.update_tabs();
|
|
||||||
}
|
}
|
||||||
pub fn change_mode(&mut self, mode_info: ModeInfo, client_id: ClientId) {
|
pub fn change_mode(&mut self, mode_info: ModeInfo, client_id: ClientId) {
|
||||||
let previous_mode = self
|
let previous_mode = self
|
||||||
|
|
@ -650,9 +664,9 @@ impl Screen {
|
||||||
if previous_mode == InputMode::Scroll
|
if previous_mode == InputMode::Scroll
|
||||||
&& (mode_info.mode == InputMode::Normal || mode_info.mode == InputMode::Locked)
|
&& (mode_info.mode == InputMode::Normal || mode_info.mode == InputMode::Locked)
|
||||||
{
|
{
|
||||||
self.get_active_tab_mut(client_id)
|
if let Some(active_tab) = self.get_active_tab_mut(client_id) {
|
||||||
.unwrap()
|
active_tab.clear_active_terminal_scroll(client_id);
|
||||||
.clear_active_terminal_scroll(client_id);
|
}
|
||||||
}
|
}
|
||||||
self.style = mode_info.style;
|
self.style = mode_info.style;
|
||||||
self.mode_info.insert(client_id, mode_info.clone());
|
self.mode_info.insert(client_id, mode_info.clone());
|
||||||
|
|
@ -662,21 +676,22 @@ impl Screen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn move_focus_left_or_previous_tab(&mut self, client_id: ClientId) {
|
pub fn move_focus_left_or_previous_tab(&mut self, client_id: ClientId) {
|
||||||
if !self
|
if let Some(active_tab) = self.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
if !active_tab.move_focus_left(client_id) {
|
||||||
.unwrap()
|
println!("can has true");
|
||||||
.move_focus_left(client_id)
|
self.switch_tab_prev(client_id);
|
||||||
{
|
}
|
||||||
self.switch_tab_prev(client_id);
|
} else {
|
||||||
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn move_focus_right_or_next_tab(&mut self, client_id: ClientId) {
|
pub fn move_focus_right_or_next_tab(&mut self, client_id: ClientId) {
|
||||||
if !self
|
if let Some(active_tab) = self.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
if !active_tab.move_focus_right(client_id) {
|
||||||
.unwrap()
|
self.switch_tab_next(client_id);
|
||||||
.move_focus_right(client_id)
|
}
|
||||||
{
|
} else {
|
||||||
self.switch_tab_next(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn toggle_tab(&mut self, client_id: ClientId) {
|
pub fn toggle_tab(&mut self, client_id: ClientId) {
|
||||||
|
|
@ -742,13 +757,18 @@ 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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.new_pane(pid, Some(client_id));
|
||||||
.unwrap()
|
} else {
|
||||||
.new_pane(pid, Some(client_id));
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ClientOrTabIndex::TabIndex(tab_index) => {
|
ClientOrTabIndex::TabIndex(tab_index) => {
|
||||||
screen.tabs.get_mut(&tab_index).unwrap().new_pane(pid, None);
|
if let Some(active_tab) = screen.tabs.get_mut(&tab_index) {
|
||||||
|
active_tab.new_pane(pid, None);
|
||||||
|
} else {
|
||||||
|
log::error!("Tab index not found: {:?}", tab_index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
screen
|
screen
|
||||||
|
|
@ -761,10 +781,11 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::TogglePaneEmbedOrFloating(client_id) => {
|
ScreenInstruction::TogglePaneEmbedOrFloating(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.toggle_pane_embed_or_floating(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.toggle_pane_embed_or_floating(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
screen
|
screen
|
||||||
.bus
|
.bus
|
||||||
.senders
|
.senders
|
||||||
|
|
@ -774,10 +795,11 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ToggleFloatingPanes(client_id, default_shell) => {
|
ScreenInstruction::ToggleFloatingPanes(client_id, default_shell) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.toggle_floating_panes(client_id, default_shell);
|
||||||
.unwrap()
|
} else {
|
||||||
.toggle_floating_panes(client_id, default_shell);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
screen
|
screen
|
||||||
.bus
|
.bus
|
||||||
.senders
|
.senders
|
||||||
|
|
@ -787,10 +809,11 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::HorizontalSplit(pid, client_id) => {
|
ScreenInstruction::HorizontalSplit(pid, client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.horizontal_split(pid, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.horizontal_split(pid, client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
screen
|
screen
|
||||||
.bus
|
.bus
|
||||||
.senders
|
.senders
|
||||||
|
|
@ -801,10 +824,11 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::VerticalSplit(pid, client_id) => {
|
ScreenInstruction::VerticalSplit(pid, client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.vertical_split(pid, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.vertical_split(pid, client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
screen
|
screen
|
||||||
.bus
|
.bus
|
||||||
.senders
|
.senders
|
||||||
|
|
@ -815,89 +839,100 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::WriteCharacter(bytes, client_id) => {
|
ScreenInstruction::WriteCharacter(bytes, client_id) => {
|
||||||
let active_tab = screen.get_active_tab_mut(client_id).unwrap();
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
match active_tab.is_sync_panes_active() {
|
match active_tab.is_sync_panes_active() {
|
||||||
true => active_tab.write_to_terminals_on_current_tab(bytes),
|
true => active_tab.write_to_terminals_on_current_tab(bytes),
|
||||||
false => active_tab.write_to_active_terminal(bytes, client_id),
|
false => active_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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.resize_left(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.resize_left(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ResizeRight(client_id) => {
|
ScreenInstruction::ResizeRight(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.resize_right(client_id);
|
||||||
.unwrap()
|
}
|
||||||
.resize_right(client_id);
|
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ResizeDown(client_id) => {
|
ScreenInstruction::ResizeDown(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.resize_down(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.resize_down(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ResizeUp(client_id) => {
|
ScreenInstruction::ResizeUp(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.resize_up(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.resize_up(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ResizeIncrease(client_id) => {
|
ScreenInstruction::ResizeIncrease(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.resize_increase(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.resize_increase(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ResizeDecrease(client_id) => {
|
ScreenInstruction::ResizeDecrease(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.resize_decrease(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.resize_decrease(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::SwitchFocus(client_id) => {
|
ScreenInstruction::SwitchFocus(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.focus_next_pane(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.focus_next_pane(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::FocusNextPane(client_id) => {
|
ScreenInstruction::FocusNextPane(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.focus_next_pane(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.focus_next_pane(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::FocusPreviousPane(client_id) => {
|
ScreenInstruction::FocusPreviousPane(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.focus_previous_pane(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.focus_previous_pane(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MoveFocusLeft(client_id) => {
|
ScreenInstruction::MoveFocusLeft(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_focus_left(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_focus_left(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
|
|
@ -912,18 +947,20 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MoveFocusDown(client_id) => {
|
ScreenInstruction::MoveFocusDown(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_focus_down(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_focus_down(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MoveFocusRight(client_id) => {
|
ScreenInstruction::MoveFocusRight(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_focus_right(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_focus_right(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
|
|
@ -938,138 +975,155 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MoveFocusUp(client_id) => {
|
ScreenInstruction::MoveFocusUp(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_focus_up(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_focus_up(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ScrollUp(client_id) => {
|
ScreenInstruction::ScrollUp(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_up(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_up(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MovePane(client_id) => {
|
ScreenInstruction::MovePane(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_active_pane(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_active_pane(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MovePaneDown(client_id) => {
|
ScreenInstruction::MovePaneDown(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_active_pane_down(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_active_pane_down(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MovePaneUp(client_id) => {
|
ScreenInstruction::MovePaneUp(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_active_pane_up(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_active_pane_up(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MovePaneRight(client_id) => {
|
ScreenInstruction::MovePaneRight(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_active_pane_right(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_active_pane_right(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::MovePaneLeft(client_id) => {
|
ScreenInstruction::MovePaneLeft(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.move_active_pane_left(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.move_active_pane_left(client_id);
|
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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_terminal_up(&point, 3, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_terminal_up(&point, 3, client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ScrollDown(client_id) => {
|
ScreenInstruction::ScrollDown(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_down(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_down(client_id);
|
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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_terminal_down(&point, 3, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_terminal_down(&point, 3, client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ScrollToBottom(client_id) => {
|
ScreenInstruction::ScrollToBottom(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_to_bottom(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_to_bottom(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::PageScrollUp(client_id) => {
|
ScreenInstruction::PageScrollUp(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_up_page(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_up_page(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::PageScrollDown(client_id) => {
|
ScreenInstruction::PageScrollDown(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_down_page(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_down_page(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::HalfPageScrollUp(client_id) => {
|
ScreenInstruction::HalfPageScrollUp(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_up_half_page(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_up_half_page(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::HalfPageScrollDown(client_id) => {
|
ScreenInstruction::HalfPageScrollDown(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.scroll_active_terminal_down_half_page(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.scroll_active_terminal_down_half_page(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ClearScroll(client_id) => {
|
ScreenInstruction::ClearScroll(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.clear_active_terminal_scroll(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.clear_active_terminal_scroll(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::CloseFocusedPane(client_id) => {
|
ScreenInstruction::CloseFocusedPane(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.close_focused_pane(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.close_focused_pane(client_id);
|
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) => {
|
||||||
|
|
@ -1089,7 +1143,13 @@ 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.get_active_tab_mut(client_id).unwrap().close_pane(id);
|
screen
|
||||||
|
.get_active_tab_mut(client_id)
|
||||||
|
.and_then(|active_tab| active_tab.close_pane(id))
|
||||||
|
.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() {
|
||||||
|
|
@ -1103,18 +1163,20 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
}
|
}
|
||||||
ScreenInstruction::UpdatePaneName(c, client_id) => {
|
ScreenInstruction::UpdatePaneName(c, client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.update_active_pane_name(c, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.update_active_pane_name(c, client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ToggleActiveTerminalFullscreen(client_id) => {
|
ScreenInstruction::ToggleActiveTerminalFullscreen(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.toggle_active_pane_fullscreen(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.toggle_active_pane_fullscreen(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
screen.update_tabs();
|
screen.update_tabs();
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
|
|
@ -1196,53 +1258,59 @@ pub(crate) fn screen_thread_main(
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::ToggleActiveSyncTab(client_id) => {
|
ScreenInstruction::ToggleActiveSyncTab(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.toggle_sync_panes_is_active();
|
||||||
.unwrap()
|
} else {
|
||||||
.toggle_sync_panes_is_active();
|
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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.handle_left_click(&point, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.handle_left_click(&point, client_id);
|
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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.handle_right_click(&point, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.handle_right_click(&point, client_id);
|
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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.handle_mouse_release(&point, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.handle_mouse_release(&point, client_id);
|
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) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab_mut(client_id) {
|
||||||
.get_active_tab_mut(client_id)
|
active_tab.handle_mouse_hold(&point, client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.handle_mouse_hold(&point, client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
ScreenInstruction::Copy(client_id) => {
|
ScreenInstruction::Copy(client_id) => {
|
||||||
screen
|
if let Some(active_tab) = screen.get_active_tab(client_id) {
|
||||||
.get_active_tab(client_id)
|
active_tab.copy_selection(client_id);
|
||||||
.unwrap()
|
} else {
|
||||||
.copy_selection(client_id);
|
log::error!("Active tab not found for client id: {:?}", client_id);
|
||||||
|
}
|
||||||
|
|
||||||
screen.render();
|
screen.render();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue