diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-04-09 17:34:43 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-04-09 17:34:43 -0400 |
commit | 84f9df66c391a0c0236dc5d052b27060c4b08c76 (patch) | |
tree | 3f0cd383de7c0e1663ba4dbe80867308e899917a /src | |
parent | 3ffd6e6501dd02ca991d16f1e2a140fa4d9d7118 (diff) |
selected files now indented like ranger
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/file_ops.rs | 2 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist_detailed.rs | 49 |
2 files changed, 25 insertions, 26 deletions
diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs index 7d83209..75a12a9 100644 --- a/src/commands/file_ops.rs +++ b/src/commands/file_ops.rs @@ -68,7 +68,7 @@ pub fn copy_filename_without_extension(context: &mut AppContext) -> JoshutoResul .curr_tab_ref() .curr_list_ref() .and_then(|c| c.curr_entry_ref()) - .map(|entry| match entry.file_name().rsplit_once(".") { + .map(|entry| match entry.file_name().rsplit_once('.') { Some((name, _)) => name.to_string(), _ => entry.file_name().to_string(), }); diff --git a/src/ui/widgets/tui_dirlist_detailed.rs b/src/ui/widgets/tui_dirlist_detailed.rs index 5705448..a98f466 100644 --- a/src/ui/widgets/tui_dirlist_detailed.rs +++ b/src/ui/widgets/tui_dirlist_detailed.rs @@ -75,24 +75,22 @@ impl<'a> Widget for TuiDirListDetailed<'a> { buf.set_string(x, y + i as u16, space_fill.as_str(), style); - let line_number_string = if ix == curr_index { - match line_num_style { - LineNumberStyle::None => "".to_string(), - _ => format!("{:<1$} ", curr_index + 1, max_index_length), - } + let mut prefix = if entry.is_selected() { + " ".to_string() } else { - match line_num_style { - LineNumberStyle::Absolute => { - format!("{:1$} ", ix + 1, max_index_length) - } - LineNumberStyle::Relative => format!( - "{:1$} ", - (curr_index as i16 - ix as i16).abs(), - max_index_length - ), - LineNumberStyle::None => String::new(), - } + "".to_string() }; + let line_number_prefix = match line_num_style { + LineNumberStyle::None => "".to_string(), + _ if ix == curr_index => format!("{:<1$} ", curr_index + 1, max_index_length), + LineNumberStyle::Absolute => format!("{:1$} ", ix + 1, max_index_length), + LineNumberStyle::Relative => format!( + "{:1$} ", + (curr_index as i16 - ix as i16).abs(), + max_index_length + ), + }; + prefix.push_str(&line_number_prefix); print_entry( buf, @@ -100,7 +98,7 @@ impl<'a> Widget for TuiDirListDetailed<'a> { style, (x + 1, y + i as u16), drawing_width - 1, - line_number_string, + &prefix, ); }); } @@ -112,7 +110,7 @@ fn print_entry( style: Style, (x, y): (u16, u16), drawing_width: usize, - index: String, + prefix: &str, ) { let size_string = match entry.metadata.file_type() { FileType::Directory => entry @@ -129,19 +127,20 @@ fn print_entry( let left_label_original = entry.label(); let right_label_original = format!(" {}{} ", symlink_string, size_string); + // draw prefix first + let prefix_width = prefix.width(); + buf.set_stringn(x, y, prefix, prefix_width, Style::default()); + let x = x + prefix_width as u16; + + // factor left_label and right_label + let drawing_width = drawing_width - prefix_width as usize; let (left_label, right_label) = factor_labels_for_entry( left_label_original, right_label_original.as_str(), drawing_width, ); - let index_width = index.width(); - // draw_index - buf.set_stringn(x, y, index, index_width, Style::default()); - - let drawing_width = drawing_width - index_width as usize; - let x = x + index_width as u16; - // Drawing labels + // Draw labels buf.set_stringn(x, y, left_label, drawing_width, style); buf.set_stringn( x + drawing_width as u16 - right_label.width() as u16, |