Skip to content

[BUG] Recorded content not expected for captured prints #2563

@jylind

Description

@jylind

Describe the bug

The following code:

    console = Console(record=True)
    print("Before Capture started:")
    console.print("[blue underline]Print 0")
    with console.capture() as capture:
        console.print("[blue underline]Print 1")
        console.print("[blue underline]Print 2")
        console.print("[blue underline]Print 3")
        console.print("[blue underline]Print 4")
    print("\nCaptured content:")
    print(capture.get())
    print("\nRecorded content:")
    print(console.export_text())

Produces following output:

Recording error

It seems that every print to capture adds previously printed content + new content.

I also wonder if the captured content should even go to the recording because it won't even go to console unless specifically printed there after capturing has been stopped.

Though, as it seems that captured content cannot be printed with console.print() (control codes seems to becomes visible) so by using regular python print() would not put it in the recording either.
(Line print(capture.get()) replaced with console.print(capture.get()))

Recording error - capture print

Platform

Click to expand

Same with Win/Linux platforms.
Windows terminal: Cmd prompt, Windows Terminal.
Linux Terminal: Putty

Using Rich version 12.6.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions