mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-02 10:58:17 +08:00
Make VT-100 sequences easier to understand
This commit is contained in:

committed by
Phil Scott

parent
20650f1e7e
commit
1ed7e65fcb
@ -0,0 +1,10 @@
|
||||
[?25l
|
||||
[38;5;11m*[0m foo
|
||||
|
||||
[2A
|
||||
[38;5;11m-[0m bar
|
||||
|
||||
[2A
|
||||
[38;5;11m*[0m baz
|
||||
|
||||
[2K[1A[2K[1A[2K[?25h
|
52
src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Cursor.cs
Normal file
52
src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Cursor.cs
Normal 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, "Hello[2AWorld")]
|
||||
[InlineData(CursorDirection.Down, "Hello[2BWorld")]
|
||||
[InlineData(CursorDirection.Right, "Hello[2CWorld")]
|
||||
[InlineData(CursorDirection.Left, "Hello[2DWorld")]
|
||||
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("Hello[3;5HWorld");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,23 @@ namespace Spectre.Console.Tests.Unit
|
||||
{
|
||||
public partial class AnsiConsoleTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(false, "Hello[2JWorld")]
|
||||
[InlineData(true, "Hello[2J[0;0HWorld")]
|
||||
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()
|
||||
{
|
||||
|
@ -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" +
|
||||
"[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");
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user