diff --git a/src/uu/ls/src/colors.rs b/src/uu/ls/src/colors.rs index 66dd4f6a2ef..a50418cd987 100644 --- a/src/uu/ls/src/colors.rs +++ b/src/uu/ls/src/colors.rs @@ -786,7 +786,7 @@ fn parse_indicator_codes() -> (FxHashMap, bool) { } fn canonicalize_indicator_value(value: &str) -> Cow<'_, str> { - if value.len() == 1 && value.chars().all(|c| c.is_ascii_digit()) { + if value.len() == 1 && value.as_bytes()[0].is_ascii_digit() { let mut canonical = String::with_capacity(2); canonical.push('0'); canonical.push_str(value); diff --git a/src/uu/ls/src/dired.rs b/src/uu/ls/src/dired.rs index 4d96c4d9c27..e3cda96b54f 100644 --- a/src/uu/ls/src/dired.rs +++ b/src/uu/ls/src/dired.rs @@ -108,7 +108,7 @@ pub fn print_dired_output( } /// Helper function to print positions with a given prefix. -fn print_positions(prefix: &str, positions: &Vec) { +fn print_positions(prefix: &str, positions: &[BytePosition]) { print!("{prefix}"); for c in positions { print!(" {c}"); @@ -117,16 +117,7 @@ fn print_positions(prefix: &str, positions: &Vec) { } pub fn add_total(dired: &mut DiredOutput, total_len: usize) { - if dired.padding == 0 { - // when dealing with " total: xx", it isn't part of the //DIRED// - // so, we just keep the size line to add it to the position of the next file - dired.padding = total_len + DIRED_TRAILING_OFFSET; - } else { - // += because if we are in -R, we have " dir:\n total X". So, we need to take the - // previous padding too. - // and we already have the previous position in mind - dired.padding += total_len + DIRED_TRAILING_OFFSET; - } + dired.padding += total_len + DIRED_TRAILING_OFFSET; } // when using -R, we have the dirname. we need to add it to the padding @@ -156,7 +147,7 @@ pub fn update_positions(dired: &mut DiredOutput, start: usize, end: usize, line_ start: start + padding, end: end + padding, }); - dired.line_offset = dired.line_offset + padding + line_len; + dired.line_offset += padding + line_len; // Remove the previous padding dired.padding = 0; } diff --git a/src/uu/ls/src/display.rs b/src/uu/ls/src/display.rs index 1695eefc566..929ce7e4610 100644 --- a/src/uu/ls/src/display.rs +++ b/src/uu/ls/src/display.rs @@ -557,10 +557,6 @@ fn display_additional_leading_info( Ok(()) } -fn calculate_line_len(output_len: usize, item_len: usize) -> usize { - output_len + item_len + 1 // line ending -} - // Currently getpwuid is `linux` target only. If it's broken state.out into // a posix-compliant attribute this can be updated... #[cfg(unix)] @@ -1210,7 +1206,7 @@ fn update_dired_for_item( displayed_len: usize, dired_name_len: usize, ) { - let line_len = calculate_line_len(output_display_len, displayed_len); + let line_len = output_display_len + displayed_len + 1; // +1 for line ending dired::calculate_and_update_positions(dired, output_display_len, dired_name_len, line_len); }