Add status support

This commit is contained in:
Patrik Svensson
2020-12-08 00:43:24 +01:00
committed by Patrik Svensson
parent cbed41e637
commit 501db5d287
36 changed files with 1290 additions and 476 deletions

View File

@ -0,0 +1,43 @@
Title: Spinners
Order: 4
---
For all available spinners, see https://jsfiddle.net/sindresorhus/2eLtsbey/embedded/result/
# Usage
Spinners can be used with [Progress](xref:progress) and [Status](xref:status).
```csharp
AnsiConsole.Status()
.Spinner(Spinner.Known.Star)
.Start("Thinking...", ctx => {
// Omitted
});
```
# Implementing a spinner
To implement your own spinner, all you have to do is
inherit from the `Spinner` base class.
In the example below, the spinner will alterate between
the characters `A`, `B` and `C` every 100 ms.
```csharp
public sealed class MySpinner : Spinner
{
// The interval for each frame
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
// Whether or not the spinner contains unicode characters
public override bool IsUnicode => false;
// The individual frames of the spinner
public override IReadOnlyList<string> Frames =>
new List<string>
{
"A", "B", "C",
};
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

View File

@ -31,5 +31,4 @@ $(document).ready(function () {
}; // keyup
})
}); // ready

60
docs/input/status.md Normal file
View File

@ -0,0 +1,60 @@
Title: Status
Order: 6
---
Spectre.Console can display information about long running tasks in the console.
<img src="assets/images/status.gif" style="max-width: 100%;margin-bottom:20px;">
If the current terminal isn't considered "interactive", such as when running
in a continuous integration system, or the terminal can't display
ANSI control sequence, any progress will be displayed in a simpler way.
# Usage
```csharp
// Synchronous
AnsiConsole.Status()
.Start("Thinking...", ctx =>
{
// Simulate some work
AnsiConsole.MarkupLine("Doing some work...");
Thread.Sleep(1000);
// Update the status and spinner
ctx.Status("Thinking some more");
ctx.Spinner(Spinner.Known.Star);
ctx.SpinnerStyle(Style.Parse("green"));
// Simulate some work
AnsiConsole.MarkupLine("Doing some more work...");
Thread.Sleep(2000);
});
```
## Asynchronous progress
If you prefer to use async/await, you can use `StartAsync` instead of `Start`.
```csharp
// Asynchronous
await AnsiConsole.Status()
.StartAsync("Thinking...", async ctx =>
{
// Omitted
});
```
# Configure
```csharp
AnsiConsole.Status()
.AutoRefresh(false)
.Spinner(Spinner.Known.Star)
.SpinnerStyle(Style.Parse("green bold"))
.Start("Thinking...", ctx =>
{
// Omitted
ctx.Refresh();
});
```