Skip to content

Commit

Permalink
ls: when -CF is passed, use a tab. closes: #5396
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jul 4, 2024
1 parent a18c132 commit fd2c4a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ fn display_grid(
writeln!(out)?;
}
} else {
let names = if quoted {
let names: Vec<String> = if quoted {
// In case some names are quoted, GNU adds a space before each
// entry that does not start with a quote to make it prettier
// on multiline.
Expand All @@ -2675,12 +2675,21 @@ fn display_grid(
} else {
names.collect()
};

// Determine whether to use tabs for separation based on whether any entry ends with '/'.
// If any entry ends with '/', it indicates that the -F flag is likely used to classify directories.
let use_tabs = names.iter().any(|name| name.ends_with('/'));

let filling = if use_tabs {
Filling::Text("\t".to_string())
} else {
Filling::Spaces(2)
};

let grid = Grid::new(
names,
GridOptions {
// TODO: To match gnu/tests/ls/stat-dtype.sh
// we might want to have Filling::Text("\t".to_string());
filling: Filling::Spaces(2),
filling,
direction,
width: width as usize,
},
Expand Down
1 change: 0 additions & 1 deletion tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4259,7 +4259,6 @@ fn test_ls_subdired_complex() {
assert_eq!(dirnames, vec!["dir1", "dir1\\c2", "dir1\\d"]);
}

#[ignore = "issue #5396"]
#[test]
fn test_ls_cf_output_should_be_delimited_by_tab() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down

0 comments on commit fd2c4a1

Please sign in to comment.