mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
Preserve line breaks
This commit is contained in:
parent
f4d1796e40
commit
22d4af4482
@ -18,6 +18,7 @@ namespace Spectre.Console.Tests
|
||||
public Color Background { get; set; }
|
||||
|
||||
public StringWriter Writer { get; }
|
||||
public string RawOutput => Writer.ToString();
|
||||
public string Output => Writer.ToString().TrimEnd('\n');
|
||||
public IReadOnlyList<string> Lines => Output.Split(new char[] { '\n' });
|
||||
|
||||
|
@ -21,6 +21,20 @@ namespace Spectre.Console.Tests.Unit
|
||||
.ShouldBe("Hello World");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Write_Line_Breaks()
|
||||
{
|
||||
// Given
|
||||
var fixture = new PlainConsole(width: 5);
|
||||
var text = Text.New("\n\n");
|
||||
|
||||
// When
|
||||
fixture.Render(text);
|
||||
|
||||
// Then
|
||||
fixture.RawOutput.ShouldBe("\n\n");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Split_Unstyled_Text_To_New_Lines_If_Width_Exceeds_Console_Width()
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ namespace Spectre.Console
|
||||
/// <inheritdoc/>
|
||||
IEnumerable<Segment> IRenderable.Render(RenderContext context, int width)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_text))
|
||||
if (string.IsNullOrEmpty(_text))
|
||||
{
|
||||
return Array.Empty<Segment>();
|
||||
}
|
||||
@ -192,7 +192,7 @@ namespace Spectre.Console
|
||||
}
|
||||
}
|
||||
|
||||
if (!last)
|
||||
if (!last || line.Count == 0)
|
||||
{
|
||||
result.Add(Segment.LineBreak());
|
||||
}
|
||||
@ -214,7 +214,10 @@ namespace Spectre.Console
|
||||
var index = segment.Text.IndexOf("\n", StringComparison.OrdinalIgnoreCase);
|
||||
if (index == -1)
|
||||
{
|
||||
result.Add(segment);
|
||||
if (!string.IsNullOrEmpty(segment.Text))
|
||||
{
|
||||
result.Add(segment);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user