summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-11-27 19:56:56 -0500
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-11-27 19:56:56 -0500
commite09ce8474a55eecee4e6c4b438fc8ec87e6b8d09 (patch)
tree0d675331bc4045d5788eeb5766d691688a6b6dc1 /src/ui
parent186e9a1f9efcb3832a2e3deff8243d8e9c4de6b2 (diff)
cargo clippy
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/widgets/tui_dirlist_detailed.rs54
-rw-r--r--src/ui/widgets/tui_file_preview.rs2
-rw-r--r--src/ui/widgets/tui_help.rs4
3 files changed, 31 insertions, 29 deletions
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,