spectre.console/docs/input/live/live-display.md
2021-05-23 23:30:14 +02:00

1.3 KiB

Title: Live Display Order: 0

Spectre.Console can update arbitrary widgets in-place.

The live display is not thread safe, and using it together with other interactive components such as prompts, status displays or other progress displays are not supported.

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

AnsiConsole.Live(table)
    .Start(ctx => 
    {
        table.AddColumn("Foo");
        ctx.Refresh();
        Thread.Sleep(1000);

        table.AddColumn("Bar");
        ctx.Refresh();
        Thread.Sleep(1000);
    });

Asynchronous progress

If you prefer to use async/await, you can use StartAsync instead of Start.

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

await AnsiConsole.Live(table)
    .StartAsync(async ctx => 
    {
        table.AddColumn("Foo");
        ctx.Refresh();
        await Task.Delay(1000);

        table.AddColumn("Bar");
        ctx.Refresh();
        await Task.Delay(1000);
    });

Configure

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

AnsiConsole.Live(table)
    .AutoClear(false)   // Do not remove when done
    .Overflow(VerticalOverflow.Ellipsis) // Show ellipsis when overflowing
    .Cropping(VerticalOverflowCropping.Top) // Crop overflow at top
    .Start(ctx =>
    {
        // Omitted
    });