1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #1177 from mmstick/ls-column

[ls] Add "-1" Flag & Fix Needless Vec
This commit is contained in:
Alex Lyon 2018-04-10 20:52:04 -07:00 committed by GitHub
commit fc7b1fcaba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,6 +82,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
NAME NAME
); );
let matches = new_coreopts!(&syntax, SUMMARY, LONG_HELP) let matches = new_coreopts!(&syntax, SUMMARY, LONG_HELP)
.optflag("1", "", "list one file per line.")
.optflag( .optflag(
"a", "a",
"all", "all",
@ -351,7 +352,8 @@ fn display_items(items: &Vec<PathBuf>, strip: Option<&Path>, options: &getopts::
display_item_long(item, strip, max_links, max_size, options); display_item_long(item, strip, max_links, max_size, options);
} }
} else { } else {
let names: Vec<_> = items if !options.opt_present("1") {
let names = items
.iter() .iter()
.filter_map(|i| { .filter_map(|i| {
let md = get_metadata(i, options); let md = get_metadata(i, options);
@ -363,21 +365,24 @@ fn display_items(items: &Vec<PathBuf>, strip: Option<&Path>, options: &getopts::
} }
Ok(md) => Some(display_file_name(&i, strip, &md, options)), Ok(md) => Some(display_file_name(&i, strip, &md, options)),
} }
}) });
.collect();
if let Some(size) = termsize::get() { if let Some(size) = termsize::get() {
let mut grid = Grid::new(GridOptions { let mut grid = Grid::new(GridOptions {
filling: Filling::Spaces(2), filling: Filling::Spaces(2),
direction: Direction::TopToBottom, direction: Direction::TopToBottom,
}); });
for name in names { for name in names {
grid.add(name); grid.add(name);
} }
if let Some(output) = grid.fit_into_width(size.cols as usize) { if let Some(output) = grid.fit_into_width(size.cols as usize) {
print!("{}", output); print!("{}", output);
return; return;
} }
} }
}
// Couldn't display a grid, either because we don't know // Couldn't display a grid, either because we don't know
// the terminal width or because fit_into_width failed // the terminal width or because fit_into_width failed