Apply cargo clippy --fix cleanups

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-14 19:51:45 +02:00
parent 39fb2a270a
commit 91c520c86a
4 changed files with 35 additions and 53 deletions

View File

@@ -494,12 +494,11 @@ impl App {
pub fn selected_target_dir(&self) -> Option<PathBuf> { pub fn selected_target_dir(&self) -> Option<PathBuf> {
if self.selected_indices.len() == 1 { if self.selected_indices.len() == 1 {
let i = self.selected_indices[0]; let i = self.selected_indices[0];
if let Some(e) = self.entries.get(i) { if let Some(e) = self.entries.get(i)
if e.is_dir() { && e.is_dir() {
return Some(e.path.clone()); return Some(e.path.clone());
} }
} }
}
Some(self.current_path.clone()) Some(self.current_path.clone())
} }

View File

@@ -2,9 +2,11 @@ use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Default)]
pub enum AppliesTo { pub enum AppliesTo {
File, File,
Dir, Dir,
#[default]
Both, Both,
} }
@@ -25,9 +27,6 @@ impl AppliesTo {
} }
} }
impl Default for AppliesTo {
fn default() -> Self { AppliesTo::Both }
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)] #[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct CustomMenuItem { pub struct CustomMenuItem {
@@ -49,22 +48,19 @@ impl Config {
/// Preferred path: config.json next to the running binary. /// Preferred path: config.json next to the running binary.
/// Falls back to ~/.config/tui-fm/config.json if the exe path can't be determined. /// Falls back to ~/.config/tui-fm/config.json if the exe path can't be determined.
fn config_path() -> Option<PathBuf> { fn config_path() -> Option<PathBuf> {
if let Ok(exe) = std::env::current_exe() { if let Ok(exe) = std::env::current_exe()
if let Some(dir) = exe.parent() { && let Some(dir) = exe.parent() {
return Some(dir.join("config.json")); return Some(dir.join("config.json"));
} }
}
dirs::config_dir().map(|d| d.join("tui-fm").join("config.json")) dirs::config_dir().map(|d| d.join("tui-fm").join("config.json"))
} }
pub fn load() -> Self { pub fn load() -> Self {
if let Some(path) = Self::config_path() { if let Some(path) = Self::config_path()
if let Ok(data) = std::fs::read_to_string(&path) { && let Ok(data) = std::fs::read_to_string(&path)
if let Ok(config) = serde_json::from_str::<Config>(&data) { && let Ok(config) = serde_json::from_str::<Config>(&data) {
return config; return config;
} }
}
}
Config::default() Config::default()
} }

View File

@@ -46,9 +46,8 @@ fn handle_key(app: &mut App, key: crossterm::event::KeyEvent) -> bool {
match key.code { match key.code {
KeyCode::Esc => { app.context_menu = None; return false; } KeyCode::Esc => { app.context_menu = None; return false; }
KeyCode::Up => { KeyCode::Up => {
if let Some(ref mut m) = app.context_menu { if let Some(ref mut m) = app.context_menu
if m.selected > 0 { m.selected -= 1; } && m.selected > 0 { m.selected -= 1; }
}
return false; return false;
} }
KeyCode::Down => { KeyCode::Down => {
@@ -170,8 +169,8 @@ fn handle_key(app: &mut App, key: crossterm::event::KeyEvent) -> bool {
app.path_input_sel_anchor = None; app.path_input_sel_anchor = None;
} }
KeyCode::Backspace => { KeyCode::Backspace => {
if !delete_selection(app) { if !delete_selection(app)
if app.path_input_cursor > 0 { && app.path_input_cursor > 0 {
let remove_pos = app.path_input_cursor - 1; let remove_pos = app.path_input_cursor - 1;
let new: String = app.path_input.chars().enumerate() let new: String = app.path_input.chars().enumerate()
.filter(|&(i, _)| i != remove_pos) .filter(|&(i, _)| i != remove_pos)
@@ -180,19 +179,17 @@ fn handle_key(app: &mut App, key: crossterm::event::KeyEvent) -> bool {
app.path_input = new; app.path_input = new;
app.path_input_cursor -= 1; app.path_input_cursor -= 1;
} }
}
app.path_input_sel_anchor = None; app.path_input_sel_anchor = None;
} }
KeyCode::Delete => { KeyCode::Delete => {
if !delete_selection(app) { if !delete_selection(app)
if app.path_input_cursor < char_count { && app.path_input_cursor < char_count {
let new: String = app.path_input.chars().enumerate() let new: String = app.path_input.chars().enumerate()
.filter(|&(i, _)| i != app.path_input_cursor) .filter(|&(i, _)| i != app.path_input_cursor)
.map(|(_, c)| c) .map(|(_, c)| c)
.collect(); .collect();
app.path_input = new; app.path_input = new;
} }
}
app.path_input_sel_anchor = None; app.path_input_sel_anchor = None;
} }
KeyCode::Left => { KeyCode::Left => {
@@ -284,13 +281,12 @@ fn handle_key(app: &mut App, key: crossterm::event::KeyEvent) -> bool {
app.navigate_up(); app.navigate_up();
} }
KeyCode::F(2) => { KeyCode::F(2) => {
if let Some(&i) = app.selected_indices.first() { if let Some(&i) = app.selected_indices.first()
if let Some(e) = app.entries.get(i) { && let Some(e) = app.entries.get(i) {
app.rename_original = Some(e.path.clone()); app.rename_original = Some(e.path.clone());
app.dialog = DialogMode::Rename(e.name.clone()); app.dialog = DialogMode::Rename(e.name.clone());
} }
} }
}
KeyCode::Delete => { KeyCode::Delete => {
if !app.selected_indices.is_empty() { if !app.selected_indices.is_empty() {
let msg = format!("Delete {} item(s)? (y/n)", app.selected_indices.len()); let msg = format!("Delete {} item(s)? (y/n)", app.selected_indices.len());
@@ -298,16 +294,13 @@ fn handle_key(app: &mut App, key: crossterm::event::KeyEvent) -> bool {
} }
} }
KeyCode::Enter => { KeyCode::Enter => {
if app.focus == Focus::FileView { if app.focus == Focus::FileView
if let Some(&i) = app.selected_indices.first() { && let Some(&i) = app.selected_indices.first()
if let Some(e) = app.entries.get(i).cloned() { && let Some(e) = app.entries.get(i).cloned()
if e.is_dir() { && e.is_dir() {
app.navigate_to(e.path.clone()); app.navigate_to(e.path.clone());
} }
} }
}
}
}
KeyCode::Up => { KeyCode::Up => {
if app.focus == Focus::FileView { if app.focus == Focus::FileView {
scroll_selection(app, -1); scroll_selection(app, -1);
@@ -395,13 +388,12 @@ fn execute_context_menu(app: &mut App) {
app.paste_into(&dst.clone()); app.paste_into(&dst.clone());
} }
ContextMenuItem::Rename => { ContextMenuItem::Rename => {
if let Some(&i) = app.selected_indices.first() { if let Some(&i) = app.selected_indices.first()
if let Some(e) = app.entries.get(i) { && let Some(e) = app.entries.get(i) {
app.rename_original = Some(e.path.clone()); app.rename_original = Some(e.path.clone());
app.dialog = DialogMode::Rename(e.name.clone()); app.dialog = DialogMode::Rename(e.name.clone());
} }
} }
}
ContextMenuItem::Properties => app.compute_properties(), ContextMenuItem::Properties => app.compute_properties(),
ContextMenuItem::NewFile => app.dialog = DialogMode::NewFile(String::new()), ContextMenuItem::NewFile => app.dialog = DialogMode::NewFile(String::new()),
ContextMenuItem::NewDir => app.dialog = DialogMode::NewDir(String::new()), ContextMenuItem::NewDir => app.dialog = DialogMode::NewDir(String::new()),
@@ -838,7 +830,7 @@ fn handle_left_click(app: &mut App, col: u16, row: u16) {
let char_count = app.path_input.chars().count(); let char_count = app.path_input.chars().count();
let input_w = inner_w.saturating_sub(hint_width + 1 + 6); let input_w = inner_w.saturating_sub(hint_width + 1 + 6);
let avail = input_w.saturating_sub(label_display_w) as usize; let avail = input_w.saturating_sub(label_display_w) as usize;
let scroll_start = if app.path_input_cursor > avail { app.path_input_cursor - avail } else { 0 }; let scroll_start = app.path_input_cursor.saturating_sub(avail);
let new_cursor = (scroll_start + click_offset).min(char_count); let new_cursor = (scroll_start + click_offset).min(char_count);
app.path_input_cursor = new_cursor; app.path_input_cursor = new_cursor;
} }
@@ -883,11 +875,10 @@ fn handle_left_click(app: &mut App, col: u16, row: u16) {
if is_double { if is_double {
app.last_click_entry = None; app.last_click_entry = None;
if let Some(e) = app.entries.get(idx).cloned() { if let Some(e) = app.entries.get(idx).cloned()
if e.is_dir() { && e.is_dir() {
app.navigate_to(e.path.clone()); app.navigate_to(e.path.clone());
} }
}
} else { } else {
app.select_only(idx); app.select_only(idx);
} }
@@ -899,22 +890,20 @@ fn handle_right_click(app: &mut App, col: u16, row: u16) {
// Right-click on sidebar favorite // Right-click on sidebar favorite
if col < layout.sidebar.x + layout.sidebar.width { if col < layout.sidebar.x + layout.sidebar.width {
if let Some(item) = hit_test_sidebar(app, col, row, &layout) { if let Some(item) = hit_test_sidebar(app, col, row, &layout)
if let SidebarItem::Favorite(_, path) = item { && let SidebarItem::Favorite(_, path) = item {
let menu = app.build_context_menu(col, row, true, Some(path)); let menu = app.build_context_menu(col, row, true, Some(path));
app.context_menu = Some(menu); app.context_menu = Some(menu);
return; return;
} }
}
return; return;
} }
// Right-click on file // Right-click on file
if let Some(idx) = hit_test_file_view(app, col, row, &layout) { if let Some(idx) = hit_test_file_view(app, col, row, &layout)
if !app.selected_indices.contains(&idx) { && !app.selected_indices.contains(&idx) {
app.select_only(idx); app.select_only(idx);
} }
}
let menu = app.build_context_menu(col, row, false, None); let menu = app.build_context_menu(col, row, false, None);
app.context_menu = Some(menu); app.context_menu = Some(menu);
@@ -985,8 +974,8 @@ fn handle_mouse_move(app: &mut App, col: u16, row: u16) {
} }
// When NewSubmenu is highlighted, check if the mouse moves into the flyout // When NewSubmenu is highlighted, check if the mouse moves into the flyout
if let Some(ns_pos) = menu.items.iter().position(|i| matches!(i, ContextMenuItem::NewSubmenu)) { if let Some(ns_pos) = menu.items.iter().position(|i| matches!(i, ContextMenuItem::NewSubmenu))
if menu.selected == ns_pos { && menu.selected == ns_pos {
let (term_w, _) = app.term_size; let (term_w, _) = app.term_size;
let sub_x = (mx + MENU_W).min(term_w.saturating_sub(SUB_W)); let sub_x = (mx + MENU_W).min(term_w.saturating_sub(SUB_W));
let sub_y = my + 1 + ns_pos as u16; let sub_y = my + 1 + ns_pos as u16;
@@ -998,8 +987,6 @@ fn handle_mouse_move(app: &mut App, col: u16, row: u16) {
if row > sub_y && row < sub_y + 3 { if row > sub_y && row < sub_y + 3 {
menu.sub_selected = Some((row - sub_y - 1) as usize); menu.sub_selected = Some((row - sub_y - 1) as usize);
} }
return;
}
} }
} }
} }
@@ -1032,7 +1019,7 @@ fn handle_mouse_drag(app: &mut App, col: u16, row: u16) {
let click_offset = (col - text_start_x) as usize; let click_offset = (col - text_start_x) as usize;
let char_count = app.path_input.chars().count(); let char_count = app.path_input.chars().count();
let avail = inner_w.saturating_sub(hint_width + 1 + 6).saturating_sub(label_display_w) as usize; let avail = inner_w.saturating_sub(hint_width + 1 + 6).saturating_sub(label_display_w) as usize;
let scroll_start = if app.path_input_cursor > avail { app.path_input_cursor - avail } else { 0 }; let scroll_start = app.path_input_cursor.saturating_sub(avail);
app.path_input_cursor = (scroll_start + click_offset).min(char_count); app.path_input_cursor = (scroll_start + click_offset).min(char_count);
} }
} }

View File

@@ -444,7 +444,7 @@ fn draw_bottom_bar(f: &mut Frame, app: &App, area: Rect) {
]; ];
if focused { if focused {
let scroll_start = if cursor_pos > avail { cursor_pos - avail } else { 0 }; let scroll_start = cursor_pos.saturating_sub(avail);
if let Some((sel_start, sel_end)) = sel_range { if let Some((sel_start, sel_end)) = sel_range {
// Render with selection highlight // Render with selection highlight
@@ -517,7 +517,7 @@ fn scroll_input_text(text: &str, cursor: usize, avail: usize) -> (String, usize)
if char_count <= avail { if char_count <= avail {
return (text.to_string(), cursor); return (text.to_string(), cursor);
} }
let start = if cursor > avail { cursor - avail } else { 0 }; let start = cursor.saturating_sub(avail);
let end = (start + avail).min(char_count); let end = (start + avail).min(char_count);
let slice: String = text.chars().skip(start).take(end - start).collect(); let slice: String = text.chars().skip(start).take(end - start).collect();
let cursor_in_display = cursor.saturating_sub(start); let cursor_in_display = cursor.saturating_sub(start);