mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 05:18:16 +08:00
Add live display support
This commit also adds functionality to LiveRenderable that should fix some problems related to vertical overflow. Closes #316 Closes #415
This commit is contained in:

committed by
Phil Scott

parent
5d68020abb
commit
3dea412785
@ -1,4 +1,4 @@
|
||||
Title: Live Displays
|
||||
Title: Live
|
||||
Order: 4
|
||||
---
|
||||
|
||||
|
62
docs/input/live/live-display.md
Normal file
62
docs/input/live/live-display.md
Normal file
@ -0,0 +1,62 @@
|
||||
Title: Live Display
|
||||
Order: 0
|
||||
---
|
||||
|
||||
Spectre.Console can update arbitrary widgets in-place.
|
||||
|
||||
<?# Alert ?>
|
||||
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.
|
||||
<?#/ Alert ?>
|
||||
|
||||
```csharp
|
||||
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`.
|
||||
|
||||
```csharp
|
||||
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
|
||||
|
||||
```csharp
|
||||
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
|
||||
});
|
||||
```
|
@ -66,7 +66,6 @@ await AnsiConsole.Progress()
|
||||
## Configure
|
||||
|
||||
```csharp
|
||||
// Asynchronous
|
||||
AnsiConsole.Progress()
|
||||
.AutoRefresh(false) // Turn off auto refresh
|
||||
.AutoClear(false) // Do not remove the task list when done
|
||||
|
@ -1,5 +1,5 @@
|
||||
Title: Status
|
||||
Order: 6
|
||||
Order: 10
|
||||
RedirectFrom: status
|
||||
---
|
||||
|
||||
|
Reference in New Issue
Block a user