mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-10-31 09:09:25 +08:00 
			
		
		
		
	Fix line ending problem with text
This commit is contained in:
		| @@ -95,6 +95,29 @@ namespace Spectre.Console.Tests.Unit | ||||
|                 console.Lines[1].ShouldBe("          "); | ||||
|                 console.Lines[2].ShouldBe("Qux  Corgi"); | ||||
|             } | ||||
|  | ||||
|             [Fact] | ||||
|             public void Should_Add_Empty_Row_At_The_End() | ||||
|             { | ||||
|                 // Given | ||||
|                 var console = new PlainConsole(width: 80); | ||||
|                 var grid = new Grid(); | ||||
|                 grid.AddColumns(2); | ||||
|                 grid.AddRow("Foo", "Bar"); | ||||
|                 grid.AddEmptyRow(); | ||||
|                 grid.AddRow("Qux", "Corgi"); | ||||
|                 grid.AddEmptyRow(); | ||||
|  | ||||
|                 // When | ||||
|                 console.Render(grid); | ||||
|  | ||||
|                 // Then | ||||
|                 console.Lines.Count.ShouldBe(4); | ||||
|                 console.Lines[0].ShouldBe("Foo  Bar  "); | ||||
|                 console.Lines[1].ShouldBe("          "); | ||||
|                 console.Lines[2].ShouldBe("Qux  Corgi"); | ||||
|                 console.Lines[3].ShouldBe("          "); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         [Fact] | ||||
|   | ||||
| @@ -62,6 +62,20 @@ namespace Spectre.Console.Tests.Unit | ||||
|                 fixture.RawOutput.ShouldBe("Hello\n\nWorld"); | ||||
|             } | ||||
|  | ||||
|             [Fact] | ||||
|             public void Should_Write_Line_Breaks_At_End() | ||||
|             { | ||||
|                 // Given | ||||
|                 var fixture = new PlainConsole(width: 5); | ||||
|                 var text = new Text("Hello\n\nWorld\n\n"); | ||||
|  | ||||
|                 // When | ||||
|                 fixture.Render(text); | ||||
|  | ||||
|                 // Then | ||||
|                 fixture.RawOutput.ShouldBe("Hello\n\nWorld\n\n"); | ||||
|             } | ||||
|  | ||||
|             [Theory] | ||||
|             [InlineData(5, "Hello World", "Hello\nWorld")] | ||||
|             [InlineData(10, "Hello Sweet Nice World", "Hello \nSweet Nice\nWorld")] | ||||
|   | ||||
| @@ -86,12 +86,13 @@ namespace Spectre.Console | ||||
|                 return Array.Empty<Segment>(); | ||||
|             } | ||||
|  | ||||
|             var justification = context.Justification ?? Alignment; | ||||
|  | ||||
|             var lines = SplitLines(context, maxWidth); | ||||
|  | ||||
|             // Justify lines | ||||
|             var justification = context.Justification ?? Alignment; | ||||
|             foreach (var (_, _, last, line) in lines.Enumerate()) | ||||
|             { | ||||
|                 var length = line.Sum(l => l.StripLineEndings().CellLength(context.Encoding)); | ||||
|                 var length = line.Sum(l => l.CellLength(context.Encoding)); | ||||
|                 if (length < maxWidth) | ||||
|                 { | ||||
|                     // Justify right side | ||||
| @@ -135,10 +136,6 @@ namespace Spectre.Console | ||||
|             foreach (var (_, first, last, part) in text.SplitLines().Enumerate()) | ||||
|             { | ||||
|                 var current = part; | ||||
|                 if (string.IsNullOrEmpty(current) && last) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
|                 if (first) | ||||
|                 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Patrik Svensson
					Patrik Svensson