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

Exporting recorded output of a Live display can give empty results. #1723

Open
bmic86 opened this issue Jan 1, 2025 · 0 comments
Open

Exporting recorded output of a Live display can give empty results. #1723

bmic86 opened this issue Jan 1, 2025 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@bmic86
Copy link

bmic86 commented Jan 1, 2025

Hello everyone 👋. I was exploring this awesome library and started to improve my personal CLI tools with it, but unfortunately I have found an issue, which I wanted to share.

Information

  • OS: Windows
  • Version: 0.49.1
  • Terminal: Windows Terminal

Describe the bug
I have observed that live display of a table is not always properly recorded. For relatively small tables, when I call AnsiConsole.ExportText() after recording, it returns an empty string. However for large tables, it returns string with the full table output (as expected).

To Reproduce
Example C# program to simulate issue:

using Spectre.Console;

AnsiConsole.Record();

var table = new Table().Centered();

AnsiConsole
    .Live(table)
    .AutoClear(false)
    .Start(ctx =>
    {
        table.AddColumn("Foo");
        table.AddColumn("Bar");

        for (int i = 0; i < 5; i++)
        {
            table.AddRow($"Foo {i}", $"Bar {i}");
        }
    });


var text = AnsiConsole.ExportText();
Console.WriteLine(text);

Expected behavior
In the example the value of a text is empty, but should contain an exported table output (the expected result of the whole example program is to print the same table twice). When I increase number of rows to for ex. 50 or 100, it produces the expected result.

Additional context
I want to be able to save my program live outputs into a file. Piping live outputs from shell is not possible/supported, and it throws System.IO.IOException (as described in this issue comment: #1393 (comment)), so the only reasonable way to do it seems to be: record, export and save into a file.

Possible fix/workaround
I have looked into the source code and found that method LiveDisplayRenderer.Completed(bool autoclear) forces to redraw when overflow occurs, which causes, the output to be correctly recorded and exported for larger tables.
As a workaround solution I have created small fix that turn this redraw behavior on, every time when recorder has been registered. You can see it on my fork: main...bmic86:spectre.console:fix/recording_on_live


Please upvote 👍 this issue if you are interested in it.

@bmic86 bmic86 added bug Something isn't working needs triage labels Jan 1, 2025
@github-project-automation github-project-automation bot moved this to Todo 🕑 in Spectre Console Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant