From 1dd4045e23b0c92570e6c203c43f318ad01dbd2c Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 9 Mar 2021 22:20:16 +0000 Subject: [PATCH] Clippy compels me to cull code --- default-tiles/strider/src/state.rs | 2 +- default-tiles/tab-bar/src/line.rs | 4 +-- default-tiles/tab-bar/src/main.rs | 4 --- src/client/panes/terminal_character.rs | 10 +++--- src/common/errors.rs | 4 +-- src/common/input/handler.rs | 15 ++++----- src/common/input/keybinds.rs | 6 ++-- src/common/ipc.rs | 8 ++--- src/common/mod.rs | 44 +++++++++++--------------- src/common/screen.rs | 13 +++----- 10 files changed, 47 insertions(+), 63 deletions(-) diff --git a/default-tiles/strider/src/state.rs b/default-tiles/strider/src/state.rs index 2a9230e8..0d96ae0b 100644 --- a/default-tiles/strider/src/state.rs +++ b/default-tiles/strider/src/state.rs @@ -58,6 +58,6 @@ impl FsEntry { } pub fn is_hidden_file(&self) -> bool { - self.name().chars().nth(0).unwrap() == '.'.into() + self.name().starts_with('.') } } diff --git a/default-tiles/tab-bar/src/line.rs b/default-tiles/tab-bar/src/line.rs index 306c0281..1f844642 100644 --- a/default-tiles/tab-bar/src/line.rs +++ b/default-tiles/tab-bar/src/line.rs @@ -56,7 +56,7 @@ fn left_more_message(tab_count_to_the_left: usize) -> LinePart { let more_text = if tab_count_to_the_left < 10000 { format!(" ← +{} ", tab_count_to_the_left) } else { - format!(" ← +many ") + " ← +many ".to_string() }; let more_styled_text = format!( "{}{}", @@ -79,7 +79,7 @@ fn right_more_message(tab_count_to_the_right: usize) -> LinePart { let more_text = if tab_count_to_the_right < 10000 { format!(" +{} → ", tab_count_to_the_right) } else { - format!(" +many → ") + " +many → ".to_string() }; let more_styled_text = format!( "{}{}{}", diff --git a/default-tiles/tab-bar/src/main.rs b/default-tiles/tab-bar/src/main.rs index 6c00cb79..f40a5c1f 100644 --- a/default-tiles/tab-bar/src/main.rs +++ b/default-tiles/tab-bar/src/main.rs @@ -26,8 +26,6 @@ impl Default for BarMode { #[derive(Default)] struct State { - active_tab_index: usize, - num_tabs: usize, tabs: Vec, mode: BarMode, new_name: String, @@ -42,8 +40,6 @@ impl ZellijTile for State { set_selectable(false); set_invisible_borders(true); set_max_height(1); - self.active_tab_index = 0; - self.num_tabs = 0; self.mode = BarMode::Normal; self.new_name = String::new(); } diff --git a/src/client/panes/terminal_character.rs b/src/client/panes/terminal_character.rs index 80c3162b..053ebd3f 100644 --- a/src/client/panes/terminal_character.rs +++ b/src/client/panes/terminal_character.rs @@ -23,7 +23,7 @@ pub enum AnsiCode { On, Reset, NamedColor(NamedColor), - RGBCode((u8, u8, u8)), + RgbCode((u8, u8, u8)), ColorIndex(u8), } @@ -336,7 +336,7 @@ impl CharacterStyles { [36, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::Cyan))), [37, ..] => *self = self.foreground(Some(AnsiCode::NamedColor(NamedColor::White))), [38, 2, ..] => { - let ansi_code = AnsiCode::RGBCode(( + let ansi_code = AnsiCode::RgbCode(( *ansi_params.get(2).unwrap() as u8, *ansi_params.get(3).unwrap() as u8, *ansi_params.get(4).unwrap() as u8, @@ -364,7 +364,7 @@ impl CharacterStyles { [46, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::Cyan))), [47, ..] => *self = self.background(Some(AnsiCode::NamedColor(NamedColor::White))), [48, 2, ..] => { - let ansi_code = AnsiCode::RGBCode(( + let ansi_code = AnsiCode::RgbCode(( *ansi_params.get(2).unwrap() as u8, *ansi_params.get(3).unwrap() as u8, *ansi_params.get(4).unwrap() as u8, @@ -416,7 +416,7 @@ impl Display for CharacterStyles { } if let Some(ansi_code) = self.foreground { match ansi_code { - AnsiCode::RGBCode((r, g, b)) => { + AnsiCode::RgbCode((r, g, b)) => { write!(f, "\u{1b}[38;2;{};{};{}m", r, g, b)?; } AnsiCode::ColorIndex(color_index) => { @@ -433,7 +433,7 @@ impl Display for CharacterStyles { }; if let Some(ansi_code) = self.background { match ansi_code { - AnsiCode::RGBCode((r, g, b)) => { + AnsiCode::RgbCode((r, g, b)) => { write!(f, "\u{1b}[48;2;{};{};{}m", r, g, b)?; } AnsiCode::ColorIndex(color_index) => { diff --git a/src/common/errors.rs b/src/common/errors.rs index 48a92b76..bd9907fa 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -133,7 +133,7 @@ pub enum ContextType { Plugin(PluginContext), /// An app-related call. App(AppContext), - IPCServer, + IpcServer, StdinHandler, AsyncTask, /// An empty, placeholder call. This should be thought of as representing no call at all. @@ -152,7 +152,7 @@ impl Display for ContextType { ContextType::Plugin(c) => write!(f, "{}plugin_thread: {}{:?}", purple, green, c), ContextType::App(c) => write!(f, "{}main_thread: {}{:?}", purple, green, c), - ContextType::IPCServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green), + ContextType::IpcServer => write!(f, "{}ipc_server: {}AcceptInput", purple, green), ContextType::StdinHandler => { write!(f, "{}stdin_handler_thread: {}AcceptInput", purple, green) } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index 40d53d5d..ed247830 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -73,15 +73,12 @@ impl InputHandler { // framework relies on it to not create dead threads that loop // and eat up CPUs. Do not remove until the test framework has // been revised. Sorry about this (@categorille) - if { - let mut should_break = false; - for action in - key_to_actions(&key, raw_bytes, &self.mode, &keybinds) - { - should_break |= self.dispatch_action(action); - } - should_break - } { + let mut should_break = false; + for action in key_to_actions(&key, raw_bytes, &self.mode, &keybinds) + { + should_break |= self.dispatch_action(action); + } + if should_break { break 'input_loop; } } diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index da0f1c15..b5dacd70 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -17,14 +17,14 @@ pub fn get_default_keybinds() -> Result { let mut defaults = Keybinds::new(); for mode in InputMode::iter() { - defaults.insert(mode, get_defaults_for_mode(&mode)?); + defaults.insert(mode, get_defaults_for_mode(&mode)); } Ok(defaults) } /// Returns the default keybinds for a givent [`InputMode`]. -fn get_defaults_for_mode(mode: &InputMode) -> Result { +fn get_defaults_for_mode(mode: &InputMode) -> ModeKeybinds { let mut defaults = ModeKeybinds::new(); match *mode { @@ -181,7 +181,7 @@ fn get_defaults_for_mode(mode: &InputMode) -> Result { } } - Ok(defaults) + defaults } /// Converts a [`Key`] terminal event to a sequence of [`Action`]s according to the current diff --git a/src/common/ipc.rs b/src/common/ipc.rs index 77d57df3..81576b86 100644 --- a/src/common/ipc.rs +++ b/src/common/ipc.rs @@ -3,12 +3,12 @@ use serde::{Deserialize, Serialize}; use std::collections::HashSet; -type SessionID = u64; +type SessionId = u64; #[derive(PartialEq, Eq, Serialize, Deserialize, Hash)] pub struct Session { // Unique ID for this session - id: SessionID, + id: SessionId, // Identifier for the underlying IPC primitive (socket, pipe) conn_name: String, // User configured alias for the session @@ -30,9 +30,9 @@ pub enum ClientToServerMsg { // Create a new session CreateSession, // Attach to a running session - AttachToSession(SessionID, ClientType), + AttachToSession(SessionId, ClientType), // Force detach - DetachSession(SessionID), + DetachSession(SessionId), // Disconnect from the session we're connected to DisconnectFromSession, } diff --git a/src/common/mod.rs b/src/common/mod.rs index 411269b6..f0babeaa 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -553,14 +553,12 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let (instance, plugin_env) = plugin_map.get(&pid).unwrap(); let handle_key = instance.exports.get_function("handle_key").unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } + for key in input_bytes.keys().flatten() { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handle_key.call(&[]).unwrap(); } } PluginInputType::Event(event) => { @@ -572,14 +570,12 @@ pub fn start(mut os_input: Box, opts: CliArgs) { .exports .get_function(handler_map.get(&event).unwrap()) .unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handle_key.call(&[]).unwrap(); - } + for key in input_bytes.keys().flatten() { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handle_key.call(&[]).unwrap(); } } } @@ -591,14 +587,12 @@ pub fn start(mut os_input: Box, opts: CliArgs) { for (instance, plugin_env) in plugin_map.values() { let handler = instance.exports.get_function("handle_global_key").unwrap(); - for key in input_bytes.keys() { - if let Ok(key) = key { - wasi_write_string( - &plugin_env.wasi_env, - &serde_json::to_string(&key).unwrap(), - ); - handler.call(&[]).unwrap(); - } + for key in input_bytes.keys().flatten() { + wasi_write_string( + &plugin_env.wasi_env, + &serde_json::to_string(&key).unwrap(), + ); + handler.call(&[]).unwrap(); } } @@ -626,7 +620,7 @@ pub fn start(mut os_input: Box, opts: CliArgs) { let listener = std::os::unix::net::UnixListener::bind(ZELLIJ_IPC_PIPE) .expect("could not listen on ipc socket"); let mut err_ctx = OPENCALLS.with(|ctx| *ctx.borrow()); - err_ctx.add_call(ContextType::IPCServer); + err_ctx.add_call(ContextType::IpcServer); send_pty_instructions.update(err_ctx); send_screen_instructions.update(err_ctx); diff --git a/src/common/screen.rs b/src/common/screen.rs index c4c4bdd7..539eef9a 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -171,15 +171,12 @@ impl Screen { pub fn go_to_tab(&mut self, mut tab_index: usize) { tab_index -= 1; let active_tab = self.get_active_tab().unwrap(); - match self.tabs.values().find(|t| t.position == tab_index) { - Some(t) => { - if t.index != active_tab.index { - self.active_tab_index = Some(t.index); - self.update_tabs(); - self.render(); - } + if let Some(t) = self.tabs.values().find(|t| t.position == tab_index) { + if t.index != active_tab.index { + self.active_tab_index = Some(t.index); + self.update_tabs(); + self.render(); } - None => {} } }