mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-01 18:38:16 +08:00
Add Layout widget (#1041)
* Add width to panels * Add height to panels * Replace RenderContext with RenderOptions * Remove exclusivity from alternative buffer * Add Layout widget * Add Align widget
This commit is contained in:
@ -187,7 +187,9 @@ public sealed class TableTests
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
table.Alignment = Justify.Left;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
@ -199,6 +201,24 @@ public sealed class TableTests
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_LeftAligned", "Align_Widget")]
|
||||
public Task Should_Left_Align_Table_Correctly_When_Wrapped_In_Align_Widget()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
|
||||
// When
|
||||
console.Write(Align.Left(table));
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_Centered")]
|
||||
public Task Should_Center_Table_Correctly()
|
||||
@ -206,7 +226,9 @@ public sealed class TableTests
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
table.Alignment = Justify.Center;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
@ -218,6 +240,24 @@ public sealed class TableTests
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_Centered", "Align_Widget")]
|
||||
public Task Should_Center_Table_Correctly_When_Wrapped_In_Align_Widget()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
|
||||
// When
|
||||
console.Write(Align.Center(table));
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_RightAligned")]
|
||||
public Task Should_Right_Align_Table_Correctly()
|
||||
@ -225,7 +265,9 @@ public sealed class TableTests
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
table.Alignment = Justify.Right;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
@ -237,6 +279,24 @@ public sealed class TableTests
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_RightAligned", "Align_Widget")]
|
||||
public Task Should_Right_Align_Table_Correctly_When_Wrapped_In_Align_Widget()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
table.AddRow("Grault", "Garply", "Fred");
|
||||
|
||||
// When
|
||||
console.Write(Align.Right(table));
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render_Nested")]
|
||||
public Task Should_Render_Table_Nested_In_Panels_Correctly()
|
||||
@ -380,7 +440,7 @@ public sealed class TableTests
|
||||
table.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green)));
|
||||
table.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue)));
|
||||
table.AddRow(new Text("Hello").Centered(), new Markup("[red]World[/]"), Text.Empty);
|
||||
table.AddRow(second, new Text("Whaat"), new Text("Lol").RightAligned());
|
||||
table.AddRow(second, new Text("Whaat"), new Text("Lol").RightJustified());
|
||||
table.AddRow(new Markup("[blue]Hej[/]"), new Markup("[yellow]Världen[/]"), Text.Empty);
|
||||
|
||||
// When
|
||||
|
Reference in New Issue
Block a user