mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 09:48:03 +00:00
df: remove trailing spaces in rightmost column
This commit is contained in:
parent
346902e30b
commit
576ec49fa5
2 changed files with 15 additions and 6 deletions
|
@ -400,12 +400,21 @@ impl fmt::Display for Table {
|
||||||
while let Some(row) = row_iter.next() {
|
while let Some(row) = row_iter.next() {
|
||||||
let mut col_iter = row.iter().enumerate().peekable();
|
let mut col_iter = row.iter().enumerate().peekable();
|
||||||
while let Some((i, elem)) = col_iter.next() {
|
while let Some((i, elem)) = col_iter.next() {
|
||||||
|
let is_last_col = col_iter.peek().is_none();
|
||||||
|
|
||||||
match self.alignments[i] {
|
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])?,
|
Alignment::Right => write!(f, "{:>width$}", elem, width = self.widths[i])?,
|
||||||
}
|
}
|
||||||
|
|
||||||
if col_iter.peek().is_some() {
|
if !is_last_col {
|
||||||
// column separator
|
// column separator
|
||||||
write!(f, " ")?;
|
write!(f, " ")?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,7 +349,7 @@ fn test_output_selects_columns() {
|
||||||
.args(&["--output=source"])
|
.args(&["--output=source"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_move_str();
|
.stdout_move_str();
|
||||||
assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem");
|
assert_eq!(output.lines().next().unwrap(), "Filesystem");
|
||||||
|
|
||||||
let output = new_ucmd!()
|
let output = new_ucmd!()
|
||||||
.args(&["--output=source,target"])
|
.args(&["--output=source,target"])
|
||||||
|
@ -408,7 +408,7 @@ fn test_output_file_all_filesystems() {
|
||||||
let mut lines = output.lines();
|
let mut lines = output.lines();
|
||||||
assert_eq!(lines.next().unwrap(), "File");
|
assert_eq!(lines.next().unwrap(), "File");
|
||||||
for line in lines {
|
for line in lines {
|
||||||
assert_eq!(line, "- ");
|
assert_eq!(line, "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ fn test_output_file_specific_files() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_move_str();
|
.stdout_move_str();
|
||||||
let actual: Vec<&str> = output.lines().collect();
|
let actual: Vec<&str> = output.lines().collect();
|
||||||
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
|
assert_eq!(actual, vec!["File", "a", "b", "c"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -448,5 +448,5 @@ fn test_nonexistent_file() {
|
||||||
.args(&["--output=file", "does-not-exist", "."])
|
.args(&["--output=file", "does-not-exist", "."])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_is("df: does-not-exist: No such file or directory\n")
|
.stderr_is("df: does-not-exist: No such file or directory\n")
|
||||||
.stdout_is("File\n. \n");
|
.stdout_is("File\n.\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue