Skip to content

Commit 6bdbc20

Browse files
committed
rename Span to TextSpan and FormatSpan to ControlSpan
1 parent a62bac4 commit 6bdbc20

30 files changed

+147
-145
lines changed

samples/RenderingPlayground/Colorizer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ namespace RenderingPlayground
77
{
88
internal static class Colorizer
99
{
10-
public static Span Underline(this string value) =>
10+
public static TextSpan Underline(this string value) =>
1111
new ContainerSpan(StyleSpan.UnderlinedOn(),
1212
new ContentSpan(value),
1313
StyleSpan.UnderlinedOff());
1414

1515

16-
public static Span Rgb(this string value, byte r, byte g, byte b) =>
16+
public static TextSpan Rgb(this string value, byte r, byte g, byte b) =>
1717
new ContainerSpan(ForegroundColorSpan.Rgb(r, g, b),
1818
new ContentSpan(value),
1919
ForegroundColorSpan.Reset());
2020

21-
public static Span LightGreen(this string value) =>
21+
public static TextSpan LightGreen(this string value) =>
2222
new ContainerSpan(ForegroundColorSpan.LightGreen(),
2323
new ContentSpan(value),
2424
ForegroundColorSpan.Reset());
2525

26-
public static Span White(this string value) =>
26+
public static TextSpan White(this string value) =>
2727
new ContainerSpan(ForegroundColorSpan.White(),
2828
new ContentSpan(value),
2929
ForegroundColorSpan.Reset());

samples/RenderingPlayground/DirectoryTableView.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ public DirectoryTableView(DirectoryInfo directory)
4444
Formatter.AddFormatter<DateTime>(d => $"{d:d} {ForegroundColorSpan.DarkGray()}{d:t}");
4545
}
4646

47-
Span Span(FormattableString formattableString)
47+
TextSpan Span(FormattableString formattableString)
4848
{
4949
return Formatter.ParseToSpan(formattableString);
5050
}
5151

52-
Span Span(object obj)
52+
TextSpan Span(object obj)
5353
{
5454
return Formatter.Format(obj);
5555
}
5656

57-
protected SpanFormatter Formatter { get; } = new SpanFormatter();
57+
protected TextSpanFormatter Formatter { get; } = new TextSpanFormatter();
5858
}
5959
}

