hrev46164 adds 1 changeset to branch 'master' old head: 4ea76fdfa3f76c303dfb6120a6517dd98b1a6d7c new head: d3f4a86549823f80504a10118e7fc41f51f06a24 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=d3f4a86+%5E4ea76fd ---------------------------------------------------------------------------- d3f4a86: Implement #10051. - Add a simple download progress meter to pkgman that prints a hash mark for every 2% of the download completed. Improvements welcome. [ Rene Gollent <rene@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev46164 Commit: d3f4a86549823f80504a10118e7fc41f51f06a24 URL: http://cgit.haiku-os.org/haiku/commit/?id=d3f4a86 Author: Rene Gollent <rene@xxxxxxxxxxx> Date: Thu Oct 3 02:48:44 2013 UTC Ticket: https://dev.haiku-os.org/ticket/10051 ---------------------------------------------------------------------------- 2 files changed, 15 insertions(+), 3 deletions(-) src/bin/pkgman/PackageManager.cpp | 17 ++++++++++++++--- src/bin/pkgman/PackageManager.h | 1 + ---------------------------------------------------------------------------- diff --git a/src/bin/pkgman/PackageManager.cpp b/src/bin/pkgman/PackageManager.cpp index e4146c5..d85673f 100644 --- a/src/bin/pkgman/PackageManager.cpp +++ b/src/bin/pkgman/PackageManager.cpp @@ -27,7 +27,8 @@ PackageManager::PackageManager(BPackageInstallationLocation location) BPackageManager(location), BPackageManager::UserInteractionHandler(), fDecisionProvider(), - fClientInstallationInterface() + fClientInstallationInterface(), + fPreviousDownloadPercentage(0) { fInstallationInterface = &fClientInstallationInterface; fUserInteractionHandler = this; @@ -156,6 +157,7 @@ void PackageManager::ProgressPackageDownloadStarted(const char* packageName) { printf("Downloading %s...\n", packageName); + fPreviousDownloadPercentage = 0; } @@ -163,14 +165,23 @@ void PackageManager::ProgressPackageDownloadActive(const char* packageName, float completionPercentage) { - // TODO: how to report progress? ncurses perhaps? + int32 currentPercentage = int32(completionPercentage * 100); + int32 difference = currentPercentage - fPreviousDownloadPercentage; + + while (difference >= 2) { + printf("#"); + difference -= 2; + } + fflush(stdout); + + fPreviousDownloadPercentage = currentPercentage - difference; } void PackageManager::ProgressPackageDownloadComplete(const char* packageName) { - printf("Finished downloading %s...\n", packageName); + printf("\nFinished downloading %s.\n", packageName); } diff --git a/src/bin/pkgman/PackageManager.h b/src/bin/pkgman/PackageManager.h index 40191c7..0162046 100644 --- a/src/bin/pkgman/PackageManager.h +++ b/src/bin/pkgman/PackageManager.h @@ -67,6 +67,7 @@ private: DecisionProvider fDecisionProvider; BPackageManager::ClientInstallationInterface fClientInstallationInterface; + int32 fPreviousDownloadPercentage; };