1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

df: remove trailing spaces in rightmost column

This commit is contained in:
Daniel Hofstetter 2022-04-18 14:30:20 +02:00
parent 346902e30b
commit 576ec49fa5
2 changed files with 15 additions and 6 deletions

View file

@ -400,12 +400,21 @@ impl fmt::Display for Table {
while let Some(row) = row_iter.next() {
let mut col_iter = row.iter().enumerate().peekable();
while let Some((i, elem)) = col_iter.next() {
let is_last_col = col_iter.peek().is_none();
match self.alignments[i] {
Alignment::Left => write!(f, "{:<width$}", elem, width = self.widths[i])?,
Alignment::Left => {
if is_last_col {
// no trailing spaces in last column
write!(f, "{}", elem)?;
} else {
write!(f, "{:<width$}", elem, width = self.widths[i])?;
}
}
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
}
if col_iter.peek().is_some() {
if !is_last_col {
// column separator
write!(f, " ")?;
}

View file

@ -349,7 +349,7 @@ fn test_output_selects_columns() {
.args(&["--output=source"])
.succeeds()
.stdout_move_str();
assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem");
assert_eq!(output.lines().next().unwrap(), "Filesystem");
let output = new_ucmd!()
.args(&["--output=source,target"])