Skip to content
Myr

progressbar: add automatic full-width mode

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

authored by Armin Ronacher · committed by Armin Ronacher · parent aeb297c · Browse files · 2 files+18 added−1 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+18 added−1 removed

  • other:+18 added−1 removed

2 files+18 added−1 removed

modified:click/_termui_impl.py+16 added
64 unmodified lines
65 if file is None:66 file = _default_text_stdout()67 self.file = file68 self.width = width69 self.autowidth = width == 07071 if length is None:72 length = _length_hint(iterable)73 if iterable is None:
105 unmodified lines
179 'info': self.info_sep.join(info_bits)180 }).strip()181182 def render_progress(self):183 from .termui import get_terminal_size184185 if self.is_hidden:186 echo(self.label, file=self.file)187 self.file.flush()188 return189190 # Update width in case the terminal has been resized191 if self.autowidth:192 old_width = self.width193 self.width = 0194 clutter_length = len(strip_ansi(self.format_progress_line()))195 new_width = max(0, get_terminal_size()[0] - clutter_length)196 if new_width < old_width:197 self.file.write(BEFORE_BAR)198 self.file.write(' ' * self.max_width)199 self.max_width = new_width200 self.width = new_width201202 clear_width = self.width203 if self.max_width is not None:204 clear_width = self.max_width205206 self.file.write(BEFORE_BAR)207 line = self.format_progress_line()208 line_len = len(strip_ansi(line))209 if self.max_width is None or self.max_width < line_len:
278 unmodified lines
modified:click/termui.py+2 added-1 removed
242 unmodified lines
243 The parameters in it are ``label`` for the label,244 ``bar`` for the progress bar and ``info`` for the245 info section.246 :param info_sep: the separator between multiple info items (eta etc.)247 :param width: the width of the progress bar in characters.247 :param width: the width of the progress bar in characters, 0 means full248 terminal width249 :param file: the file to write to. If this is not a terminal then250 only the label is printed.251 """252 from ._termui_impl import ProgressBar
211 unmodified lines