mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 05:18:16 +08:00
Add support for exclusive mode
This commit is contained in:

committed by
Phil Scott

parent
c2bab0ebf8
commit
7f6f2437b1
12
docs/input/live/index.cshtml
Normal file
12
docs/input/live/index.cshtml
Normal file
@ -0,0 +1,12 @@
|
||||
Title: Live Displays
|
||||
Order: 4
|
||||
---
|
||||
|
||||
<h1>Sections</h1>
|
||||
|
||||
<ul>
|
||||
@foreach (IDocument child in OutputPages.GetChildrenOf(Document))
|
||||
{
|
||||
<li>@Html.DocumentLink(child)</li>
|
||||
}
|
||||
</ul>
|
86
docs/input/live/progress.md
Normal file
86
docs/input/live/progress.md
Normal file
@ -0,0 +1,86 @@
|
||||
Title: Progress
|
||||
Order: 5
|
||||
RedirectFrom: progress
|
||||
---
|
||||
|
||||
Spectre.Console can display information about long running tasks in the console.
|
||||
|
||||
<img src="../assets/images/progress.png" style="max-width: 100%;margin-bottom:20px;">
|
||||
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<i class="fas fa-exclamation-triangle icon-web"></i> The progress 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.
|
||||
</div>
|
||||
|
||||
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.
|
||||
|
||||
<img src="../assets/images/progress_fallback.png" style="max-width: 100%;">
|
||||
|
||||
# Usage
|
||||
|
||||
```csharp
|
||||
// Synchronous
|
||||
AnsiConsole.Progress()
|
||||
.Start(ctx =>
|
||||
{
|
||||
// Define tasks
|
||||
var task1 = ctx.AddTask("[green]Reticulating splines[/]");
|
||||
var task2 = ctx.AddTask("[green]Folding space[/]");
|
||||
|
||||
while(!ctx.IsFinished)
|
||||
{
|
||||
task1.Increment(1.5);
|
||||
task2.Increment(0.5);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Asynchronous progress
|
||||
|
||||
If you prefer to use async/await, you can use `StartAsync` instead of `Start`.
|
||||
|
||||
```csharp
|
||||
// Asynchronous
|
||||
await AnsiConsole.Progress()
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
// Define tasks
|
||||
var task1 = ctx.AddTask("[green]Reticulating splines[/]");
|
||||
var task2 = ctx.AddTask("[green]Folding space[/]");
|
||||
|
||||
while (!ctx.IsFinished)
|
||||
{
|
||||
// Simulate some work
|
||||
await Task.Delay(250);
|
||||
|
||||
// Increment
|
||||
task1.Increment(1.5);
|
||||
task2.Increment(0.5);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
# Configure
|
||||
|
||||
```csharp
|
||||
// Asynchronous
|
||||
AnsiConsole.Progress()
|
||||
.AutoRefresh(false) // Turn off auto refresh
|
||||
.AutoClear(false) // Do not remove the task list when done
|
||||
.HideCompleted(false) // Hide tasks as they are completed
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(), // Task description
|
||||
new ProgressBarColumn(), // Progress bar
|
||||
new PercentageColumn(), // Percentage
|
||||
new RemainingTimeColumn(), // Remaining time
|
||||
new SpinnerColumn(), // Spinner
|
||||
})
|
||||
.Start(ctx =>
|
||||
{
|
||||
// Omitted
|
||||
});
|
||||
```
|
67
docs/input/live/status.md
Normal file
67
docs/input/live/status.md
Normal file
@ -0,0 +1,67 @@
|
||||
Title: Status
|
||||
Order: 6
|
||||
RedirectFrom: status
|
||||
---
|
||||
|
||||
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;">
|
||||
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<i class="fas fa-exclamation-triangle icon-web"></i> The status display is not
|
||||
thread safe, and using it together with other interactive components such as
|
||||
prompts, progress displays or other status displays are not supported.
|
||||
</div>
|
||||
|
||||
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();
|
||||
});
|
||||
```
|
Reference in New Issue
Block a user