Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ fn parse_indicator_codes() -> (FxHashMap<Indicator, String>, 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);
Expand Down
15 changes: 3 additions & 12 deletions src/uu/ls/src/dired.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BytePosition>) {
fn print_positions(prefix: &str, positions: &[BytePosition]) {
print!("{prefix}");
for c in positions {
print!(" {c}");
Expand All @@ -117,16 +117,7 @@ fn print_positions(prefix: &str, positions: &Vec<BytePosition>) {
}

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch :)

}

// when using -R, we have the dirname. we need to add it to the padding
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions src/uu/ls/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
}

Expand Down
Loading