Permalink
Browse files

df: displaying sizes in 1K blocks and not bytes anymore

  • Loading branch information...
1 parent 32667e7 commit 79250e5cf561945ec4354599bd609582f71bcd28 @bzzn bzzn committed Nov 9, 2011
Showing with 18 additions and 17 deletions.
  1. +18 −17 df/DriveSummary.cs
View
@@ -77,8 +77,11 @@ public DriveSummary(IEnumerable<IDrive> drives, bool humanReadable, bool printFi
{
this.drives = drives;
var columnFormats = new ColumnFormats();
+ columnNames = new [] { "Drive", "Type", "1K-blocks", "Used", "Avail", "Use" };
+
if (humanReadable)
{
+ columnNames[2] = "Size";
columnFormats = columnFormats.WithHumanReadableFormat();
formatProvider = new FileSizeFormatProvider();
}
@@ -89,18 +92,18 @@ public DriveSummary(IEnumerable<IDrive> drives, bool humanReadable, bool printFi
headerFormatDefinition = columnFormats.CreateHeader();
formatDefinition = columnFormats.CreateColumn();
- columnType = drive => {
- return string.Format(
- formatProvider,
- formatDefinition,
- drive.Letter,
- drive.Format,
- drive.Size,
- drive.Used,
- drive.Free,
- PercentUsedOf(drive)
- );
- };
+ var oneKilobyte = 1024;
+ columnType = drive =>
+ string.Format(
+ formatProvider,
+ formatDefinition,
+ drive.Letter,
+ drive.Format,
+ drive.Size / oneKilobyte,
+ drive.Used / oneKilobyte,
+ drive.Free / oneKilobyte,
+ PercentUsedOf(drive)
+ );
this.printFileSystemType = printFileSystemType;
}
@@ -111,25 +114,22 @@ public void DriveSummaryHumanReadable(IEnumerable<IDrive> drives, bool printFile
headerFormatDefinition = columnFormats.CreateColumn();
formatDefinition = columnFormats.CreateColumn();
columnType = drive =>
- {
- return string.Format(formatProvider, formatDefinition,
+ string.Format(formatProvider, formatDefinition,
drive.Letter,
drive.Format,
drive.Size,
drive.Used,
drive.Free,
PercentUsedOf(drive)
);
- };
return;
}
public string Render()
{
var summary = new StringBuilder();
- string[] names = { "Drive", "Type", "Size", "Used", "Avail", "Use" };
- summary.AppendLine(string.Format(headerFormatDefinition, names));
+ summary.AppendLine(string.Format(headerFormatDefinition, columnNames));
foreach (var drive in drives)
summary.AppendLine(columnType(drive));
return summary.ToString();
@@ -146,5 +146,6 @@ private int PercentUsedOf(IDrive drive)
private string headerFormatDefinition;
private bool printFileSystemType;
private FileSizeFormatProvider formatProvider;
+ private string[] columnNames;
}
}

0 comments on commit 79250e5

Please sign in to comment.