From 2266da9106a8abc322b3b23d362a90ef65408954 Mon Sep 17 00:00:00 2001
From: 2Shirt <2xShirt@gmail.com>
Date: Sun, 17 Nov 2024 16:12:04 -0800
Subject: [PATCH] Apply Clippy pedantic recommendations
---
src/app.rs | 63 ++++++++++++++++++----------------------
src/components/footer.rs | 56 +++++++++++++++--------------------
src/components/left.rs | 23 +++++++--------
src/components/popup.rs | 11 +++----
src/components/right.rs | 24 +++++++--------
src/components/title.rs | 11 +++----
src/config.rs | 37 ++++++++++++-----------
src/system/disk.rs | 8 ++---
src/system/diskpart.rs | 4 +--
src/tasks.rs | 13 ++++-----
10 files changed, 110 insertions(+), 140 deletions(-)
diff --git a/src/app.rs b/src/app.rs
index 4322a1a..a5ba031 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -141,14 +141,15 @@ impl App {
(_, Mode::PreClone) => Mode::Clone,
(_, Mode::Clone) => Mode::SelectParts,
(Mode::SelectParts, Mode::Confirm) => Mode::PostClone,
- (_, Mode::PostClone) => Mode::Done,
- (_, Mode::Done) => Mode::Done,
+ (_, Mode::PostClone | Mode::Done) => Mode::Done,
(_, Mode::Failed) => Mode::Failed,
// Invalid states
(_, Mode::Confirm) => panic!("This shouldn't happen."),
};
- if new_mode != self.cur_mode {
+ if new_mode == self.cur_mode {
+ None
+ } else {
match self.cur_mode {
// Update prev_mode if appropriate
Mode::Confirm => {}
@@ -159,8 +160,6 @@ impl App {
_ => self.prev_mode = self.cur_mode,
}
Some(new_mode)
- } else {
- None
}
}
@@ -171,13 +170,13 @@ impl App {
.frame_rate(self.frame_rate);
tui.enter()?;
- for component in self.components.iter_mut() {
+ for component in &mut self.components {
component.register_action_handler(self.action_tx.clone())?;
}
- for component in self.components.iter_mut() {
+ for component in &mut self.components {
component.register_config_handler(self.config.clone())?;
}
- for component in self.components.iter_mut() {
+ for component in &mut self.components {
component.init(tui.size()?)?;
}
@@ -213,7 +212,7 @@ impl App {
Event::Key(key) => self.handle_key_event(key)?,
_ => {}
}
- for component in self.components.iter_mut() {
+ for component in &mut self.components {
if let Some(action) = component.handle_events(Some(event.clone()))? {
action_tx.send(action)?;
}
@@ -226,22 +225,19 @@ impl App {
let Some(keymap) = self.config.keybindings.get(&self.cur_mode) else {
return Ok(());
};
- match keymap.get(&vec![key]) {
- Some(action) => {
+ if let Some(action) = keymap.get(&vec![key]) {
+ info!("Got action: {action:?}");
+ action_tx.send(action.clone())?;
+ } else {
+ // If the key was not handled as a single key action,
+ // then consider it for multi-key combinations.
+ self.last_tick_key_events.push(key);
+
+ // Check for multi-key combinations
+ if let Some(action) = keymap.get(&self.last_tick_key_events) {
info!("Got action: {action:?}");
action_tx.send(action.clone())?;
}
- _ => {
- // If the key was not handled as a single key action,
- // then consider it for multi-key combinations.
- self.last_tick_key_events.push(key);
-
- // Check for multi-key combinations
- if let Some(action) = keymap.get(&self.last_tick_key_events) {
- info!("Got action: {action:?}");
- action_tx.send(action.clone())?;
- }
- }
}
Ok(())
}
@@ -272,7 +268,7 @@ impl App {
self.action_tx.send(Action::SetMode(Mode::Failed))?;
}
Action::InstallDriver => {
- self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?
+ self.action_tx.send(Action::SetMode(Mode::InstallDrivers))?;
}
Action::SelectDriver(ref driver) => {
self.driver = Some(driver.clone());
@@ -358,14 +354,13 @@ impl App {
// Get System32 path
let system32 = if cfg!(windows) {
- match env::var("SYSTEMROOT") {
- Ok(path) => format!("{path}/System32"),
- Err(_) => {
- self.action_tx.send(Action::Error(String::from(
- "ERROR\n\n\nFailed to find SYSTEMROOT",
- )))?;
- return Ok(());
- }
+ if let Ok(path) = env::var("SYSTEMROOT") {
+ format!("{path}/System32")
+ } else {
+ self.action_tx.send(Action::Error(String::from(
+ "ERROR\n\n\nFailed to find SYSTEMROOT",
+ )))?;
+ return Ok(());
}
} else {
String::from(".")
@@ -467,9 +462,9 @@ impl App {
}
_ => {}
}
- for component in self.components.iter_mut() {
+ for component in &mut self.components {
if let Some(action) = component.update(action.clone())? {
- self.action_tx.send(action)?
+ self.action_tx.send(action)?;
};
}
}
@@ -494,7 +489,7 @@ impl App {
if let Err(err) = component.draw(frame, area) {
let _ = self
.action_tx
- .send(Action::Error(format!("Failed to draw: {:?}", err)));
+ .send(Action::Error(format!("Failed to draw: {err:?}")));
}
}
};
diff --git a/src/components/footer.rs b/src/components/footer.rs
index 8258e21..1530cd7 100644
--- a/src/components/footer.rs
+++ b/src/components/footer.rs
@@ -14,7 +14,10 @@
// along with Deja-vu. If not, see .
//
use color_eyre::Result;
-use ratatui::{prelude::*, widgets::*};
+use ratatui::{
+ prelude::*,
+ widgets::{Block, Borders, Paragraph},
+};
use tokio::sync::mpsc::UnboundedSender;
use super::Component;
@@ -24,13 +27,13 @@ use crate::{action::Action, app::Mode, config::Config};
pub struct Footer {
command_tx: Option>,
config: Config,
- footer_text: String,
+ text: String,
}
impl Footer {
pub fn new() -> Self {
Self {
- footer_text: String::from("(q) to quit"),
+ text: String::from("(q) to quit"),
..Default::default()
}
}
@@ -48,36 +51,25 @@ impl Component for Footer {
}
fn update(&mut self, action: Action) -> Result