pkgman: better download progress bar
* Use Unicode block drawing characters to provide sub-character accuracy * Also display the download progress percentage as a number When downloading big packages this helps seeing that the bar continues moving and that the download is not stalled.
This commit is contained in:
parent
a5ce4678c0
commit
87d0590f60
@ -30,7 +30,6 @@ PackageManager::PackageManager(BPackageInstallationLocation location,
|
|||||||
BPackageManager::UserInteractionHandler(),
|
BPackageManager::UserInteractionHandler(),
|
||||||
fDecisionProvider(interactive),
|
fDecisionProvider(interactive),
|
||||||
fClientInstallationInterface(),
|
fClientInstallationInterface(),
|
||||||
fPreviousDownloadPercentage(0),
|
|
||||||
fInteractive(interactive)
|
fInteractive(interactive)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -172,7 +171,6 @@ void
|
|||||||
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
||||||
{
|
{
|
||||||
printf("Downloading %s...\n", packageName);
|
printf("Downloading %s...\n", packageName);
|
||||||
fPreviousDownloadPercentage = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,16 +178,42 @@ void
|
|||||||
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||||
float completionPercentage)
|
float completionPercentage)
|
||||||
{
|
{
|
||||||
int32 currentPercentage = int32(completionPercentage * 100);
|
static const char* progressChars[] = {
|
||||||
int32 difference = currentPercentage - fPreviousDownloadPercentage;
|
"\xE2\x96\x8F",
|
||||||
|
"\xE2\x96\x8E",
|
||||||
|
"\xE2\x96\x8D",
|
||||||
|
"\xE2\x96\x8C",
|
||||||
|
"\xE2\x96\x8B",
|
||||||
|
"\xE2\x96\x8A",
|
||||||
|
"\xE2\x96\x89",
|
||||||
|
"\xE2\x96\x88",
|
||||||
|
};
|
||||||
|
|
||||||
while (difference >= 2) {
|
const int width = 70;
|
||||||
printf("#");
|
|
||||||
difference -= 2;
|
int position;
|
||||||
|
int ipart = (int)(completionPercentage * width);
|
||||||
|
int fpart = (int)(((completionPercentage * width) - ipart) * 8);
|
||||||
|
|
||||||
|
printf("\r"); // erase the line
|
||||||
|
|
||||||
|
for (position = 0; position < width; position++) {
|
||||||
|
if (position < ipart) {
|
||||||
|
// This part is fully downloaded, show a full block
|
||||||
|
printf(progressChars[7]);
|
||||||
|
} else if (position > ipart) {
|
||||||
|
// This part is not downloaded, show a space
|
||||||
|
printf(" ");
|
||||||
|
} else {
|
||||||
|
// This part is partially downloaded
|
||||||
|
printf(progressChars[fpart]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
fPreviousDownloadPercentage = currentPercentage - difference;
|
// Also print the progress percentage
|
||||||
|
printf(" %d%%", (int)(completionPercentage * 100));
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@ private:
|
|||||||
DecisionProvider fDecisionProvider;
|
DecisionProvider fDecisionProvider;
|
||||||
BPackageManager::ClientInstallationInterface
|
BPackageManager::ClientInstallationInterface
|
||||||
fClientInstallationInterface;
|
fClientInstallationInterface;
|
||||||
int32 fPreviousDownloadPercentage;
|
|
||||||
bool fInteractive;
|
bool fInteractive;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user