diff --git a/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs b/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs index 347da5d26c..0adbb3171a 100644 --- a/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs +++ b/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs @@ -17,5 +17,14 @@ public void Container_span_supports_add_method() span.ContentLength.Should().Be("content with child".Length); } + + [Fact] + public void Container_span_supports_add_string_method() + { + var span = new ContainerSpan(new ContentSpan("content")); + span.Add(" with string"); + + span.ContentLength.Should().Be("content with string".Length); + } } } diff --git a/src/System.CommandLine.Rendering/ContainerSpan.cs b/src/System.CommandLine.Rendering/ContainerSpan.cs index 933204b4e4..5a70ec2730 100644 --- a/src/System.CommandLine.Rendering/ContainerSpan.cs +++ b/src/System.CommandLine.Rendering/ContainerSpan.cs @@ -72,5 +72,17 @@ public void Add(TextSpan child) RecalculateChildPositions(); } + + public void Add(string text) + { + if (string.IsNullOrEmpty(text)) + { + return; + } + + _children.Add(new ContentSpan(text)); + + RecalculateChildPositions(); + } } }