Skip to content

Commit

Permalink
style(fmt): various cleanups (zellij-org#3698)
Browse files Browse the repository at this point in the history
* fix(configuration): rounding error in ui

* style(fmt): remove warnings

* style(fmt): rustfmt
  • Loading branch information
imsnif authored and Tomcat-42 committed Nov 9, 2024
1 parent 3148209 commit 96024c7
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 88 deletions.
6 changes: 3 additions & 3 deletions default-plugins/configuration/src/rebind_leaders_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl RebindLeadersScreen {
WIDTH_BREAKPOINTS.1
};
let base_x = cols.saturating_sub(screen_width) / 2;
let base_y = rows.saturating_sub(7) / 2;
let base_y = rows.saturating_sub(10) / 2;
let primary_modifier_key_text = self.primary_modifier_text();
let (primary_modifier_text, primary_modifier_start_position) =
if cols >= WIDTH_BREAKPOINTS.0 {
Expand All @@ -305,7 +305,7 @@ impl RebindLeadersScreen {
print_text_with_coordinates(
Text::new(primary_modifier_text).color_range(3, primary_modifier_start_position..),
base_x,
base_y + 4,
base_y + 5,
None,
None,
);
Expand All @@ -327,7 +327,7 @@ impl RebindLeadersScreen {
})
.collect(),
base_x,
base_y + 5,
base_y + 6,
Some(screen_width / 2),
None,
);
Expand Down
4 changes: 2 additions & 2 deletions zellij-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use zellij_utils::{
config::Config,
get_mode_info,
keybinds::Keybinds,
layout::{FloatingPaneLayout, Layout, PercentOrFixed, PluginAlias, Run, RunPluginOrAlias},
layout::{FloatingPaneLayout, Layout, PluginAlias, Run, RunPluginOrAlias},
options::Options,
plugins::PluginAliases,
},
Expand Down Expand Up @@ -1169,7 +1169,7 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
.unwrap()
.propagate_configuration_changes(changes);
},
ServerInstruction::FailedToWriteConfigToDisk(client_id, file_path) => {
ServerInstruction::FailedToWriteConfigToDisk(_client_id, file_path) => {
session_data
.write()
.unwrap()
Expand Down
5 changes: 2 additions & 3 deletions zellij-server/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::{
};
use wasmtime::Engine;

use crate::background_jobs::BackgroundJob;
use crate::panes::PaneId;
use crate::screen::ScreenInstruction;
use crate::session_layout_metadata::SessionLayoutMetadata;
Expand All @@ -34,7 +33,7 @@ use zellij_utils::{
command::TerminalAction,
keybinds::Keybinds,
layout::{FloatingPaneLayout, Layout, Run, RunPlugin, RunPluginOrAlias, TiledPaneLayout},
plugins::{PluginAliases, PluginConfig},
plugins::PluginAliases,
},
ipc::ClientAttributes,
pane_size::Size,
Expand Down Expand Up @@ -254,7 +253,7 @@ pub(crate) fn plugin_thread_main(
default_keybinds,
);

for mut run_plugin_or_alias in background_plugins {
for run_plugin_or_alias in background_plugins {
load_background_plugin(
run_plugin_or_alias,
&mut wasm_bridge,
Expand Down
24 changes: 2 additions & 22 deletions zellij-server/src/plugins/plugin_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ impl<'a> PluginLoader<'a> {
default_shell: Option<TerminalAction>,
default_layout: Box<Layout>,
layout_dir: Option<PathBuf>,
base_modes: &HashMap<ClientId, InputMode>,
keybinds: &HashMap<ClientId, Keybinds>,
) -> Result<()> {
let err_context = || format!("failed to reload plugin {plugin_id} from memory");
let mut connected_clients: Vec<ClientId> =
Expand All @@ -100,11 +98,6 @@ impl<'a> PluginLoader<'a> {
return Err(anyhow!("No connected clients, cannot reload plugin"));
}
let first_client_id = connected_clients.remove(0);
let keybinds = keybinds.get(&first_client_id).cloned().unwrap_or_default();
let default_mode = base_modes
.get(&first_client_id)
.cloned()
.unwrap_or_default();

let mut plugin_loader = PluginLoader::new_from_existing_plugin_attributes(
&plugin_cache,
Expand All @@ -122,8 +115,6 @@ impl<'a> PluginLoader<'a> {
default_shell,
default_layout,
layout_dir,
default_mode,
keybinds,
)?;
plugin_loader
.load_module_from_memory()
Expand Down Expand Up @@ -290,8 +281,6 @@ impl<'a> PluginLoader<'a> {
default_shell: Option<TerminalAction>,
default_layout: Box<Layout>,
layout_dir: Option<PathBuf>,
base_modes: &HashMap<ClientId, InputMode>,
keybinds: &HashMap<ClientId, Keybinds>,
) -> Result<()> {
let err_context = || format!("failed to reload plugin id {plugin_id}");

Expand All @@ -301,11 +290,6 @@ impl<'a> PluginLoader<'a> {
return Err(anyhow!("No connected clients, cannot reload plugin"));
}
let first_client_id = connected_clients.remove(0);
let keybinds = keybinds.get(&first_client_id).cloned().unwrap_or_default();
let default_mode = base_modes
.get(&first_client_id)
.cloned()
.unwrap_or_default();

let mut plugin_loader = PluginLoader::new_from_existing_plugin_attributes(
&plugin_cache,
Expand All @@ -323,8 +307,6 @@ impl<'a> PluginLoader<'a> {
default_shell,
default_layout,
layout_dir,
default_mode,
keybinds,
)?;
plugin_loader
.compile_module()
Expand Down Expand Up @@ -406,8 +388,6 @@ impl<'a> PluginLoader<'a> {
default_shell: Option<TerminalAction>,
default_layout: Box<Layout>,
layout_dir: Option<PathBuf>,
default_mode: InputMode,
keybinds: Keybinds,
) -> Result<Self> {
let err_context = || "Failed to find existing plugin";
let (running_plugin, _subscriptions, _workers) = {
Expand Down Expand Up @@ -833,11 +813,11 @@ impl<'a> PluginLoader<'a> {
self.plugin_id,
)))));
let wasi_ctx = wasi_ctx_builder.build_p1();
let mut mut_plugin = self.plugin.clone();
let plugin = self.plugin.clone();
let plugin_env = PluginEnv {
plugin_id: self.plugin_id,
client_id: self.client_id,
plugin: mut_plugin,
plugin,
permissions: Arc::new(Mutex::new(None)),
senders: self.senders.clone(),
wasi_ctx,
Expand Down
10 changes: 0 additions & 10 deletions zellij-server/src/plugins/wasm_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ impl WasmBridge {
let default_shell = self.default_shell.clone();
let default_layout = self.default_layout.clone();
let layout_dir = self.layout_dir.clone();
let base_modes = self.base_modes.clone();
let keybinds = self.keybinds.clone();
async move {
match PluginLoader::reload_plugin(
plugin_id,
Expand All @@ -388,8 +386,6 @@ impl WasmBridge {
default_shell.clone(),
default_layout.clone(),
layout_dir.clone(),
&base_modes,
&keybinds,
) {
Ok(_) => {
let plugin_list = plugin_map.lock().unwrap().list_plugins();
Expand Down Expand Up @@ -449,8 +445,6 @@ impl WasmBridge {
let default_shell = self.default_shell.clone();
let default_layout = self.default_layout.clone();
let layout_dir = self.layout_dir.clone();
let base_modes = self.base_modes.clone();
let keybinds = self.keybinds.clone();
async move {
match PluginLoader::reload_plugin(
first_plugin_id,
Expand All @@ -468,8 +462,6 @@ impl WasmBridge {
default_shell.clone(),
default_layout.clone(),
layout_dir.clone(),
&base_modes,
&keybinds,
) {
Ok(_) => {
let plugin_list = plugin_map.lock().unwrap().list_plugins();
Expand All @@ -496,8 +488,6 @@ impl WasmBridge {
default_shell.clone(),
default_layout.clone(),
layout_dir.clone(),
&base_modes,
&keybinds,
) {
Ok(_) => {
let plugin_list = plugin_map.lock().unwrap().list_plugins();
Expand Down
3 changes: 1 addition & 2 deletions zellij-server/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
},
PtyInstruction::Reconfigure {
default_editor,
client_id,
client_id: _,
} => {
pty.reconfigure(default_editor);
},
Expand Down Expand Up @@ -931,7 +931,6 @@ impl Pty {
None,
open_file_payload.originating_plugin.clone(),
),
_ => (false, false, None, None),
};

if hold_on_start {
Expand Down
9 changes: 5 additions & 4 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ impl Screen {
let mut found = false;
for tab in self.tabs.values_mut() {
if tab.has_pane_with_pid(&pane_id) {
tab.resize_pane_with_id(resize, pane_id);
tab.resize_pane_with_id(resize, pane_id).non_fatal();
found = true;
break;
}
Expand Down Expand Up @@ -2232,7 +2232,7 @@ impl Screen {
} else {
self.new_tab(tab_index, swap_layouts, None, None)?;
}
let mut tab = self.tabs.get_mut(&tab_index).with_context(err_context)?;
let tab = self.tabs.get_mut(&tab_index).with_context(err_context)?;
if let Some(new_tab_name) = new_tab_name {
tab.name = new_tab_name.clone();
}
Expand Down Expand Up @@ -2828,15 +2828,16 @@ pub(crate) fn screen_thread_main(
screen.unblock_input()?;
screen.log_and_report_session_state()?;
},
ClientTabIndexOrPaneId::TabIndex(tab_index) => {
ClientTabIndexOrPaneId::TabIndex(_tab_index) => {
log::error!("Cannot OpenInPlaceEditor with a TabIndex");
},
ClientTabIndexOrPaneId::PaneId(pane_id_to_replace) => {
let mut found = false;
let all_tabs = screen.get_tabs_mut();
for tab in all_tabs.values_mut() {
if tab.has_pane_with_pid(&pane_id_to_replace) {
tab.replace_pane_with_editor_pane(pid, pane_id_to_replace);
tab.replace_pane_with_editor_pane(pid, pane_id_to_replace)
.non_fatal();
found = true;
break;
}
Expand Down
3 changes: 0 additions & 3 deletions zellij-server/src/tab/layout_applier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ impl<'a> LayoutApplier<'a> {
client_id: ClientId,
) -> Result<bool> {
// true => should_show_floating_panes
let layout_name = layout.name.clone();
let hide_floating_panes = layout.hide_floating_panes;
self.apply_tiled_panes_layout(layout, new_terminal_ids, &mut new_plugin_ids, client_id)?;
let layout_has_floating_panes = self.apply_floating_panes_layout(
floating_panes_layout,
new_floating_terminal_ids,
&mut new_plugin_ids,
layout_name,
)?;
let should_show_floating_panes = layout_has_floating_panes && !hide_floating_panes;
return Ok(should_show_floating_panes);
Expand Down Expand Up @@ -379,7 +377,6 @@ impl<'a> LayoutApplier<'a> {
floating_panes_layout: Vec<FloatingPaneLayout>,
new_floating_terminal_ids: Vec<(u32, HoldForCommand)>,
new_plugin_ids: &mut HashMap<RunPluginOrAlias, Vec<u32>>,
layout_name: Option<String>,
) -> Result<bool> {
// true => has floating panes
let err_context = || format!("Failed to apply_floating_panes_layout");
Expand Down
32 changes: 4 additions & 28 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,8 @@ impl Tab {
self.os_api,
self.senders,
self.character_cell_size
);
)
.non_fatal();
self.insert_scrollback_editor_replaced_pane(replaced_pane, pid);
},
None => {
Expand Down Expand Up @@ -3089,17 +3090,6 @@ impl Tab {
}
}

pub fn scroll_terminal_half_page_up(&mut self, terminal_pane_id: u32) {
if let Some(terminal_pane) = self.get_pane_with_id_mut(PaneId::Terminal(terminal_pane_id)) {
let fictitious_client_id = 1; // this is not checked for terminal panes and we
// don't have an actual client id here
// TODO: traits were a mistake
// prevent overflow when row == 0
let scroll_rows = (terminal_pane.rows().max(1).saturating_sub(1)) / 2;
terminal_pane.scroll_down(scroll_rows, fictitious_client_id);
}
}

pub fn scroll_active_terminal_down_half_page(&mut self, client_id: ClientId) -> Result<()> {
let err_context =
|| format!("failed to scroll down half a page in active pane for client {client_id}");
Expand All @@ -3117,21 +3107,6 @@ impl Tab {
Ok(())
}

pub fn scroll_terminal_half_page_down(&mut self, terminal_pane_id: u32) {
if let Some(terminal_pane) = self.get_pane_with_id_mut(PaneId::Terminal(terminal_pane_id)) {
let fictitious_client_id = 1; // this is not checked for terminal panes and we
// don't have an actual client id here
// TODO: traits were a mistake
let scroll_rows = (terminal_pane.rows().max(1) - 1) / 2;
terminal_pane.scroll_down(scroll_rows, fictitious_client_id);
if !terminal_pane.is_scrolled() {
if let PaneId::Terminal(raw_fd) = terminal_pane.pid() {
self.process_pending_vte_events(raw_fd).non_fatal();
}
}
}
}

pub fn scroll_active_terminal_to_bottom(&mut self, client_id: ClientId) -> Result<()> {
let err_context =
|| format!("failed to scroll to bottom in active pane for client {client_id}");
Expand Down Expand Up @@ -4122,7 +4097,8 @@ impl Tab {
match self.suppressed_panes.remove(&pane_id) {
Some(pane) => {
self.show_floating_panes();
self.add_floating_pane(pane.1, pane_id, None, None);
self.add_floating_pane(pane.1, pane_id, None, None)
.non_fatal();
self.floating_panes.focus_pane_for_all_clients(pane_id);
},
None => {
Expand Down
7 changes: 3 additions & 4 deletions zellij-utils/src/input/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use thiserror::Error;
use std::convert::TryFrom;

use super::keybinds::Keybinds;
use super::layout::{RunPlugin, RunPluginOrAlias};
use super::layout::RunPluginOrAlias;
use super::options::Options;
use super::plugins::{PluginAliases, PluginsConfigError};
use super::theme::{Themes, UiConfig};
Expand Down Expand Up @@ -402,10 +402,9 @@ impl Config {
#[cfg(test)]
mod config_test {
use super::*;
use crate::data::{InputMode, Palette, PaletteColor, PluginTag};
use crate::input::layout::{RunPlugin, RunPluginLocation};
use crate::data::{InputMode, Palette, PaletteColor};
use crate::input::layout::RunPlugin;
use crate::input::options::{Clipboard, OnForceClose};
use crate::input::plugins::PluginConfig;
use crate::input::theme::{FrameConfig, Theme, Themes, UiConfig};
use std::collections::{BTreeMap, HashMap};
use std::io::Write;
Expand Down
1 change: 0 additions & 1 deletion zellij-utils/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
data::{ClientId, ConnectToSession, KeyWithModifier, Style},
errors::{get_current_ctx, prelude::*, ErrorContext},
input::config::Config,
input::keybinds::Keybinds,
input::{actions::Action, layout::Layout, options::Options, plugins::PluginAliases},
pane_size::{Size, SizeInPixels},
};
Expand Down
4 changes: 2 additions & 2 deletions zellij-utils/src/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,13 +1030,13 @@ impl Action {
Action::KeybindPipe {
name,
payload,
args,
args: _, // currently unsupported
plugin,
configuration,
launch_new,
skip_cache,
floating,
in_place,
in_place: _, // currently unsupported
cwd,
pane_title,
plugin_id,
Expand Down
Loading

0 comments on commit 96024c7

Please sign in to comment.