Make VT-100 sequences easier to understand

This commit is contained in:
Patrik Svensson
2021-03-28 17:04:03 +02:00
committed by Phil Scott
parent 20650f1e7e
commit 1ed7e65fcb
9 changed files with 275 additions and 26 deletions

View File

@ -0,0 +1,10 @@
[?25l
* foo

- bar

* baz
[?25h

View File

@ -0,0 +1,52 @@
using Shouldly;
using Spectre.Console.Testing;
using Xunit;
namespace Spectre.Console.Tests.Unit
{
public partial class AnsiConsoleTests
{
public sealed class Cursor
{
public sealed class TheMoveMethod
{
[Theory]
[InlineData(CursorDirection.Up, "HelloWorld")]
[InlineData(CursorDirection.Down, "HelloWorld")]
[InlineData(CursorDirection.Right, "HelloWorld")]
[InlineData(CursorDirection.Left, "HelloWorld")]
public void Should_Return_Correct_Ansi_Code(CursorDirection direction, string expected)
{
// Given
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
// When
console.Write("Hello");
console.Cursor.Move(direction, 2);
console.Write("World");
// Then
console.Output.ShouldBe(expected);
}
}
public sealed class TheSetPositionMethod
{
[Fact]
public void Should_Return_Correct_Ansi_Code()
{
// Given
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
// When
console.Write("Hello");
console.Cursor.SetPosition(5, 3);
console.Write("World");
// Then
console.Output.ShouldBe("HelloWorld");
}
}
}
}
}

View File

@ -7,6 +7,23 @@ namespace Spectre.Console.Tests.Unit
{
public partial class AnsiConsoleTests
{
[Theory]
[InlineData(false, "HelloWorld")]
[InlineData(true, "HelloWorld")]
public void Should_Clear_Screen(bool home, string expected)
{
// Given
var console = new FakeAnsiConsole(ColorSystem.Standard);
// When
console.Write("Hello");
console.Clear(home);
console.Write("World");
// Then
console.Output.ShouldBe(expected);
}
[Fact]
public void Should_Combine_Decoration_And_Colors()
{

View File

@ -1,13 +1,18 @@
using Shouldly;
using System.Threading.Tasks;
using Spectre.Console.Testing;
using Spectre.Verify.Extensions;
using VerifyXunit;
using Xunit;
namespace Spectre.Console.Tests.Unit
{
[UsesVerify]
[ExpectationPath("Widgets/Status")]
public sealed class StatusTests
{
[Fact]
public void Should_Render_Status_Correctly()
[Expectation("Render")]
public Task Should_Render_Status_Correctly()
{
// Given
var console = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);
@ -28,16 +33,7 @@ namespace Spectre.Console.Tests.Unit
});
// Then
console.Output
.NormalizeLineEndings()
.ShouldBe(
"[?25l \n" +
"* foo\n" +
"  \n" +
"- bar\n" +
"  \n" +
"* baz\n" +
" [?25h");
return Verifier.Verify(console.Output);
}
}
}