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:
parent
7115cef989
commit
45c3eb3a3c
@ -173,10 +173,13 @@ PackageManager::Warn(status_t error, const char* format, ...)
|
||||
void
|
||||
PackageManager::ProgressPackageDownloadStarted(const char* packageName)
|
||||
{
|
||||
fShowProgress = isatty(STDOUT_FILENO);
|
||||
fLastBytes = 0;
|
||||
fLastRateCalcTime = system_time();
|
||||
fDownloadRate = 0;
|
||||
printf(" 0%%");
|
||||
|
||||
if (fShowProgress)
|
||||
printf(" 0%%");
|
||||
}
|
||||
|
||||
|
||||
@ -186,7 +189,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||
{
|
||||
if (bytes == totalBytes)
|
||||
fLastBytes = totalBytes;
|
||||
if (!fInteractive)
|
||||
if (!fShowProgress)
|
||||
return;
|
||||
|
||||
// Do not update if nothing changed in the last 500ms
|
||||
@ -258,7 +261,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||
void
|
||||
PackageManager::ProgressPackageDownloadComplete(const char* packageName)
|
||||
{
|
||||
if (fInteractive) {
|
||||
if (fShowProgress) {
|
||||
// Erase the line, return to the start, and reset colors
|
||||
printf("\r\33[2K\r\x1B[0m");
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ private:
|
||||
fClientInstallationInterface;
|
||||
bool fInteractive;
|
||||
|
||||
bool fShowProgress;
|
||||
off_t fLastBytes;
|
||||
bigtime_t fLastRateCalcTime;
|
||||
float fDownloadRate;
|
||||
|
Loading…
Reference in New Issue
Block a user