Skip to content

Commit 8d8e3db

Browse files
committed
Other: Reformat the 'space' command output.
1 parent 43d7d4b commit 8d8e3db

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

G33kShell.Desktop/Terminal/Commands/SpaceCommand.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// about your modifications. Your contributions are valued!
99
//
1010
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11-
using System;
11+
1212
using System.IO;
1313
using System.Linq;
1414
using System.Threading.Tasks;
@@ -25,21 +25,10 @@ protected override Task<bool> Run(ITerminalState state)
2525
var drives = DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveType == DriveType.Fixed);
2626
foreach (var drive in drives)
2727
{
28-
var totalSpace = drive.TotalSize;
29-
var freeSpace = drive.AvailableFreeSpace;
30-
var usagePercentage = (double)(totalSpace - freeSpace) / totalSpace;
31-
32-
// Build the size string and calculate its length.
33-
var infoText = drive.TotalSize.ToSize();
34-
35-
// Progress bar width calculation.
36-
var totalWidth = state.CliPrompt.Width;
37-
var fixedTextWidth = drive.Name.Length + infoText.Length + 5;
38-
var progressWidth = totalWidth - fixedTextWidth;
39-
var filledWidth = (int)Math.Round(progressWidth * usagePercentage);
40-
41-
// Display drive info.
42-
WriteLine($"{drive.Name} [{new string('=', filledWidth).PadRight(progressWidth, '.')}] {infoText}");
28+
var usagePercent = (double)(drive.TotalSize - drive.AvailableFreeSpace) / drive.TotalSize;
29+
var s = $"[{drive.Name}] _ {usagePercent:P0}{drive.TotalSize.ToSize()}";
30+
s = s.Replace("_", usagePercent.ToProgressBar(state.CliPrompt.Width - s.Length));
31+
WriteLine(s);
4332
}
4433
return Task.FromResult(true);
4534
}

0 commit comments

Comments
 (0)