Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jylind opened this issue Oct 4, 2022 · 2 comments · Fixed by #3470
Closed

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

jylind opened this issue Oct 4, 2022 · 2 comments · Fixed by #3470

Comments

@jylind
Copy link

jylind commented Oct 4, 2022

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

@TomJGooding
Copy link
Contributor

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

Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants