mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-19 10:12:50 +08:00
parent
9637066927
commit
d475e3b30a
@ -247,7 +247,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public sealed class WriteLine
|
public sealed class WriteLine
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Reset_Colors_Correctly()
|
public void Should_Reset_Colors_Correctly_After_Line_Break()
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||||
@ -263,6 +263,21 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
.ShouldBe("[101mHello[0m\n[102mWorld[0m\n");
|
.ShouldBe("[101mHello[0m\n[102mWorld[0m\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var fixture = new AnsiConsoleFixture(ColorSystem.Standard, AnsiSupport.Yes);
|
||||||
|
|
||||||
|
// When
|
||||||
|
fixture.Console.Background = ConsoleColor.Red;
|
||||||
|
fixture.Console.WriteLine("Hello\nWorld");
|
||||||
|
|
||||||
|
// Then
|
||||||
|
fixture.Output.NormalizeLineEndings()
|
||||||
|
.ShouldBe("[101mHello[0m\n[101mWorld[0m\n");
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AnsiSupport.Yes)]
|
[InlineData(AnsiSupport.Yes)]
|
||||||
[InlineData(AnsiSupport.No)]
|
[InlineData(AnsiSupport.No)]
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Spectre.Console.Internal;
|
|
||||||
|
|
||||||
namespace Spectre.Console
|
namespace Spectre.Console
|
||||||
{
|
{
|
||||||
@ -20,12 +19,7 @@ namespace Spectre.Console
|
|||||||
throw new ArgumentNullException(nameof(console));
|
throw new ArgumentNullException(nameof(console));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (console.PushColor(Color.Default, true))
|
console.Write(Environment.NewLine);
|
||||||
using (console.PushColor(Color.Default, false))
|
|
||||||
using (console.PushDecoration(Decoration.None))
|
|
||||||
{
|
|
||||||
console.Write(Environment.NewLine);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -60,12 +60,19 @@ namespace Spectre.Console.Internal
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_out.Write(AnsiBuilder.GetAnsi(
|
var parts = text.NormalizeLineEndings().Split(new[] { '\n' });
|
||||||
_system,
|
foreach (var (_, _, last, part) in parts.Enumerate())
|
||||||
text.NormalizeLineEndings(native: true),
|
{
|
||||||
Decoration,
|
if (!string.IsNullOrEmpty(part))
|
||||||
Foreground,
|
{
|
||||||
Background));
|
_out.Write(AnsiBuilder.GetAnsi(_system, part, Decoration, Foreground, Background));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!last)
|
||||||
|
{
|
||||||
|
_out.Write(Environment.NewLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user