mayuki / Kurukuru
- понедельник, 4 декабря 2017 г. в 03:14:57
Terminal Spinner for .NET Core/Standard
Terminal Spinner library for .NET Core/Standard. strongly inspired by cli-spinners, ora, CLISpinner.
Install-Package Kurukuru
dotnet add package Kurukuru
Just add using Kurukuru;
then call Spinner.Start
with some delegate.
Spinner.Start("Processing...", () =>
{
Thread.Sleep(1000 * 3);
// MEMO: If you want to show as failed, throw a exception here.
// throw new Exception("Something went wrong!");
});
Spinner.Start("Stage 1...", spinner =>
{
Thread.Sleep(1000 * 3);
spinner.Text = "Stage 2...";
Thread.Sleep(1000 * 3);
spinner.Fail("Something went wrong!");
});
You can also use async method pattern. Use StartAsync
method.
await Spinner.StartAsync("Processing...", async () =>
{
await Task.Delay(1000 * 3);
// MEMO: If you want to show as failed, throw a exception here.
// throw new Exception("Something went wrong!");
});
await Spinner.StartAsync("Stage 1...", async spinner =>
{
await Task.Delay(1000 * 3);
spinner.Text = "Stage 2...";
await Task.Delay(1000 * 3);
spinner.Fail("Something went wrong!");
});
Kurukuru.Spinner
classStart
/ StartAsync
: Create and start new spinner. And it waits specified action.
void Start(string text, Action<Spinner> action, Pattern pattern = null, Pattern fallbackPattern = null)
void Start(string text, Action<Spinner> action, Pattern pattern = null, Pattern fallbackPattern = null)
Task StartAsync(string text, Func<Task> action, Pattern pattern = null, Pattern fallbackPattern = null)
Task StartAsync(string text, Func<Spinner, Task> action, Pattern pattern = null, Pattern fallbackPattern = null)
text
: a text to display while running action.action
: a long-running action.patterns
: Use spinner pattern (see Patterns
class). Default value is Patterns.Dot
.fallbackPattern
: Use spinner pattern if console's codepage is non-Unicode. Default value is Patterns.Line
.Stop
: Stop spinner and show a result if needed.
Stop(string text = null, string symbol = null, ConsoleColor? color = null)
Stop(string text, string symbol, ConsoleColor? color, string terminator)
Success
: Show result as ✔ success. (equivalent to Stop
method)Fail
: Show result as ✖ failure. (equivalent to Stop
method)Warning
: Show result as ⚠ warning. (equivalent to Stop
method)Info
: Show result as ℹ information. (equivalent to Stop
method)Text
: Get or set a text to display while running action.Color
: Get or set a color of the spinner. (not for text)MIT License.