samples/RenderingPlayground/ProcessesView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class ProcessesView : StackLayoutView
1111
{
1212
public ProcessesView(Process[] processes)
1313
{
14-
var formatter = new SpanFormatter();
14+
var formatter = new TextSpanFormatter();
1515
formatter.AddFormatter<TimeSpan>(t => new ContentSpan(t.ToString(@"hh\:mm\:ss")));
1616

1717
Add(new ContentView(""));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public DirectoryView(DirectoryInfo directory)
301301
throw new ArgumentNullException(nameof(directory));
302302
}
303303

304-
var formatter = new SpanFormatter();
304+
var formatter = new TextSpanFormatter();
305305
formatter.AddFormatter<DateTime>(d => $"{d:d} {ForegroundColorSpan.DarkGray()}{d:t}");
306306

307307
Add(new ContentView(""));
@@ -331,7 +331,7 @@ public DirectoryView(DirectoryInfo directory)
331331

332332
Add(tableView);
333333

334-
Span Span(FormattableString formattableString)
334+
TextSpan Span(FormattableString formattableString)
335335
{
336336
return formatter.ParseToSpan(formattableString);
337337
}

src/System.CommandLine.Rendering.Tests/FormatSpanTests.cs renamed to src/System.CommandLine.Rendering.Tests/ControlSpanTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace System.CommandLine.Rendering.Tests
88
{
9-
public class FormatSpanTests
9+
public class ControlSpanTests
1010
{
1111
[Fact]
1212
public void ForegroundColorSpans_with_equivalent_content_have_the_same_hash_code()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace System.CommandLine.Rendering.Tests
55
{
66
public class RenderingTestCase
77
{
8-
private static readonly SpanFormatter _formatter = new SpanFormatter();
8+
private static readonly TextSpanFormatter _formatter = new TextSpanFormatter();
99

1010
public RenderingTestCase(
1111
string name,
@@ -31,7 +31,7 @@ public RenderingTestCase(
3131

3232
public string Name { get; }
3333

34-
public Span InputSpan { get; }
34+
public TextSpan InputSpan { get; }
3535

3636
public Region Region { get; }
3737

src/System.CommandLine.Rendering.Tests/SpanFormatterTests.cs renamed to src/System.CommandLine.Rendering.Tests/TextSpanFormatterTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
namespace System.CommandLine.Rendering.Tests
1010
{
11-
public class SpanFormatterTests
11+
public class TextSpanFormatterTests
1212
{
1313
private readonly ITestOutputHelper output;
1414

15-
public SpanFormatterTests(ITestOutputHelper output)
15+
public TextSpanFormatterTests(ITestOutputHelper output)
1616
{
1717
this.output = output;
1818
}
1919

2020
[Fact]
2121
public void A_simple_formattable_string_can_be_converted_to_a_ContentSpan()
2222
{
23-
var span = new SpanFormatter().ParseToSpan($"some text");
23+
var span = new TextSpanFormatter().ParseToSpan($"some text");
2424

2525
span.Should()
2626
.BeOfType<ContentSpan>()
@@ -33,7 +33,7 @@ public void A_simple_formattable_string_can_be_converted_to_a_ContentSpan()
3333
[Fact]
3434
public void A_formattable_string_containing_ansi_codes_can_be_converted_to_a_ContainerSpan()
3535
{
36-
var span = new SpanFormatter().ParseToSpan($"some {StyleSpan.BlinkOn()}blinking{StyleSpan.BlinkOff()} text");
36+
var span = new TextSpanFormatter().ParseToSpan($"some {StyleSpan.BlinkOn()}blinking{StyleSpan.BlinkOff()} text");
3737

3838
var containerSpan = span.Should()
3939
.BeOfType<ContainerSpan>()
@@ -58,7 +58,7 @@ public void A_formattable_string_containing_ansi_codes_can_be_converted_to_a_Con
5858
[Fact]
5959
public void Empty_strings_are_returned_as_empty_spans()
6060
{
61-
var formatter = new SpanFormatter();
61+
var formatter = new TextSpanFormatter();
6262

6363
var span = formatter
6464
.ParseToSpan($"{Ansi.Color.Foreground.Red}normal{Ansi.Color.Foreground.Default:a}");
@@ -71,9 +71,9 @@ public void Empty_strings_are_returned_as_empty_spans()
7171
.Should()
7272
.BeEquivalentTo(
7373
new ContainerSpan(
74-
Span.Empty(),
74+
TextSpan.Empty(),
7575
new ContentSpan("normal"),
76-
Span.Empty()
76+
TextSpan.Empty()
7777
),
7878
options => options.WithStrictOrdering()
7979
.Excluding(s => s.Parent)
@@ -87,7 +87,7 @@ public void FormattableString_parsing_handles_escapes(
8787
FormattableString fs,
8888
int expectedCount)
8989
{
90-
var formatter = new SpanFormatter();
90+
var formatter = new TextSpanFormatter();
9191

9292
var span = formatter.ParseToSpan(fs);
9393

@@ -127,7 +127,7 @@ public void FormattableString_parsing_handles_format_strings(
127127
FormattableString fs,
128128
int expectedCount)
129129
{
130-
var formatter = new SpanFormatter();
130+
var formatter = new TextSpanFormatter();
131131

132132
var span = formatter.ParseToSpan(fs);
133133

@@ -150,11 +150,11 @@ public void FormattableString_parsing_handles_format_strings(
150150
[Fact]
151151
public void When_formatting_null_values_then_empty_span_is_returned()
152152
{
153-
var formatter = new SpanFormatter();
153+
var formatter = new TextSpanFormatter();
154154

155155
var span = formatter.Format(null);
156156

157-
span.Should().Be(Span.Empty());
157+
span.Should().Be(TextSpan.Empty());
158158
}
159159

160160
public static IEnumerable<object[]> FormattableStringsWithFormatStrings()

src/System.CommandLine.Rendering.Tests/SpanTests.cs renamed to src/System.CommandLine.Rendering.Tests/TextSpanTests.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.IO;
45
using FluentAssertions;
56
using Xunit;
67

78
namespace System.CommandLine.Rendering.Tests
89
{
9-
public class SpanTests
10+
public class TextSpanTests
1011
{
1112
[Fact]
1213
public void Content_span_length_is_the_same_as_the_contained_string_length()
@@ -86,7 +87,7 @@ public void Span_starts_update_when_parent_is_added_to_another_parent_span()
8687
[Fact]
8788
public void ToString_with_non_ansi_omits_ANSI_codes()
8889
{
89-
var span = new SpanFormatter()
90+
var span = new TextSpanFormatter()
9091
.ParseToSpan($"one{ForegroundColorSpan.Red()}two{ForegroundColorSpan.Reset()}three");
9192

9293
span.ToString(OutputMode.NonAnsi)
@@ -97,12 +98,28 @@ public void ToString_with_non_ansi_omits_ANSI_codes()
9798
[Fact]
9899
public void ToString_with_ansi_includes_ANSI_codes()
99100
{
100-
var span = new SpanFormatter()
101+
var span = new TextSpanFormatter()
101102
.ParseToSpan($"one{ForegroundColorSpan.Red()}two{ForegroundColorSpan.Reset()}three");
102103

103104
span.ToString(OutputMode.Ansi)
104105
.Should()
105106
.Be($"one{Ansi.Color.Foreground.Red.EscapeSequence}two{Ansi.Color.Foreground.Default.EscapeSequence}three");
106107
}
108+
109+
[Fact]
110+
public void Ansi_control_codes_can_be_included_in_interpolated_strings()
111+
{
112+
var writer = new StringWriter();
113+
114+
var formatter = new TextSpanFormatter();
115+
116+
var span = formatter.ParseToSpan($"{Ansi.Color.Foreground.LightGray}hello{Ansi.Color.Off}");
117+
118+
writer.Write(span.ToString(OutputMode.Ansi));
119+
120+
writer.ToString()
121+
.Should()
122+
.Be($"{Ansi.Color.Foreground.LightGray.EscapeSequence}hello{Ansi.Color.Off.EscapeSequence}");
123+
}
107124
}
108125
}

src/System.CommandLine.Rendering.Tests/SpanVisitorTests.cs renamed to src/System.CommandLine.Rendering.Tests/TextSpanVisitorTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace System.CommandLine.Rendering.Tests
1111
{
12-
public class SpanVisitorTests
12+
public class TextSpanVisitorTests
1313
{
1414
[Fact]
1515
public void Initialize_is_only_called_once()
@@ -27,11 +27,11 @@ public void Initialize_is_only_called_once()
2727
visitor.InitializeCount.Should().Be(1);
2828
}
2929

30-
public class TestVisitor : SpanVisitor
30+
public class TestVisitor : TextSpanVisitor
3131
{
3232
public int InitializeCount { get; set; }
3333

34-
protected override void Start(Span span)
34+
protected override void Start(TextSpan span)
3535
{
3636
InitializeCount++;
3737
}
@@ -66,9 +66,9 @@ public void SpanVisitor_visits_child_spans_in_depth_first_order()
6666
}
6767
}
6868

69-
public class RecordingSpanVisitor : SpanVisitor
69+
public class RecordingSpanVisitor : TextSpanVisitor
7070
{
71-
public override void VisitUnknownSpan(Span span) => VisitedSpans.Add(span);
71+
public override void VisitUnknownSpan(TextSpan span) => VisitedSpans.Add(span);
7272

7373
public override void VisitContainerSpan(ContainerSpan span)
7474
{
@@ -85,6 +85,6 @@ public override void VisitContainerSpan(ContainerSpan span)
8585

8686
public override void VisitStyleSpan(StyleSpan span) => VisitedSpans.Add(span);
8787

88-
public List<Span> VisitedSpans { get; } = new List<Span>();
88+
public List<TextSpan> VisitedSpans { get; } = new List<TextSpan>();
8989
}
9090
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace System.CommandLine.Rendering.Tests
1111
{
1212
public class TextStyleRenderingTests
1313
{
14-
private readonly SpanFormatter _spanFormatter = new SpanFormatter();
14+
private readonly TextSpanFormatter _textSpanFormatter = new TextSpanFormatter();
1515
private readonly TestTerminal _terminal = new TestTerminal();
1616

1717
[Fact]
1818
public void BackgroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_rendering()
1919
{
20-
var span = _spanFormatter.ParseToSpan(
20+
var span = _textSpanFormatter.ParseToSpan(
2121
$"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each.");
2222

2323
var renderer = new ConsoleRenderer(_terminal, OutputMode.Ansi);
@@ -34,7 +34,7 @@ public void BackgroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_render
3434
[Fact]
3535
public void ForegroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_rendering()
3636
{
37-
var span = _spanFormatter.ParseToSpan(
37+
var span = _textSpanFormatter.ParseToSpan(
3838
$"{ForegroundColorSpan.Red()}red {ForegroundColorSpan.Blue()}blue {ForegroundColorSpan.Green()}green {ForegroundColorSpan.Reset()}or a {ForegroundColorSpan.Rgb(12, 34, 56)}little of each.");
3939

4040
var renderer = new ConsoleRenderer(_terminal, OutputMode.Ansi);
@@ -51,7 +51,7 @@ public void ForegroundColorSpans_are_replaced_with_ANSI_codes_during_ANSI_render
5151
[Fact]
5252
public void BackgroundColorSpans_are_replaced_with_System_Console_calls_during_non_ANSI_rendering()
5353
{
54-
var span = _spanFormatter.ParseToSpan(
54+
var span = _textSpanFormatter.ParseToSpan(
5555
$"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each.");
5656

5757
var renderer = new ConsoleRenderer(_terminal, OutputMode.NonAnsi);
@@ -80,7 +80,7 @@ public void BackgroundColorSpans_are_replaced_with_System_Console_calls_during_n
8080
[Fact]
8181
public void ForegroundColorSpans_are_replaced_with_System_Console_calls_during_non_ANSI_rendering()
8282
{
83-
var span = _spanFormatter.ParseToSpan(
83+
var span = _textSpanFormatter.ParseToSpan(
8484
$"{ForegroundColorSpan.Red()}red {ForegroundColorSpan.Blue()}blue {ForegroundColorSpan.Green()}green {ForegroundColorSpan.Reset()}or a {ForegroundColorSpan.Rgb(12, 34, 56)}little of each.");
8585

8686
var renderer = new ConsoleRenderer(_terminal, OutputMode.NonAnsi);
@@ -109,7 +109,7 @@ public void ForegroundColorSpans_are_replaced_with_System_Console_calls_during_n
109109
[Fact]
110110
public void BackgroundColorSpans_are_removed_during_file_rendering()
111111
{
112-
var span = _spanFormatter.ParseToSpan(
112+
var span = _textSpanFormatter.ParseToSpan(
113113
$"{BackgroundColorSpan.Red()}red {BackgroundColorSpan.Blue()}blue {BackgroundColorSpan.Green()}green {BackgroundColorSpan.Reset()}or a {BackgroundColorSpan.Rgb(12, 34, 56)}little of each.");
114114

115115
var renderer = new ConsoleRenderer(_terminal, OutputMode.PlainText);
@@ -124,7 +124,7 @@ public void BackgroundColorSpans_are_removed_during_file_rendering()
124124
[Fact]
125125
public void ForegroundColorSpans_are_removed_during_file_rendering()
126126
{
127-
var span = _spanFormatter.ParseToSpan(
127+
var span = _textSpanFormatter.ParseToSpan(
128128
$"{ForegroundColorSpan.Red()}red {ForegroundColorSpan.Blue()}blue {ForegroundColorSpan.Green()}green {ForegroundColorSpan.Reset()}or a {ForegroundColorSpan.Rgb(12, 34, 56)}little of each.");
129129

130130
var renderer = new ConsoleRenderer(_terminal, OutputMode.PlainText);

0 commit comments

Comments
 (0)