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:
@@ -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");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user