Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/write list irenderable #1438

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
13 changes: 13 additions & 0 deletions src/Spectre.Console/Extensions/AnsiConsoleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,17 @@ public static void WriteLine(this IAnsiConsole console, string text, Style? styl

console.Write(text + Environment.NewLine, style);
}

/// <summary>
/// Writes a <see cref="IRenderable"/> items to the console.
/// </summary>
/// <param name="console">The console to write to.</param>
/// <param name="renderables">The <see cref="IRenderable"/> items to write.</param>
public static void Write(this IAnsiConsole console, params IRenderable[] renderables)
{
foreach (var renderable in renderables)
{
console.Write(renderable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BarChart
Number of fruits
Apple ████████ 12
Orange █████████████████████████████████████████████████ 54
Banana ████████████████████████████ 33
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Table
┌────────┬────────┬───────┐
│ Foo │ Bar │ Baz │
├────────┼────────┼───────┤
│ Qux │ Corgi │ Waldo │
│ Grault │ Garply │ Fred │
└────────┴────────┴───────┘
32 changes: 32 additions & 0 deletions test/Spectre.Console.Tests/Unit/AnsiConsoleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ public void Should_Not_Include_Decoration_If_Set_To_None()
// Then
console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
}

[Fact]
public void Should_Display_All_IRenderable_Itens_In_Line()
{
// Given
var console = new TestConsole()
.Colors(ColorSystem.Standard);

// When
console.Write(
new Text("Hello "),
new Text("World!"));

// Then
console.Output.ShouldBe("Hello World!");
}

[Fact]
public void Should_Display_All_IRenderable_Itens_In_Line2()
{
// Given
var console = new TestConsole()
.Colors(ColorSystem.Standard);

// When
console.Write(
new Text("Hello "),
new TextPath(@"C:\Test"));

// Then
console.Output.ShouldBe(@"Hello C:/Test");
}
}

public sealed class WriteLine
Expand Down
21 changes: 21 additions & 0 deletions test/Spectre.Console.Tests/Unit/Widgets/BarChartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ public async Task Should_Render_Correctly()
await Verifier.Verify(console.Output);
}

[Fact]
[Expectation("RenderWithText")]
public async Task Should_Render_Correctly_With_Text()
{
// Given
var console = new TestConsole();

// When
console.Write(
new Text("BarChart\n"),
new BarChart()
.Width(60)
.Label("Number of fruits")
.AddItem("Apple", 12)
.AddItem("Orange", 54)
.AddItem("Banana", 33));

// Then
await Verifier.Verify(console.Output);
}

[Fact]
[Expectation("Zero_Value")]
public async Task Should_Render_Correctly_2()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Spectre.Console.Tests.Unit;

[UsesVerify]
[ExpectationPath("Widgets/ProgressBar")]
public class ProgressBarTests
{
Expand Down
20 changes: 20 additions & 0 deletions test/Spectre.Console.Tests/Unit/Widgets/Table/TableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ public Task Should_Render_Table_Correctly()
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("RenderWithText")]
public Task Should_Render_Table_Correctly_With_Text()
{
// 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(
new Text("Table\n"),
table);

// Then
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("Render_Row_Separators")]
public Task Should_Render_Table_With_Row_Separators_Correctly()
Expand Down
18 changes: 18 additions & 0 deletions test/Spectre.Console.Tests/Unit/Widgets/TextPathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,22 @@ public Task Should_Behave_As_Expected_When_Rendering_Inside_Panel_Columns()
// Then
return Verifier.Verify(console.Output);
}

[Theory]
[InlineData("C:/Foo/Bar/Baz.txt", "Path:\nC:/Foo/Bar/Baz.txt")]
[InlineData("/Foo/Bar/Baz.txt", "Path:\n/Foo/Bar/Baz.txt")]
[InlineData("Foo/Bar/Baz.txt", "Path:\nFoo/Bar/Baz.txt")]
public void Should_Render_Full_Path_With_Text_If_Possible(string input, string expected)
{
// Given
var console = new TestConsole().Width(40);

// When
console.Write(
new Text("Path:\n"),
new TextPath(input));

// Then
console.Output.ShouldBe(expected);
}
}
Loading