diff options
Diffstat (limited to 'sphinx')
-rw-r--r-- | sphinx/util/display.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/sphinx/util/display.py b/sphinx/util/display.py index 99b76599a..f0e016c3a 100644 --- a/sphinx/util/display.py +++ b/sphinx/util/display.py @@ -5,7 +5,7 @@ from typing import Any, Callable, Iterable, Iterator, TypeVar from sphinx.locale import __ from sphinx.util import logging -from sphinx.util.console import bold, colorize, term_width_line # type: ignore +from sphinx.util.console import bold # type: ignore if False: from types import TracebackType @@ -32,20 +32,26 @@ def status_iterator( verbosity: int = 0, stringify_func: Callable[[Any], str] = display_chunk, ) -> Iterator[T]: + single_line = verbosity < 1 + bold_summary = bold(summary) if length == 0: - logger.info(bold(summary), nonl=True) - for i, item in enumerate(iterable, start=1): - item_str = colorize(color, stringify_func(item)) - if length == 0: - logger.info(item_str, nonl=True) - logger.info(' ', nonl=True) - else: - s = f'{bold(summary)}[{int(100 * i / length): >3d}%] {item_str}' - if verbosity: - logger.info(s + '\n', nonl=True) - else: - logger.info(term_width_line(s), nonl=True) - yield item + logger.info(bold_summary, nonl=True) + for item in iterable: + logger.info(stringify_func(item) + ' ', nonl=True, color=color) + yield item + else: + for i, item in enumerate(iterable, start=1): + if single_line: + # clear the entire line ('Erase in Line') + logger.info('\x1b[2K', nonl=True) + logger.info(f'{bold_summary}[{i / length: >4.0%}] ', nonl=True) # NoQA: G004 + # Emit the string representation of ``item`` + logger.info(stringify_func(item), nonl=True, color=color) + # If in single-line mode, emit a carriage return to move the cursor + # to the start of the line. + # If not, emit a newline to move the cursor to the next line. + logger.info('\r' * single_line, nonl=single_line) + yield item logger.info('') |