mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-02 19:08:15 +08:00
Add status support
This commit is contained in:

committed by
Patrik Svensson

parent
cbed41e637
commit
501db5d287
25
src/Spectre.Console.Tests/Tools/DummySpinners.cs
Normal file
25
src/Spectre.Console.Tests/Tools/DummySpinners.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
public sealed class DummySpinner1 : Spinner
|
||||
{
|
||||
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
|
||||
public override bool IsUnicode => true;
|
||||
public override IReadOnlyList<string> Frames => new List<string>
|
||||
{
|
||||
"*",
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class DummySpinner2 : Spinner
|
||||
{
|
||||
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
|
||||
public override bool IsUnicode => true;
|
||||
public override IReadOnlyList<string> Frames => new List<string>
|
||||
{
|
||||
"-",
|
||||
};
|
||||
}
|
||||
}
|
42
src/Spectre.Console.Tests/Unit/StatusTests.cs
Normal file
42
src/Spectre.Console.Tests/Unit/StatusTests.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public sealed partial class StatusTests
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Render_Status_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor, width: 10);
|
||||
|
||||
var status = new Status(console);
|
||||
status.AutoRefresh = false;
|
||||
status.Spinner = new DummySpinner1();
|
||||
|
||||
// When
|
||||
status.Start("foo", ctx =>
|
||||
{
|
||||
ctx.Refresh();
|
||||
ctx.Spinner(new DummySpinner2());
|
||||
ctx.Status("bar");
|
||||
ctx.Refresh();
|
||||
ctx.Spinner(new DummySpinner1());
|
||||
ctx.Status("baz");
|
||||
});
|
||||
|
||||
// Then
|
||||
console.Output
|
||||
.NormalizeLineEndings()
|
||||
.ShouldBe(
|
||||
"[?25l \n" +
|
||||
"[38;5;11m*[0m foo\n" +
|
||||
" [1A[1A \n" +
|
||||
"[38;5;11m-[0m bar\n" +
|
||||
" [1A[1A \n" +
|
||||
"[38;5;11m*[0m baz\n" +
|
||||
" [2K[1A[2K[1A[2K[?25h");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user