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,31 +352,35 @@ 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") {
.iter() let names = items
.filter_map(|i| { .iter()
let md = get_metadata(i, options); .filter_map(|i| {
match md { let md = get_metadata(i, options);
Err(e) => { match md {
let filename = get_file_name(i, strip); Err(e) => {
show_error!("{}: {}", filename, e); let filename = get_file_name(i, strip);
None show_error!("{}: {}", filename, e);
None
}
Ok(md) => Some(display_file_name(&i, strip, &md, options)),
} }
Ok(md) => Some(display_file_name(&i, strip, &md, options)), });
if let Some(size) = termsize::get() {
let mut grid = Grid::new(GridOptions {
filling: Filling::Spaces(2),
direction: Direction::TopToBottom,
});
for name in names {
grid.add(name);
}
if let Some(output) = grid.fit_into_width(size.cols as usize) {
print!("{}", output);
return;
} }
})
.collect();
if let Some(size) = termsize::get() {
let mut grid = Grid::new(GridOptions {
filling: Filling::Spaces(2),
direction: Direction::TopToBottom,
});
for name in names {
grid.add(name);
}
if let Some(output) = grid.fit_into_width(size.cols as usize) {
print!("{}", output);
return;
} }
} }