From e09ce8474a55eecee4e6c4b438fc8ec87e6b8d09 Mon Sep 17 00:00:00 2001 From: Jeff Zhao Date: Sat, 27 Nov 2021 19:56:56 -0500 Subject: cargo clippy --- src/ui/widgets/tui_dirlist_detailed.rs | 54 ++++++++++++++++++---------------- src/ui/widgets/tui_file_preview.rs | 2 +- src/ui/widgets/tui_help.rs | 4 +-- 3 files changed, 31 insertions(+), 29 deletions(-) (limited to 'src/ui') 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 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>, + keymap: &'a [Row<'a>], offset: &'a mut u8, search_query: &'a str, } impl<'a> TuiHelp<'a> { - pub fn new(keymap: &'a Vec, 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, -- cgit v1.2.3