diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:05:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:05:54 +0000 |
commit | f768fbfe45055f9ab5260ee04bb4c2706bfd6e44 (patch) | |
tree | 8b11d8fa50d831770d3eeb4d01abf67b9e598572 /apt-pkg/install-progress.cc | |
parent | Adding upstream version 2.9.0. (diff) | |
download | apt-f768fbfe45055f9ab5260ee04bb4c2706bfd6e44.tar.xz apt-f768fbfe45055f9ab5260ee04bb4c2706bfd6e44.zip |
Adding upstream version 2.9.1.upstream/2.9.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'apt-pkg/install-progress.cc')
-rw-r--r-- | apt-pkg/install-progress.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/apt-pkg/install-progress.cc b/apt-pkg/install-progress.cc index 2b0dc21..fe33244 100644 --- a/apt-pkg/install-progress.cc +++ b/apt-pkg/install-progress.cc @@ -13,6 +13,7 @@ #include <sstream> #include <vector> #include <fcntl.h> +#include <langinfo.h> #include <sys/ioctl.h> #include <unistd.h> @@ -344,14 +345,23 @@ void PackageManagerFancy::Stop() std::string PackageManagerFancy::GetTextProgressStr(float Percent, int OutputSize) { + bool Unicode = strcmp(nl_langinfo(CODESET), "UTF-8") == 0; std::string output; if (unlikely(OutputSize < 3)) return 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)))); + double dummy; + double const BarDoneFractional = std::modf(Percent * BarSize, &dummy); + const char *const BarDoneFractionalChar = (const char *[]){ + " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"}[static_cast<int>(std::floor(BarDoneFractional * 8))]; output.append("["); - std::fill_n(std::fill_n(std::back_inserter(output), BarDone, '#'), BarSize - BarDone, '.'); + for (int i = 0; i < BarDone; i++) + output.append(Unicode ? "█" : "#"); + if (BarDone + 1 <= BarSize) + output.append(Unicode ? BarDoneFractionalChar : "."); + std::fill_n(std::back_inserter(output), BarSize - BarDone - 1, Unicode ? ' ' : '.'); output.append("]"); return output; } |