| 254 | ).rstrip() |
| 255 | |
| 256 | def render_progress(self) -> None: |
| 257 | if self.hidden: |
| 258 | return |
| 259 | |
| 260 | if not self._is_atty: |
| 261 | class="cm"># Only output the label once if the output is not a TTY. |
| 262 | if self._last_line != self.label: |
| 263 | self._last_line = self.label |
| 264 | echo(self.label, file=self.file, color=self.color) |
| 265 | return |
| 266 | |
| 267 | buf = [] |
| 268 | class="cm"># Update width in case the terminal has been resized |
| 269 | if self.autowidth: |
| 270 | import shutil |
| 271 | |
| 272 | old_width = self.width |
| 273 | self.width = 0 |
| 274 | clutter_length = term_len(self.format_progress_line()) |
| 275 | new_width = max(0, shutil.get_terminal_size().columns - clutter_length) |
| 276 | if new_width < old_width and self.max_width is not None: |
| 277 | buf.append(BEFORE_BAR) |
| 278 | buf.append(class="st">" " * self.max_width) |
| 279 | self.max_width = new_width |
| 280 | self.width = new_width |
| 281 | |
| 282 | clear_width = self.width |
| 283 | if self.max_width is not None: |
| 284 | clear_width = self.max_width |
| 285 | |
| 286 | buf.append(BEFORE_BAR) |
| 287 | line = self.format_progress_line() |
| 288 | line_len = term_len(line) |
| 289 | if self.max_width is None or self.max_width < line_len: |
| 290 | self.max_width = line_len |
| 291 | |
| 292 | buf.append(line) |
| 293 | buf.append(class="st">" " * (clear_width - line_len)) |
| 294 | line = class="st">"".join(buf) |
| 295 | class="cm"># Render the line only if it changed. |
| 296 | |
| 297 | if line != self._last_line: |
| 298 | self._last_line = line |
| 299 | echo(line, file=self.file, color=self.color, nl=False) |
| 300 | self.file.flush() |
| 301 | |
| 302 | def make_step(self, n_steps: int) -> None: |
| 303 | self.pos += n_steps |