Skip to content

Commit 88d8571

Browse files
Add dependency on Spectre.Console.Ansi
1 parent f4a3acb commit 88d8571

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+264
-3790
lines changed

src/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<PackageVersion Include="Polyfill" Version="8.9.0" />
1111
<PackageVersion Include="Roslynator.Analyzers" PrivateAssets="All" Version="4.14.1" />
1212
<PackageVersion Include="Shouldly" Version="4.3.0" />
13+
<PackageVersion Include="Spectre.Console.Ansi" Version="0.54.1-alpha.0.33" />
1314
<PackageVersion Include="Spectre.Verify.Extensions" Version="28.16.0" />
1415
<PackageVersion Include="System.Memory" Version="4.6.3" />
1516
<PackageVersion Include="Verify.Xunit" Version="31.8.0" />

src/Sandbox/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Text;
2+
using Spectre.Console;
13
using Spectre.Tui;
24

35
namespace Sandbox;
@@ -13,6 +15,7 @@ public static void Main(string[] args)
1315
renderer.SetTargetFps(60);
1416

1517
Console.Title = "Spectre.Tui Sandbox";
18+
Console.OutputEncoding = Encoding.Unicode;
1619

1720
while (running)
1821
{
@@ -36,9 +39,10 @@ public static void Main(string[] args)
3639

3740
// Some text
3841
ctx.Render(Text.FromMarkup(
39-
"""
42+
$"""
4043
नमस्ते [red]Happy Holidays[/] 🎅 Happy Holidays\n[u]Happy Holidays[/]
4144
Happy Holidays [yellow bold]Happy Holidays[/] Happy Holidays Happy Holidays
45+
{ctx.Viewport.Width} x {ctx.Viewport.Height}
4246
""", Color.Green),
4347
inner.Inflate(-1, -1));
4448
});

src/Sandbox/Widgets/BoxWidget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Spectre.Console;
12
using Spectre.Tui;
23

34
namespace Sandbox;

src/Sandbox/Widgets/ClearWidget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Spectre.Console;
12
using Spectre.Tui;
23

34
namespace Sandbox;

src/Sandbox/Widgets/FpsWidget.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
using Spectre.Console;
12
using Spectre.Tui;
23

34
namespace Sandbox;
45

56
public sealed class FpsWidget : IWidget
67
{
78
private readonly string _text;
8-
private readonly Style _style;
9+
private readonly Appearance _style;
910

1011
public FpsWidget(
1112
TimeSpan elapsed,
@@ -15,7 +16,7 @@ public FpsWidget(
1516
var fps = TimeSpan.FromSeconds(1) / elapsed;
1617

1718
_text = $"[yellow]FPS:[/] {fps:0.000}";
18-
_style = new Style
19+
_style = new Appearance
1920
{
2021
Foreground = foreground ?? Color.Default,
2122
Background = background ?? Color.Default,
@@ -24,11 +25,14 @@ public FpsWidget(
2425

2526
public void Render(RenderContext context)
2627
{
28+
var text = Text.FromMarkup(_text, _style);
29+
var width = text.GetWidth();
30+
2731
context.Render(
28-
Text.FromMarkup(_text, _style),
32+
text,
2933
new Rectangle(
30-
(context.Viewport.Width - _text.Length) / 2,
34+
(context.Viewport.Width - width) / 2,
3135
context.Viewport.Height / 2,
32-
_text.Length, 1));
36+
width, 1));
3337
}
3438
}

src/Spectre.Tui.Testing/AnsiTestTerminal.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Spectre.Console;
12
using Spectre.Tui.Ansi;
23

34
namespace Spectre.Tui.Testing;
@@ -6,11 +7,18 @@ public sealed class AnsiTestTerminal : AnsiTerminal, ITestTerminal
67
{
78
private readonly Size _size;
89

9-
1010
public string Output { get; private set; } = "[Terminal buffer not flushed]";
1111

12-
public AnsiTestTerminal(ColorSystem colors, Size? size = null)
13-
: base(colors)
12+
public AnsiTestTerminal(
13+
ColorSystem colors = ColorSystem.TrueColor,
14+
Size? size = null)
15+
: base(new AnsiCapabilities
16+
{
17+
Ansi = true,
18+
ColorSystem = colors,
19+
Links = true,
20+
AlternateBuffer = true,
21+
})
1422
{
1523
_size = size ?? new Size(80, 25);
1624
}

src/Spectre.Tui.Testing/TuiFixture.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,13 @@ public TuiFixture(ITestTerminal terminal)
1919

2020
public string Render(IWidget widget)
2121
{
22-
_renderer.Draw((frame, _) =>
23-
{
24-
frame.Render(widget);
25-
});
26-
22+
_renderer.Draw((frame, _) => frame.Render(widget));
2723
return _terminal.Output;
2824
}
2925

3026
public string Render(Action<RenderContext> action)
3127
{
32-
_renderer.Draw((frame, _) =>
33-
{
34-
action(frame);
35-
});
36-
28+
_renderer.Draw((frame, _) => action(frame));
3729
return _terminal.Output;
3830
}
3931
}

src/Spectre.Tui.Tests/CellTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Spectre.Console;
2+
13
namespace Spectre.Tui.Tests;
24

35
public sealed class CellTests

src/Spectre.Tui.Tests/Text/TextLineTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Spectre.Console;
2+
13
namespace Spectre.Tui.Tests;
24

35
public sealed class TextLineTests
@@ -22,7 +24,7 @@ public void Should_Set_Style()
2224
var line = TextLine.FromString("Hello\nWorld", Color.Red);
2325

2426
// Then
25-
line.Style.ShouldBe(new Style
27+
line.Style.ShouldBe(new Appearance
2628
{
2729
Foreground = Color.Red,
2830
});

src/Spectre.Tui.Tests/Text/TextSpanTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Spectre.Console;
2+
13
namespace Spectre.Tui.Tests;
24

35
public sealed class TextSpanTests
@@ -21,7 +23,7 @@ public void Should_Set_Style()
2123
var span = new TextSpan("Hello World", Color.Red);
2224

2325
// Then
24-
span.Style.ShouldBe(new Style
26+
span.Style.ShouldBe(new Appearance
2527
{
2628
Foreground = Color.Red
2729
});

0 commit comments

Comments
 (0)