From 1d10e0c6748a5b98a1efed6d0a39c49aafbc52fb Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 20 Sep 2023 22:00:30 +0200 Subject: [PATCH 1/3] ls: rename the function for something more explicit --- src/uu/ls/src/dired.rs | 2 +- src/uu/ls/src/ls.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs index f66d22b38..ba8f09335 100644 --- a/src/uu/ls/src/dired.rs +++ b/src/uu/ls/src/dired.rs @@ -54,7 +54,7 @@ pub fn indent(out: &mut BufWriter) -> UResult<()> { Ok(()) } -pub fn calculate_offset_and_push(dired: &mut DiredOutput, path_len: usize) { +pub fn calculate_subdired(dired: &mut DiredOutput, path_len: usize) { let offset = if dired.subdired_positions.is_empty() { DIRED_TRAILING_OFFSET } else { diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 3d67cccaa..7f977da2a 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1921,7 +1921,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { } writeln!(out, "{}:", path_data.p_buf.display())?; if config.dired { - dired::calculate_offset_and_push(&mut dired, path_data.display_name.len()); + dired::calculate_subdired(&mut dired, path_data.display_name.len()); } } else { writeln!(out, "\n{}:", path_data.p_buf.display())?; From 8db6146dd3c6b131723bfd0cd3bf3b443a3efdc4 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 20 Sep 2023 22:00:38 +0200 Subject: [PATCH 2/3] ls remove old comment --- src/uu/ls/src/dired.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs index ba8f09335..8e85a2e0f 100644 --- a/src/uu/ls/src/dired.rs +++ b/src/uu/ls/src/dired.rs @@ -95,7 +95,6 @@ pub fn add_total(total_len: usize, dired: &mut DiredOutput) { dired.just_printed_total = true; dired.dired_positions.push(BytePosition { start: 0, - // the 2 is from the trailing spaces // the 1 is from the line ending (\n) end: total_len + DIRED_TRAILING_OFFSET - 1, }); From a12dd2ee1eddb42d23646ef7964b919a4b752d3c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 20 Sep 2023 22:09:34 +0200 Subject: [PATCH 3/3] ls rename the function for consistency --- src/uu/ls/src/dired.rs | 7 +++---- src/uu/ls/src/ls.rs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs index 8e85a2e0f..288d7fc76 100644 --- a/src/uu/ls/src/dired.rs +++ b/src/uu/ls/src/dired.rs @@ -33,7 +33,7 @@ impl fmt::Display for BytePosition { static DIRED_TRAILING_OFFSET: usize = 2; /// Calculates the byte positions for DIRED -pub fn calculate_dired_byte_positions( +pub fn calculate_dired( output_display_len: usize, dfn_len: usize, dired_positions: &[BytePosition], @@ -143,12 +143,11 @@ mod tests { use super::*; #[test] - fn test_calculate_dired_byte_positions() { + fn test_calculate_dired() { let output_display = "sample_output".to_string(); let dfn = "sample_file".to_string(); let dired_positions = vec![BytePosition { start: 5, end: 10 }]; - let (start, end) = - calculate_dired_byte_positions(output_display.len(), dfn.len(), &dired_positions); + let (start, end) = calculate_dired(output_display.len(), dfn.len(), &dired_positions); assert_eq!(start, 24); assert_eq!(end, 35); diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 7f977da2a..f7a3b79ae 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -2545,7 +2545,7 @@ fn display_item_long( let displayed_file = display_file_name(item, config, None, String::new(), out).contents; if config.dired { - let (start, end) = dired::calculate_dired_byte_positions( + let (start, end) = dired::calculate_dired( output_display.len(), displayed_file.len(), &dired.dired_positions,