Skip to content

Commit

Permalink
style(fmt): rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
imsnif committed Sep 16, 2024
1 parent 7a3b14d commit c543413
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 85 deletions.
12 changes: 10 additions & 2 deletions default-plugins/fixture-plugin-for-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,19 @@ impl ZellijPlugin for State {
},
BareKey::Char('u') if key.has_modifiers(&[KeyModifier::Alt]) => {
let should_change_focus_to_new_tab = true;
break_panes_to_new_tab(&[PaneId::Terminal(1), PaneId::Plugin(2)], Some("new_tab_name".to_owned()), should_change_focus_to_new_tab);
break_panes_to_new_tab(
&[PaneId::Terminal(1), PaneId::Plugin(2)],
Some("new_tab_name".to_owned()),
should_change_focus_to_new_tab,
);
},
BareKey::Char('v') if key.has_modifiers(&[KeyModifier::Alt]) => {
let should_change_focus_to_target_tab = true;
break_panes_to_tab_with_index(&[PaneId::Terminal(1), PaneId::Plugin(2)], 2, should_change_focus_to_target_tab);
break_panes_to_tab_with_index(
&[PaneId::Terminal(1), PaneId::Plugin(2)],
2,
should_change_focus_to_target_tab,
);
},
_ => {},
},
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum PluginInstruction {
Option<TiledPaneLayout>,
Vec<FloatingPaneLayout>,
usize, // tab_index
bool, // should change focus to new tab
bool, // should change focus to new tab
ClientId,
),
ApplyCachedEvents {
Expand Down
6 changes: 3 additions & 3 deletions zellij-server/src/plugins/unit/plugin_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ macro_rules! grant_permissions_and_log_actions_in_thread_struct_variant {
.recv()
.expect("failed to receive event on channel");
match event {
$exit_event { .. }=> {
$exit_event { .. } => {
exit_event_count += 1;
log.lock().unwrap().push(event);
if exit_event_count == $exit_after_count {
Expand Down Expand Up @@ -8236,7 +8236,7 @@ pub fn break_panes_to_new_tab_plugin_command() {
.unwrap()
.iter()
.find_map(|i| {
if let ScreenInstruction::BreakPanesToNewTab{..} = i {
if let ScreenInstruction::BreakPanesToNewTab { .. } = i {
Some(i.clone())
} else {
None
Expand Down Expand Up @@ -8307,7 +8307,7 @@ pub fn break_panes_to_tab_with_index_plugin_command() {
.unwrap()
.iter()
.find_map(|i| {
if let ScreenInstruction::BreakPanesToTabWithIndex{..} = i {
if let ScreenInstruction::BreakPanesToTabWithIndex { .. } = i {
Some(i.clone())
} else {
None
Expand Down
55 changes: 45 additions & 10 deletions zellij-server/src/plugins/zellij_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,26 @@ fn host_run_plugin_command(caller: Caller<'_, PluginEnv>) {
PluginCommand::CloseTabWithIndex(tab_index) => {
close_tab_with_index(env, tab_index)
},
PluginCommand::BreakPanesToNewTab(pane_ids, new_tab_name, should_change_focus_to_new_tab) => {
break_panes_to_new_tab(env, pane_ids.into_iter().map(|p_id| p_id.into()).collect(), new_tab_name, should_change_focus_to_new_tab)
},
PluginCommand::BreakPanesToTabWithIndex(pane_ids, should_change_focus_to_new_tab, tab_index) => {
break_panes_to_tab_with_index(env, pane_ids.into_iter().map(|p_id| p_id.into()).collect(), tab_index, should_change_focus_to_new_tab)
},
PluginCommand::BreakPanesToNewTab(
pane_ids,
new_tab_name,
should_change_focus_to_new_tab,
) => break_panes_to_new_tab(
env,
pane_ids.into_iter().map(|p_id| p_id.into()).collect(),
new_tab_name,
should_change_focus_to_new_tab,
),
PluginCommand::BreakPanesToTabWithIndex(
pane_ids,
should_change_focus_to_new_tab,
tab_index,
) => break_panes_to_tab_with_index(
env,
pane_ids.into_iter().map(|p_id| p_id.into()).collect(),
tab_index,
should_change_focus_to_new_tab,
),
},
(PermissionStatus::Denied, permission) => {
log::error!(
Expand Down Expand Up @@ -1595,7 +1609,12 @@ fn close_tab_with_index(env: &PluginEnv, tab_index: usize) {
.send_to_screen(ScreenInstruction::CloseTabWithIndex(tab_index));
}

fn break_panes_to_new_tab(env: &PluginEnv, pane_ids: Vec<PaneId>, new_tab_name: Option<String>, should_change_focus_to_new_tab: bool) {
fn break_panes_to_new_tab(
env: &PluginEnv,
pane_ids: Vec<PaneId>,
new_tab_name: Option<String>,
should_change_focus_to_new_tab: bool,
) {
let default_shell = env.default_shell.clone().or_else(|| {
Some(TerminalAction::RunCommand(RunCommand {
command: env.path_to_default_shell.clone(),
Expand All @@ -1604,13 +1623,29 @@ fn break_panes_to_new_tab(env: &PluginEnv, pane_ids: Vec<PaneId>, new_tab_name:
});
let _ = env
.senders
.send_to_screen(ScreenInstruction::BreakPanesToNewTab{pane_ids, default_shell, new_tab_name, should_change_focus_to_new_tab, client_id: env.client_id});
.send_to_screen(ScreenInstruction::BreakPanesToNewTab {
pane_ids,
default_shell,
new_tab_name,
should_change_focus_to_new_tab,
client_id: env.client_id,
});
}

fn break_panes_to_tab_with_index(env: &PluginEnv, pane_ids: Vec<PaneId>, should_change_focus_to_new_tab: bool, tab_index: usize) {
fn break_panes_to_tab_with_index(
env: &PluginEnv,
pane_ids: Vec<PaneId>,
should_change_focus_to_new_tab: bool,
tab_index: usize,
) {
let _ = env
.senders
.send_to_screen(ScreenInstruction::BreakPanesToTabWithIndex{pane_ids, tab_index, client_id: env.client_id, should_change_focus_to_new_tab});
.send_to_screen(ScreenInstruction::BreakPanesToTabWithIndex {
pane_ids,
tab_index,
client_id: env.client_id,
should_change_focus_to_new_tab,
});
}

// Custom panic handler for plugins.
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum PtyInstruction {
Vec<FloatingPaneLayout>,
usize, // tab_index
HashMap<RunPluginOrAlias, Vec<u32>>, // plugin_ids
bool, // should change focus to new tab
bool, // should change focus to new tab
ClientId,
), // the String is the tab name
ClosePane(PaneId),
Expand Down
112 changes: 75 additions & 37 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub enum ScreenInstruction {
Vec<(u32, HoldForCommand)>, // new floating pane pids
HashMap<RunPluginOrAlias, Vec<u32>>,
usize, // tab_index
bool, // should change focus to new tab
bool, // should change focus to new tab
ClientId,
),
SwitchTabNext(ClientId),
Expand Down Expand Up @@ -396,12 +396,12 @@ pub enum ScreenInstruction {
TogglePaneIdFullscreen(PaneId),
TogglePaneEmbedOrEjectForPaneId(PaneId),
CloseTabWithIndex(usize),
BreakPanesToNewTab{
pane_ids: Vec<PaneId>,
BreakPanesToNewTab {
pane_ids: Vec<PaneId>,
default_shell: Option<TerminalAction>,
should_change_focus_to_new_tab: bool,
new_tab_name: Option<String>,
client_id: ClientId
client_id: ClientId,
},
BreakPanesToTabWithIndex {
pane_ids: Vec<PaneId>,
Expand Down Expand Up @@ -616,8 +616,10 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenContext::TogglePaneEmbedOrEjectForPaneId
},
ScreenInstruction::CloseTabWithIndex(..) => ScreenContext::CloseTabWithIndex,
ScreenInstruction::BreakPanesToNewTab{..} => ScreenContext::BreakPanesToNewTab,
ScreenInstruction::BreakPanesToTabWithIndex{..} => ScreenContext::BreakPanesToTabWithIndex,
ScreenInstruction::BreakPanesToNewTab { .. } => ScreenContext::BreakPanesToNewTab,
ScreenInstruction::BreakPanesToTabWithIndex { .. } => {
ScreenContext::BreakPanesToTabWithIndex
},
}
}
}
Expand Down Expand Up @@ -1186,7 +1188,9 @@ impl Screen {
}
for tab_index in tabs_to_close {
// cleanup as needed
self.close_tab_at_index(tab_index).context(err_context).non_fatal();
self.close_tab_at_index(tab_index)
.context(err_context)
.non_fatal();
}
if output.is_dirty() {
let serialized_output = output.serialize().context(err_context)?;
Expand Down Expand Up @@ -1275,12 +1279,14 @@ impl Screen {
) -> Result<()> {
let err_context = || format!("failed to create new tab for client {client_id:?}",);

let client_id = client_id.map(|client_id| if self.get_active_tab(client_id).is_ok() {
client_id
} else if let Some(first_client_id) = self.get_first_client_id() {
first_client_id
} else {
client_id
let client_id = client_id.map(|client_id| {
if self.get_active_tab(client_id).is_ok() {
client_id
} else if let Some(first_client_id) = self.get_first_client_id() {
first_client_id
} else {
client_id
}
});

let tab_name = tab_name.unwrap_or_else(|| String::new());
Expand Down Expand Up @@ -1352,16 +1358,20 @@ impl Screen {
// move the relevant clients out of the current tab and place them in the new one
let drained_clients = if should_change_client_focus {
if self.session_is_mirrored {
let client_mode_infos_in_source_tab =
if let Ok(active_tab) = self.get_active_tab_mut(client_id) {
let client_mode_infos_in_source_tab = active_tab.drain_connected_clients(None);
if active_tab.has_no_connected_clients() {
active_tab.visible(false).with_context(err_context).non_fatal();
}
Some(client_mode_infos_in_source_tab)
} else {
None
};
let client_mode_infos_in_source_tab = if let Ok(active_tab) =
self.get_active_tab_mut(client_id)
{
let client_mode_infos_in_source_tab = active_tab.drain_connected_clients(None);
if active_tab.has_no_connected_clients() {
active_tab
.visible(false)
.with_context(err_context)
.non_fatal();
}
Some(client_mode_infos_in_source_tab)
} else {
None
};
let all_connected_clients: Vec<ClientId> =
self.connected_clients.borrow().iter().copied().collect();
for client_id in all_connected_clients {
Expand All @@ -1372,7 +1382,10 @@ impl Screen {
let client_mode_info_in_source_tab =
active_tab.drain_connected_clients(Some(vec![client_id]));
if active_tab.has_no_connected_clients() {
active_tab.visible(false).with_context(err_context).non_fatal();
active_tab
.visible(false)
.with_context(err_context)
.non_fatal();
}
self.update_client_tab_focus(client_id, tab_index);
Some(client_mode_info_in_source_tab)
Expand All @@ -1388,7 +1401,6 @@ impl Screen {
.get_mut(&tab_index)
.context("couldn't find tab with index {tab_index}")
.and_then(|tab| {

tab.apply_layout(
layout,
floating_panes_layout,
Expand All @@ -1403,8 +1415,7 @@ impl Screen {
tab.visible(true)?;
tab.add_multiple_clients(drained_clients)?;
}
tab.resize_whole_tab(self.size)
.with_context(err_context)?;
tab.resize_whole_tab(self.size).with_context(err_context)?;
tab.set_force_render();
Ok(())
})
Expand Down Expand Up @@ -2174,10 +2185,7 @@ impl Screen {
}
}

let (
mut tiled_panes_layout,
floating_panes_layout
) = self.default_layout.new_tab();
let (mut tiled_panes_layout, floating_panes_layout) = self.default_layout.new_tab();
let tab_index = self.get_new_tab_index();
let swap_layouts = (
self.default_layout.swap_tiled_layouts.clone(),
Expand Down Expand Up @@ -2281,7 +2289,10 @@ impl Screen {
client_id: ClientId,
) -> Result<()> {
let all_tabs = self.get_tabs_mut();
let has_tab_with_index = all_tabs.values().find(|t| t.position == tab_index).is_some();
let has_tab_with_index = all_tabs
.values()
.find(|t| t.position == tab_index)
.is_some();
if !has_tab_with_index {
log::error!("Cannot find tab with index: {tab_index}");
return Ok(());
Expand Down Expand Up @@ -3505,7 +3516,12 @@ pub(crate) fn screen_thread_main(
if create && !tab_exists {
let tab_index = screen.get_new_tab_index();
let should_change_focus_to_new_tab = true;
screen.new_tab(tab_index, swap_layouts, Some(tab_name), Some(client_id))?;
screen.new_tab(
tab_index,
swap_layouts,
Some(tab_name),
Some(client_id),
)?;
screen
.bus
.senders
Expand Down Expand Up @@ -4570,11 +4586,33 @@ pub(crate) fn screen_thread_main(
ScreenInstruction::CloseTabWithIndex(tab_index) => {
screen.close_tab_at_index(tab_index).non_fatal()
},
ScreenInstruction::BreakPanesToNewTab{pane_ids, default_shell, should_change_focus_to_new_tab, new_tab_name, client_id} => {
screen.break_multiple_panes_to_new_tab(pane_ids, default_shell, should_change_focus_to_new_tab, new_tab_name, client_id)?;
ScreenInstruction::BreakPanesToNewTab {
pane_ids,
default_shell,
should_change_focus_to_new_tab,
new_tab_name,
client_id,
} => {
screen.break_multiple_panes_to_new_tab(
pane_ids,
default_shell,
should_change_focus_to_new_tab,
new_tab_name,
client_id,
)?;
},
ScreenInstruction::BreakPanesToTabWithIndex{pane_ids, tab_index, should_change_focus_to_new_tab, client_id} => {
screen.break_multiple_panes_to_tab_with_index(pane_ids, tab_index, should_change_focus_to_new_tab, client_id)?;
ScreenInstruction::BreakPanesToTabWithIndex {
pane_ids,
tab_index,
should_change_focus_to_new_tab,
client_id,
} => {
screen.break_multiple_panes_to_tab_with_index(
pane_ids,
tab_index,
should_change_focus_to_new_tab,
client_id,
)?;
},
}
}
Expand Down
9 changes: 6 additions & 3 deletions zellij-server/src/tab/layout_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@ impl<'a> LayoutApplier<'a> {
position_and_size,
layout.borderless,
);
} else if let Some(position) = positions_in_layout
.iter()
.position(|(layout, _position_and_size)| Run::is_terminal(&layout.run) && Run::is_terminal(&run_instruction))
} else if let Some(position) =
positions_in_layout
.iter()
.position(|(layout, _position_and_size)| {
Run::is_terminal(&layout.run) && Run::is_terminal(&run_instruction)
})
{
let (layout, position_and_size) = positions_in_layout.remove(position);
self.tiled_panes.set_geom_for_pane_with_run(
Expand Down
Loading

0 comments on commit c543413

Please sign in to comment.