From c935ad3f025d5c3d8026711a1eb50b2917b61d59 Mon Sep 17 00:00:00 2001 From: Harald van Dijk Date: Sun, 3 Nov 2019 21:46:59 +0000 Subject: [PATCH] Fix progress bar when nix-prefetch-url is piped. The intent of the code was that if the window size cannot be determined, it would be treated as having the maximum possible size. Because of a missing assignment, it was actually treated as having a width of 0. The reason the width could not be determined was because it was obtained from stdout, not stderr, even though the printing was done to stderr. This commit addresses both issues. --- src/libutil/util.cc | 2 +- src/nix/progress-bar.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 2a1272885..d29802bcd 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1467,7 +1467,7 @@ static Sync> windowSize{{0, 0}}; static void updateWindowSize() { struct winsize ws; - if (ioctl(1, TIOCGWINSZ, &ws) == 0) { + if (ioctl(2, TIOCGWINSZ, &ws) == 0) { auto windowSize_(windowSize.lock()); windowSize_->first = ws.ws_row; windowSize_->second = ws.ws_col; diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc index 5c05d6b22..661966733 100644 --- a/src/nix/progress-bar.cc +++ b/src/nix/progress-bar.cc @@ -341,7 +341,7 @@ public: } auto width = getWindowSize().second; - if (width <= 0) std::numeric_limits::max(); + if (width <= 0) width = std::numeric_limits::max(); writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K"); }