diff options
Diffstat (limited to 'progress.py')
-rw-r--r-- | progress.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/progress.py b/progress.py index 69c95927..f2edf144 100644 --- a/progress.py +++ b/progress.py | |||
@@ -23,7 +23,7 @@ except ImportError: | |||
23 | 23 | ||
24 | from repo_trace import IsTraceToStderr | 24 | from repo_trace import IsTraceToStderr |
25 | 25 | ||
26 | _NOT_TTY = not os.isatty(2) | 26 | _TTY = sys.stderr.isatty() |
27 | 27 | ||
28 | # This will erase all content in the current line (wherever the cursor is). | 28 | # This will erase all content in the current line (wherever the cursor is). |
29 | # It does not move the cursor, so this is usually followed by \r to move to | 29 | # It does not move the cursor, so this is usually followed by \r to move to |
@@ -97,7 +97,8 @@ class Progress(object): | |||
97 | self._start = time.time() | 97 | self._start = time.time() |
98 | self._show = not delay | 98 | self._show = not delay |
99 | self._units = units | 99 | self._units = units |
100 | self._elide = elide | 100 | self._elide = elide and _TTY |
101 | |||
101 | # Only show the active jobs section if we run more than one in parallel. | 102 | # Only show the active jobs section if we run more than one in parallel. |
102 | self._show_jobs = False | 103 | self._show_jobs = False |
103 | self._active = 0 | 104 | self._active = 0 |
@@ -129,7 +130,7 @@ class Progress(object): | |||
129 | def _write(self, s): | 130 | def _write(self, s): |
130 | s = "\r" + s | 131 | s = "\r" + s |
131 | if self._elide: | 132 | if self._elide: |
132 | col = os.get_terminal_size().columns | 133 | col = os.get_terminal_size(sys.stderr.fileno()).columns |
133 | if len(s) > col: | 134 | if len(s) > col: |
134 | s = s[: col - 1] + ".." | 135 | s = s[: col - 1] + ".." |
135 | sys.stderr.write(s) | 136 | sys.stderr.write(s) |
@@ -157,7 +158,7 @@ class Progress(object): | |||
157 | msg = self._last_msg | 158 | msg = self._last_msg |
158 | self._last_msg = msg | 159 | self._last_msg = msg |
159 | 160 | ||
160 | if _NOT_TTY or IsTraceToStderr(): | 161 | if not _TTY or IsTraceToStderr(): |
161 | return | 162 | return |
162 | 163 | ||
163 | elapsed_sec = time.time() - self._start | 164 | elapsed_sec = time.time() - self._start |
@@ -199,7 +200,7 @@ class Progress(object): | |||
199 | 200 | ||
200 | def end(self): | 201 | def end(self): |
201 | self._update_event.set() | 202 | self._update_event.set() |
202 | if _NOT_TTY or IsTraceToStderr() or not self._show: | 203 | if not _TTY or IsTraceToStderr() or not self._show: |
203 | return | 204 | return |
204 | 205 | ||
205 | duration = duration_str(time.time() - self._start) | 206 | duration = duration_str(time.time() - self._start) |