From bc6674c89e09a09850616b4b149eeba68fc0344d Mon Sep 17 00:00:00 2001 From: Emir SARI Date: Tue, 5 Mar 2024 21:46:47 +0300 Subject: [PATCH] pkgman: Use BNumberFormat for i18n Change-Id: I2441f1d37bfccd5f5dbc9b763aeb87d017e628bc Reviewed-on: https://review.haiku-os.org/c/haiku/+/7508 Haiku-Format: Haiku-format Bot Tested-by: Commit checker robot Reviewed-by: Adrien Destugues --- src/bin/pkgman/PackageManager.cpp | 23 ++++++++++++++++------- src/bin/pkgman/PackageManager.h | 3 +++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/bin/pkgman/PackageManager.cpp b/src/bin/pkgman/PackageManager.cpp index ba2ffcaef4..2560f351fc 100644 --- a/src/bin/pkgman/PackageManager.cpp +++ b/src/bin/pkgman/PackageManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2024, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -178,8 +178,12 @@ PackageManager::ProgressPackageDownloadStarted(const char* packageName) fLastRateCalcTime = system_time(); fDownloadRate = 0; - if (fShowProgress) - printf(" 0%%"); + if (fShowProgress) { + char percentString[32]; + fNumberFormat.FormatPercent(percentString, sizeof(percentString), 0.0); + // Make sure there is enough space for '100 %' percent format + printf("%6s", percentString); + } } @@ -215,10 +219,12 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName, if (width < 30) { // Not much space for anything, just draw a percentage - leftStr.SetToFormat("%3d%%", (int)(completionPercentage * 100)); + fNumberFormat.FormatPercent(leftStr, completionPercentage); } else { - leftStr.SetToFormat("%3d%% %s", (int)(completionPercentage * 100), - packageName); + BString dataString; + fNumberFormat.FormatPercent(dataString, completionPercentage); + // Make sure there is enough space for '100 %' percent format + leftStr.SetToFormat("%6s %s", dataString.String(), packageName); char byteBuffer[32]; char totalBuffer[32]; @@ -267,7 +273,10 @@ PackageManager::ProgressPackageDownloadComplete(const char* packageName) } char byteBuffer[32]; - printf("100%% %s [%s]\n", packageName, + char percentString[32]; + fNumberFormat.FormatPercent(percentString, sizeof(percentString), 1.0); + // Make sure there is enough space for '100 %' percent format + printf("%6s %s [%s]\n", percentString, packageName, string_for_size(fLastBytes, byteBuffer, sizeof(byteBuffer))); fflush(stdout); } diff --git a/src/bin/pkgman/PackageManager.h b/src/bin/pkgman/PackageManager.h index 3359b07cb5..fd26643c59 100644 --- a/src/bin/pkgman/PackageManager.h +++ b/src/bin/pkgman/PackageManager.h @@ -13,6 +13,8 @@ #include #include +#include + #include "DecisionProvider.h" @@ -68,6 +70,7 @@ private: private: DecisionProvider fDecisionProvider; + BNumberFormat fNumberFormat; BPackageManager::ClientInstallationInterface fClientInstallationInterface; bool fInteractive;