diff --git a/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs b/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs
index 394c850..1303104 100644
--- a/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs
+++ b/src/Spectre.Console.Tests/Unit/AnsiConsoleTests.Markup.cs
@@ -12,7 +12,7 @@ namespace Spectre.Console.Tests.Unit
{
[Theory]
[InlineData("[yellow]Hello[/]", "[93mHello[0m")]
- [InlineData("[yellow]Hello [italic]World[/]![/]", "[93mHello[0m[93m [0m[3;93mWorld[0m[93m![0m")]
+ [InlineData("[yellow]Hello [italic]World[/]![/]", "[93mHello [0m[3;93mWorld[0m[93m![0m")]
public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected)
{
// Given
@@ -26,7 +26,7 @@ namespace Spectre.Console.Tests.Unit
}
[Theory]
- [InlineData("[yellow]Hello [[ World[/]", "[93mHello[0m[93m [0m[93m[[0m[93m [0m[93mWorld[0m")]
+ [InlineData("[yellow]Hello [[ World[/]", "[93mHello [ World[0m")]
public void Should_Be_Able_To_Escape_Tags(string markup, string expected)
{
// Given
diff --git a/src/Spectre.Console/ConsoleExtensions.Rendering.cs b/src/Spectre.Console/ConsoleExtensions.Rendering.cs
index c7f364e..096425d 100644
--- a/src/Spectre.Console/ConsoleExtensions.Rendering.cs
+++ b/src/Spectre.Console/ConsoleExtensions.Rendering.cs
@@ -30,8 +30,11 @@ namespace Spectre.Console
using (console.PushStyle(Style.Plain))
{
+ var segments = renderable.Render(options, console.Width);
+ segments = Segment.Merge(segments);
+
var current = Style.Plain;
- foreach (var segment in renderable.Render(options, console.Width))
+ foreach (var segment in segments)
{
if (string.IsNullOrEmpty(segment.Text))
{
diff --git a/src/Spectre.Console/Internal/Utilities/ConsoleHelper.cs b/src/Spectre.Console/Internal/Utilities/ConsoleHelper.cs
index 54dadc5..0328c03 100644
--- a/src/Spectre.Console/Internal/Utilities/ConsoleHelper.cs
+++ b/src/Spectre.Console/Internal/Utilities/ConsoleHelper.cs
@@ -1,5 +1,4 @@
using System.IO;
-using System.Runtime.InteropServices;
namespace Spectre.Console.Internal
{
diff --git a/src/Spectre.Console/Rendering/Segment.cs b/src/Spectre.Console/Rendering/Segment.cs
index 889f8f5..2d93867 100644
--- a/src/Spectre.Console/Rendering/Segment.cs
+++ b/src/Spectre.Console/Rendering/Segment.cs
@@ -16,7 +16,7 @@ namespace Spectre.Console.Rendering
///
/// Gets the segment text.
///
- public string Text { get; }
+ public string Text { get; internal set; }
///
/// Gets a value indicating whether or not this is an expicit line break
@@ -226,6 +226,41 @@ namespace Spectre.Console.Rendering
return lines;
}
+ internal static IEnumerable Merge(IEnumerable segments)
+ {
+ var result = new List();
+
+ var previous = (Segment?)null;
+ foreach (var segment in segments)
+ {
+ if (previous == null)
+ {
+ previous = segment;
+ continue;
+ }
+
+ // Same style?
+ if (previous.Style.Equals(segment.Style))
+ {
+ // Modify the content of the previous segment
+ previous.Text += segment.Text;
+ }
+ else
+ {
+ // Push the current one to the results.
+ result.Add(previous);
+ previous = segment;
+ }
+ }
+
+ if (previous != null)
+ {
+ result.Add(previous);
+ }
+
+ return result;
+ }
+
internal static List> MakeSameHeight(int cellHeight, List> cells)
{
foreach (var cell in cells)