Textualize / rich

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

[BUG] Duplicated output while using console.capture() while recording #3100

Open mmcgugan opened 1 year ago

mmcgugan commented 1 year ago

Describe the bug

When capturing on a Console with recording enabled, everything printed to the console seems to get duplicated in the recorded output (but the output of the capture is fine).

An example:

from rich.console import Console
console = Console(record=True)
with console.capture() as capture:
    console.print("The first line")
    console.print("The second line")
    console.print("And the third line")

export = console.export_text()
cap = capture.get()

The value of "export" is:

The first line
The first line
The second line
The first line
The second line
And the third line

While "cap" is:

The first line
The second line
And the third line

It seems that each time I call console.print() it duplicates the whole contents of the buffer.

Is there maybe a step that I've missed here in setting up recording?

Platform

Click to expand Tried this on Windows 10 and Linux Ubuntu 20.04, using PowerShell and cmd through Windows Terminal. Python 3.11.4 and Rich 13.5.2. Output of rich.diagnose: ``` ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 25 │ │ 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=201, height=25), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=201, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=25, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=201, height=25) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 201 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭── ───╮ │ Windows features available. │ │ ╭─────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │ │ ╰─────────────────────────────────────────────────╯ │ │ │ │ truecolor = True │ │ vt = True │ ╰─────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': None, │ │ '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="Windows" ```
github-actions[bot] commented 1 year ago

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory