From ab82a7877718548bbe6af297083e1226ab2743f3 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Sat, 2 Jan 2016 12:07:24 -0600 Subject: [PATCH] (GH-525) Improve Write-Progress As a continuation of GH-8, download progress should be written inline, but needs some improvements: - Write an empty line when it has completed so that the next log item doesn't write to the same line. - Improve the content of the progress message with both percentage and the status message. --- .../powershell/PoshHostUserInterface.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs b/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs index 8e62ba155e..40d0f548bd 100644 --- a/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs +++ b/src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs @@ -118,14 +118,27 @@ public override void WriteDebugLine(string message) this.Log().Debug(message); } + private bool hasLoggedStartProgress = false; + private bool hasLoggedFinalProgress = false; public override void WriteProgress(long sourceId, ProgressRecord record) - { + { if (record.PercentComplete == -1) return; - - if (record.PercentComplete == 100) this.Log().Debug(() => "Progress: 100%{0}".format_with(" ".PadRight(20))); + if (hasLoggedFinalProgress) return; + if (!hasLoggedStartProgress) + { + hasLoggedStartProgress = true; + this.Log().Debug(record.Activity); + } // http://stackoverflow.com/a/888569/18475 - Console.Write("\rProgress: {0}%{1}".format_with(record.PercentComplete, " ".PadRight(20))); + Console.Write("\rProgress: {0}% - {1}".format_with(record.PercentComplete.to_string(), record.StatusDescription.PadRight(50, ' '))); + + if (record.PercentComplete == 100 && !hasLoggedFinalProgress) + { + hasLoggedFinalProgress = true; + this.Log().Info(""); + this.Log().Info(record.StatusDescription.Replace("Saving","Finished downloading. Saved")); + } } public override void WriteVerboseLine(string message)