diff options
author | Julian Andres Klode <jak@debian.org> | 2016-08-18 10:02:35 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-08-18 10:02:35 +0200 |
commit | d1fd09b982f6108dc32ec75330b0535236c48311 (patch) | |
tree | c0dce6cf7501c1e0d5e3bad34e9b63c0d6dcd354 /apt-pkg/install-progress.cc | |
parent | b5fcba3682581b2a48921cc830dbf3deae6b0ff3 (diff) | |
parent | 43670e2ef8b689d9efba633d11d2a5fc6f9968a0 (diff) |
Merge tag '1.3_rc2' into ubuntu
apt Debian release 1.3~rc2
Diffstat (limited to 'apt-pkg/install-progress.cc')
-rw-r--r-- | apt-pkg/install-progress.cc | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc index c77c240c3..be5b8b5c7 100644 --- a/apt-pkg/install-progress.cc +++ b/apt-pkg/install-progress.cc @@ -14,6 +14,7 @@ #include <algorithm> #include <stdio.h> #include <sstream> +#include <cmath> #include <apti18n.h> @@ -321,19 +322,14 @@ std::string PackageManagerFancy::GetTextProgressStr(float Percent, int OutputSize) { std::string output; - int i; - - // should we raise a exception here instead? - if (Percent < 0.0 || Percent > 1.0 || OutputSize < 3) + if (unlikely(OutputSize < 3)) return output; - - int BarSize = OutputSize - 2; // bar without the leading "[" and trailing "]" - output += "["; - for(i=0; i < BarSize*Percent; i++) - output += "#"; - for (/*nothing*/; i < BarSize; i++) - output += "."; - output += "]"; + + int const BarSize = OutputSize - 2; // bar without the leading "[" and trailing "]" + int const BarDone = std::max(0, std::min(BarSize, static_cast<int>(std::floor(Percent * BarSize)))); + output.append("["); + std::fill_n(std::fill_n(std::back_inserter(output), BarDone, '#'), BarSize - BarDone, '.'); + output.append("]"); return output; } |