spectreconsole / spectre.console

A .NET library that makes it easier to create beautiful console applications.
https://spectreconsole.net
MIT License
9.45k stars 499 forks source link

[Live Layout] Partial update, Fixed Header and Footer, Update only middle Content #1345

Open w4po opened 1 year ago

w4po commented 1 year ago

Hello,

I was trying to do a layout consisting of a Header and a content, I want the header to be fixed,

Something like:

var layout = new Layout()
    .SplitRows(
        new Layout("Header", new FigletText("FIGLET")),
        new Layout("Content").Ratio(2));

AnsiConsole.Write(layout);

await AnsiConsole
    .Progress()
    .UseRenderHook((renderable, _) => layout["Content"].Update(renderable))
    .StartAsync(async ctx =>
    {
        var task = ctx.AddTask("Downloading:");
        while (!ctx.IsFinished)
        {
            await Task.Delay(150).ConfigureAwait(false);
            task.Increment(0.7);
        }
    }).ConfigureAwait(false);

So it would be really nice if we could trigger a redraw to update only part of the layout with: layout["Content"].Update(renderable);

Is that possible? Thank you very much for the awesome work <3.


Please upvote :+1: this issue if you are interested in it.

heroboy commented 11 months ago

I would like a ProgressBar widget. code maybe:

var progress = new ProgressBar("downloading");
var layout = new Layout()
    .SplitRows(
        new Layout("Header", new FigletText("FIGLET")),
        new Layout("Content", progress ));

await AnsiConsole.Live(layout)
    .StartAsync(async ctx =>
    {
        for(int i = 0;i<100;++i)
        {
            await Task.Delay(150).ConfigureAwait(false);
            progress .Increment(0.01);
        }
    }).ConfigureAwait(false);
patriksvensson commented 11 months ago

It is not possible to partially update a layout. This is by design and nothing I see that we will add support for since it would require a complete rewrite of most of the library.