diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-11-27 19:56:56 -0500 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-11-27 19:56:56 -0500 |
commit | e09ce8474a55eecee4e6c4b438fc8ec87e6b8d09 (patch) | |
tree | 0d675331bc4045d5788eeb5766d691688a6b6dc1 | |
parent | 186e9a1f9efcb3832a2e3deff8243d8e9c4de6b2 (diff) |
cargo clippy
-rw-r--r-- | src/commands/bulk_rename.rs | 2 | ||||
-rw-r--r-- | src/commands/cursor_move.rs | 8 | ||||
-rw-r--r-- | src/commands/delete_files.rs | 2 | ||||
-rw-r--r-- | src/commands/preview_cursor_move.rs | 12 | ||||
-rw-r--r-- | src/commands/search_fzf.rs | 2 | ||||
-rw-r--r-- | src/commands/subdir_fzf.rs | 5 | ||||
-rw-r--r-- | src/io/io_worker.rs | 3 | ||||
-rw-r--r-- | src/preview/preview_file.rs | 2 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 54 | ||||
-rw-r--r-- | src/ui/widgets/tui_file_preview.rs | 2 | ||||
-rw-r--r-- | src/ui/widgets/tui_help.rs | 4 |
11 files changed, 45 insertions, 51 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index 4ef51d4..acab29a 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -82,8 +82,6 @@ pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult<()> { } println!("{}", termion::clear::All); - termion::cursor::Goto(0, 0); - for (p, q) in paths.iter().zip(paths_renamed.iter()) { println!("{:?} -> {:?}", p, q); } diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs index f22ac55..3303abb 100644 --- a/src/commands/cursor_move.rs +++ b/src/commands/cursor_move.rs @@ -124,12 +124,10 @@ fn get_page_size(context: &AppContext, backend: &TuiBackend) -> Option<usize> { } else { None } + } else if rect_height >= 2 { + Some(rect_height - 2) } else { - if rect_height >= 2 { - Some(rect_height - 2) - } else { - None - } + None } } diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs index db7463f..e5ef734 100644 --- a/src/commands/delete_files.rs +++ b/src/commands/delete_files.rs @@ -68,7 +68,7 @@ fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io:: .curr_tab_ref() .curr_list_ref() .map(|s| s.get_selected_paths()) - .unwrap_or_else(|| vec![]); + .unwrap_or_else(Vec::new); let paths_len = paths.len(); if paths_len == 0 { return Err(std::io::Error::new( diff --git a/src/commands/preview_cursor_move.rs b/src/commands/preview_cursor_move.rs index 6b30a14..7ce434b 100644 --- a/src/commands/preview_cursor_move.rs +++ b/src/commands/preview_cursor_move.rs @@ -8,12 +8,10 @@ pub fn preview_cursor_move(context: &mut AppContext, new_index: usize) -> Joshut let curr_tab = context.tab_context_ref().curr_tab_ref(); let curr_list = curr_tab.curr_list_ref(); let curr_entry = curr_list.and_then(|c| c.curr_entry_ref()); - let file_path = curr_entry.map(|e| e.file_path().to_path_buf()); - file_path + curr_entry.map(|e| e.file_path().to_path_buf()) }; let preview_context = context.preview_context_mut(); - if let Some(file_path) = file_path { if let Some(Some(preview)) = preview_context.get_preview_mut(&file_path) { preview.index = new_index; @@ -32,7 +30,7 @@ pub fn preview_up(context: &mut AppContext, u: usize) -> JoshutoResult<()> { let preview_context = context.preview_context_ref(); if let Some(file_path) = file_path { - if let Some(Some(preview)) = preview_context.get_preview_ref(&file_path) { + if let Some(Some(preview)) = preview_context.get_preview_ref(file_path) { if preview.index < u { Some(0) } else { @@ -46,7 +44,7 @@ pub fn preview_up(context: &mut AppContext, u: usize) -> JoshutoResult<()> { } }; if let Some(new_index) = new_index { - preview_cursor_move(context, new_index); + preview_cursor_move(context, new_index)?; } Ok(()) } @@ -61,7 +59,7 @@ pub fn preview_down(context: &mut AppContext, u: usize) -> JoshutoResult<()> { let preview_context = context.preview_context_ref(); if let Some(file_path) = file_path { - if let Some(Some(preview)) = preview_context.get_preview_ref(&file_path) { + if let Some(Some(preview)) = preview_context.get_preview_ref(file_path) { Some(preview.index + u) } else { None @@ -71,7 +69,7 @@ pub fn preview_down(context: &mut AppContext, u: usize) -> JoshutoResult<()> { } }; if let Some(new_index) = new_index { - preview_cursor_move(context, new_index); + preview_cursor_move(context, new_index)?; } Ok(()) } diff --git a/src/commands/search_fzf.rs b/src/commands/search_fzf.rs index 445ce35..a551f7f 100644 --- a/src/commands/search_fzf.rs +++ b/src/commands/search_fzf.rs @@ -20,7 +20,7 @@ pub fn search_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> Joshuto .collect(); v }) - .unwrap_or_else(|| vec![]); + .unwrap_or_else(Vec::new); if items.is_empty() { return Err(JoshutoError::new( diff --git a/src/commands/subdir_fzf.rs b/src/commands/subdir_fzf.rs index 050f744..74c86f2 100644 --- a/src/commands/subdir_fzf.rs +++ b/src/commands/subdir_fzf.rs @@ -61,15 +61,14 @@ pub fn subdir_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> Joshuto pub fn fzf_change_dir(context: &mut AppContext, path: &Path) -> JoshutoResult<()> { if path.is_dir() { - change_directory(context, &path)?; + change_directory(context, path)?; } else if let Some(parent) = path.parent() { let file_name = path .file_name() .and_then(|name| name.to_str()) .unwrap() .trim(); - - change_directory(context, &parent)?; + change_directory(context, parent)?; let index = match context.tab_context_ref().curr_tab_ref().curr_list_ref() { Some(curr_list) => curr_list diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs index 2ebc245..5b67acc 100644 --- a/src/io/io_worker.rs +++ b/src/io/io_worker.rs @@ -258,7 +258,7 @@ pub fn recursive_cut( progress.set_files_processed(progress.files_processed() + 1); Ok(()) } - Err(e) => { + Err(_e) => { if file_type.is_dir() { fs::create_dir(dest_buf.as_path())?; for entry in fs::read_dir(src)? { @@ -288,6 +288,5 @@ pub fn recursive_cut( } Ok(()) } - e => e, } } diff --git a/src/preview/preview_file.rs b/src/preview/preview_file.rs index d4e08c5..7f0d1ff 100644 --- a/src/preview/preview_file.rs +++ b/src/preview/preview_file.rs @@ -25,7 +25,7 @@ pub struct FilePreview { impl std::convert::From<Output> for FilePreview { fn from(output: Output) -> Self { let s = String::from_utf8_lossy(&output.stdout).to_string(); - let s2 = s.replace('\t', " ").to_string(); + let s2 = s.replace('\t', " "); let status = output.status; Self { status, diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index e03f084..22d5665 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use tui::buffer::Buffer; use tui::layout::Rect; use tui::style::{Color, Modifier, Style}; @@ -127,22 +129,20 @@ fn factor_labels_for_entry<'a>( ("".to_string(), "") } else if width_remainder >= 0 { (left_label_original.to_string(), right_label_original) + } else if left_width_remainder < MIN_LEFT_LABEL_WIDTH { + ( + if left_label_original.width() as i32 <= left_width_remainder { + trim_file_label(left_label_original, drawing_width) + } else { + left_label_original.to_string() + }, + "", + ) } else { - if left_width_remainder < MIN_LEFT_LABEL_WIDTH { - ( - if left_label_original.width() as i32 <= left_width_remainder { - trim_file_label(left_label_original, drawing_width) - } else { - left_label_original.to_string() - }, - "", - ) - } else { - ( - trim_file_label(left_label_original, left_width_remainder as usize), - right_label_original, - ) - } + ( + trim_file_label(left_label_original, left_width_remainder as usize), + right_label_original, + ) } } @@ -161,17 +161,19 @@ pub fn trim_file_label(name: &str, drawing_width: usize) -> String { truncated } else { let ext_width = extension.width(); - if ext_width > drawing_width { - // file ext does not fit - let stem_width = drawing_width; - let truncated_stem = stem.trunc(stem_width - 3); - format!("{}{}.{}", truncated_stem, ELLIPSIS, ELLIPSIS) - } else if ext_width == drawing_width { - extension.replacen('.', ELLIPSIS, 1) - } else { - let stem_width = drawing_width - ext_width; - let truncated_stem = stem.trunc(stem_width - 1); - format!("{}{}{}", truncated_stem, ELLIPSIS, extension) + match ext_width.cmp(&drawing_width) { + Ordering::Less => { + let stem_width = drawing_width - ext_width; + let truncated_stem = stem.trunc(stem_width - 1); + format!("{}{}{}", truncated_stem, ELLIPSIS, extension) + } + Ordering::Equal => extension.replacen('.', ELLIPSIS, 1), + Ordering::Greater => { + // file ext does not fit + let stem_width = drawing_width; + let truncated_stem = stem.trunc(stem_width - 3); + format!("{}{}.{}", truncated_stem, ELLIPSIS, ELLIPSIS) + } } } } diff --git a/src/ui/widgets/tui_file_preview.rs b/src/ui/widgets/tui_file_preview.rs index cc9e7bd..cfd6812 100644 --- a/src/ui/widgets/tui_file_preview.rs +++ b/src/ui/widgets/tui_file_preview.rs @@ -27,7 +27,7 @@ impl<'a> Widget for TuiFilePreview<'a> { .skip(self.preview.index) .zip(area.y..area.y + area.height) { - buf.set_spans(area.x, y, &line, area.width); + buf.set_spans(area.x, y, line, area.width); } } } diff --git a/src/ui/widgets/tui_help.rs b/src/ui/widgets/tui_help.rs index 58f109b..cdec4db 100644 --- a/src/ui/widgets/tui_help.rs +++ b/src/ui/widgets/tui_help.rs @@ -24,13 +24,13 @@ const FOOTER: &str = "Press <ESC> to return, / to search, 1,2,3 to sort"; pub struct TuiHelp<'a> { // This keymap is constructed with get_keymap_table function - keymap: &'a Vec<Row<'a>>, + keymap: &'a [Row<'a>], offset: &'a mut u8, search_query: &'a str, } impl<'a> TuiHelp<'a> { - pub fn new(keymap: &'a Vec<Row>, offset: &'a mut u8, search_query: &'a str) -> TuiHelp<'a> { + pub fn new(keymap: &'a [Row], offset: &'a mut u8, search_query: &'a str) -> TuiHelp<'a> { TuiHelp { keymap, offset, |