Skip to content

Commit 425cf56

Browse files
authored
Add overload to ContainerSpan.Add() to accept a string which becomes a ContentSpan (#908)
1 parent d252893 commit 425cf56

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,14 @@ public void Container_span_supports_add_method()
1717

1818
span.ContentLength.Should().Be("content with child".Length);
1919
}
20+
21+
[Fact]
22+
public void Container_span_supports_add_string_method()
23+
{
24+
var span = new ContainerSpan(new ContentSpan("content"));
25+
span.Add(" with string");
26+
27+
span.ContentLength.Should().Be("content with string".Length);
28+
}
2029
}
2130
}

src/System.CommandLine.Rendering/ContainerSpan.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,17 @@ public void Add(TextSpan child)
7272

7373
RecalculateChildPositions();
7474
}
75+
76+
public void Add(string text)
77+
{
78+
if (string.IsNullOrEmpty(text))
79+
{
80+
return;
81+
}
82+
83+
_children.Add(new ContentSpan(text));
84+
85+
RecalculateChildPositions();
86+
}
7587
}
7688
}

0 commit comments

Comments
 (0)