rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Recorded content not expected for captured prints

Open jylind opened this issue 3 years ago • 2 comments

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

jylind avatar Oct 04 '22 19:10 jylind

From just five minutes looking into this, I think issue #2172 might be relevant here with different expectations for recorded content.

TomJGooding avatar Jun 11 '24 21:06 TomJGooding

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

github-actions[bot] avatar Aug 26 '24 14:08 github-actions[bot]