aboutsummaryrefslogtreecommitdiff
path: root/src/libmain/progress-bar.cc
diff options
context:
space:
mode:
authorAlois Wohlschlager <alois1@gmx-topmail.de>2024-06-24 18:26:05 +0200
committerAlois Wohlschlager <alois1@gmx-topmail.de>2024-06-24 20:39:50 +0200
commit206a5dbb8f4606a1a7b8d0179e018880b9b92575 (patch)
tree280fd21f93625477328e4a2f78b96164f0e49a7e /src/libmain/progress-bar.cc
parentd86009bd76ae85e56e1d26aab26d38f90ecb6439 (diff)
libmain/progress-bar: move implementation out of the header
Change-Id: Ib4b42ebea290ee575294df6b2f17a38a5d850b80
Diffstat (limited to 'src/libmain/progress-bar.cc')
-rw-r--r--src/libmain/progress-bar.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc
index 28bb14863..e36bc0b01 100644
--- a/src/libmain/progress-bar.cc
+++ b/src/libmain/progress-bar.cc
@@ -13,6 +13,11 @@
namespace nix {
+// 100 years ought to be enough for anyone (yet sufficiently smaller than max() to not cause signed integer overflow).
+constexpr const auto A_LONG_TIME = std::chrono::duration_cast<std::chrono::milliseconds>(
+ 100 * 365 * std::chrono::seconds(86400)
+);
+
using namespace std::literals::chrono_literals;
static std::string_view getS(const std::vector<Logger::Field> & fields, size_t n)
@@ -36,6 +41,21 @@ static std::string_view storePathToName(std::string_view path)
return i == std::string::npos ? base.substr(0, 0) : base.substr(i + 1);
}
+ProgressBar::ProgressBar(bool isTTY)
+ : isTTY(isTTY)
+{
+ state_.lock()->active = isTTY;
+ updateThread = std::thread([&]() {
+ auto state(state_.lock());
+ auto nextWakeup = A_LONG_TIME;
+ while (state->active) {
+ if (!state->haveUpdate)
+ state.wait_for(updateCV, nextWakeup);
+ nextWakeup = draw(*state, {});
+ state.wait_for(quitCV, std::chrono::milliseconds(50));
+ }
+ });
+}
ProgressBar::~ProgressBar()
{