pkgman: Split "interactive" and "show progress" logic.

Previously we didn't show progress in non-interactive mode. Now
we do, so long as stdout is a TTY.

Fixes #14603.
This commit is contained in:
Augustin Cavalier
2019-05-13 19:32:30 -04:00
parent 7115cef989
commit 45c3eb3a3c
2 changed files with 7 additions and 3 deletions
+6 -3
View File
@@ -173,10 +173,13 @@ PackageManager::Warn(status_t error, const char* format, ...)
void void
PackageManager::ProgressPackageDownloadStarted(const char* packageName) PackageManager::ProgressPackageDownloadStarted(const char* packageName)
{ {
fShowProgress = isatty(STDOUT_FILENO);
fLastBytes = 0; fLastBytes = 0;
fLastRateCalcTime = system_time(); fLastRateCalcTime = system_time();
fDownloadRate = 0; fDownloadRate = 0;
printf(" 0%%");
if (fShowProgress)
printf(" 0%%");
} }
@@ -186,7 +189,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName,
{ {
if (bytes == totalBytes) if (bytes == totalBytes)
fLastBytes = totalBytes; fLastBytes = totalBytes;
if (!fInteractive) if (!fShowProgress)
return; return;
// Do not update if nothing changed in the last 500ms // Do not update if nothing changed in the last 500ms
@@ -258,7 +261,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName,
void void
PackageManager::ProgressPackageDownloadComplete(const char* packageName) PackageManager::ProgressPackageDownloadComplete(const char* packageName)
{ {
if (fInteractive) { if (fShowProgress) {
// Erase the line, return to the start, and reset colors // Erase the line, return to the start, and reset colors
printf("\r\33[2K\r\x1B[0m"); printf("\r\33[2K\r\x1B[0m");
} }
+1
View File
@@ -72,6 +72,7 @@ private:
fClientInstallationInterface; fClientInstallationInterface;
bool fInteractive; bool fInteractive;
bool fShowProgress;
off_t fLastBytes; off_t fLastBytes;
bigtime_t fLastRateCalcTime; bigtime_t fLastRateCalcTime;
float fDownloadRate; float fDownloadRate;