Skip to content
Myr

Merge pull request #863 from georgeyk/progressbar-to-stderr

Before adoption: this commit came in with the history the project adopted, so no landing records it.

ProgressBar should use stderr by default

authored by Dan Sully · committed by GitHub · parents 19d5273, 2a49ba9 · Browse files · 2 files+38 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+38 added−28 removed

  • tests:+13 added−0 removed
  • other:+25 added−28 removed

2 files+38 added−28 removed

modified:click/_termui_impl.py+25 added-28 removed
190 unmodified lines
191 }).rstrip()192193 def render_progress(self):194 from .termui import get_terminal_size195 nl = False195196 if self.is_hidden:198 buf = [self.label]199 nl = True200 else:201 buf = []202 # Update width in case the terminal has been resized203 if self.autowidth:204 old_width = self.width205 self.width = 0206 clutter_length = term_len(self.format_progress_line())207 new_width = max(0, get_terminal_size()[0] - clutter_length)208 if new_width < old_width:209 buf.append(BEFORE_BAR)210 buf.append(' ' * self.max_width)211 self.max_width = new_width212 self.width = new_width197 return198214 clear_width = self.width215 if self.max_width is not None:216 clear_width = self.max_width199 buf = []200 # Update width in case the terminal has been resized201 if self.autowidth:202 old_width = self.width203 self.width = 0204 clutter_length = term_len(self.format_progress_line())205 new_width = max(0, get_terminal_size()[0] - clutter_length)206 if new_width < old_width:207 buf.append(BEFORE_BAR)208 buf.append(' ' * self.max_width)209 self.max_width = new_width210 self.width = new_width211218 buf.append(BEFORE_BAR)219 line = self.format_progress_line()220 line_len = term_len(line)221 if self.max_width is None or self.max_width < line_len:222 self.max_width = line_len223 buf.append(line)212 clear_width = self.width213 if self.max_width is not None:214 clear_width = self.max_width215225 buf.append(' ' * (clear_width - line_len))226 line = ''.join(buf)216 buf.append(BEFORE_BAR)217 line = self.format_progress_line()218 line_len = term_len(line)219 if self.max_width is None or self.max_width < line_len:220 self.max_width = line_len221222 buf.append(line)223 buf.append(' ' * (clear_width - line_len))224 line = ''.join(buf)225 # Render the line only if it changed.226 if line != self._last_line:227 self._last_line = line231 echo(line, file=self.file, color=self.color, nl=nl)228 echo(line, file=self.file, color=self.color, nl=True)229 self.file.flush()230231 def make_step(self, n_steps):232 self.pos += n_steps
321 unmodified lines
modified:tests/test_termui.py+13 added
42 unmodified lines
43 result = runner.invoke(cli, [])44 assert result.exception is None454647def test_progressbar_hidden(runner, monkeypatch):48 label = 'whatever'4950 @click.command()51 def cli():52 with click.progressbar(tuple(range(10)), label=label) as progress:53 for thing in progress:54 pass5556 monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: False)57 assert runner.invoke(cli, []).output == ''585960def test_choices_list_in_prompt(runner, monkeypatch):61 @click.command()62 @click.option('-g', type=click.Choice(['none', 'day', 'week', 'month']),63 prompt=True)
21 unmodified lines