Skip to content

Commit 6cc3eda

Browse files
committed
df: table: Print raw bytes
Final step, let's just print the raw bytes now.
1 parent 439cf79 commit 6cc3eda

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/uu/df/src/table.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use uucore::fsext::{FsUsage, MountInfo};
1717
use uucore::locale::get_message;
1818

1919
use std::ffi::OsString;
20+
use std::iter;
2021
use std::ops::AddAssign;
2122

2223
/// A row in the filesystem usage data table.
@@ -486,28 +487,28 @@ impl Table {
486487
for row in &self.rows {
487488
let mut col_iter = row.iter().enumerate().peekable();
488489
while let Some((i, elem)) = col_iter.next() {
489-
// TODO: Fix this, and print the bytes directly.
490-
let elem = String::from_utf8(elem.bytes.clone()).unwrap_or("meh?".to_string());
491490
let is_last_col = col_iter.peek().is_none();
492491

492+
let pad_width = self.widths[i].saturating_sub(elem.width);
493493
match self.alignments.get(i) {
494494
Some(Alignment::Left) => {
495-
if is_last_col {
496-
// no trailing spaces in last column
497-
write!(writer, "{elem}")?;
498-
} else {
499-
write!(writer, "{elem:<width$}", width = self.widths[i])?;
495+
writer.write_all(&elem.bytes)?;
496+
// no trailing spaces in last column
497+
if !is_last_col {
498+
writer
499+
.write_all(&iter::repeat_n(b' ', pad_width).collect::<Vec<_>>())?;
500500
}
501501
}
502502
Some(Alignment::Right) => {
503-
write!(writer, "{elem:>width$}", width = self.widths[i])?;
503+
writer.write_all(&iter::repeat_n(b' ', pad_width).collect::<Vec<_>>())?;
504+
writer.write_all(&elem.bytes)?;
504505
}
505506
None => break,
506507
}
507508

508509
if !is_last_col {
509510
// column separator
510-
write!(writer, " ")?;
511+
writer.write_all(b" ")?;
511512
}
512513
}
513514

0 commit comments

Comments
 (0)