Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.67k stars 1.73k forks source link

[BUG] Progress documentation unclear #3240

Open gjsmo opened 11 months ago

gjsmo commented 11 months ago

Describe the bug

The documentation for Progress is incomplete, and does not mention the start() function anywhere. This is very confusing, as trying to use the class without calling start() (or using a context manager) produces no output. For example, the following does not work:

from time import sleep
from rich.progress import Progress

progress = Progress()

task = progress.add_task(description='test Progress', total=100)
for n in range(100):
    sleep(0.1)
    progress.advance(task, 1)
progress.remove_task(task)

Adding progress.start() after instantiating works, as well as the following:

from time import sleep
from rich.progress import Progress

with Progress() as progress:
    task = progress.add_task(description='test Progress', total=100)
    for n in range(100):
        sleep(0.1)
        progress.advance(task, 1)
    progress.remove_task(task)

It appears that start() is called in the __enter__ function, but nowhere is it mentioned that this should be called manually if not using a context manager. This should be clarified, or if the intended behavior is that a context manager is the ONLY acceptable method of using Progress(), then this should be documented as well, perhaps producing a warning if possible. It's worth noting that the documentation does say "The Progress class is designed to be used as a context manager which will start and stop the progress display automatically", however it doesn't indicate that failing to do so will cause no output.

It's worth noting that this same issue was encountered in #2758, and the developer there also indicated that the documentation was not clear.

Platform

Click to expand This occurs on *all platforms*, but my current environment is shown below. ``` ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = '256' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 56 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = True │ │ is_jupyter = False │ │ is_terminal = True │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=210, height=56), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=210, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=56, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=210, height=56) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 210 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ Windows features available. │ │ │ │ ╭───────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ ╰───────────────────────────────────────────────────╯ │ │ │ │ truecolor = False │ │ vt = False │ ╰───────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': 'tmux-256color', │ │ 'COLORTERM': None, │ │ 'CLICOLOR': None, │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': None, │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ platform="Linux" rich==13.7.0 ```
github-actions[bot] commented 11 months ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory