Skip to content

Fixes #5391, #5392. Add Terminal.Gui.Interop.Spectre with SpectreView and style bridge#5393

Open
Copilot wants to merge 11 commits into
developfrom
copilot/add-spectreview-rendering
Open

Fixes #5391, #5392. Add Terminal.Gui.Interop.Spectre with SpectreView and style bridge#5393
Copilot wants to merge 11 commits into
developfrom
copilot/add-spectreview-rendering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 24, 2026

Summary

Adds Terminal.Gui.Interop.Spectre — a separate assembly that bridges Spectre.Console rendering into Terminal.Gui applications.

Fixes #5391 — Style/Color conversion bridge
Fixes #5392 — SpectreView for rendering any IRenderable

SpectreView Scenario Demo

What's Included

SpectreView : View

A read-only View that renders any Spectre.Console IRenderable:

// Render a Spectre Table
spectreView.Renderable = new Table ().AddColumn ("Name").AddRow ("Alice");

// Render Spectre Markup (Markup implements IRenderable)
spectreView.Renderable = new Markup ("[bold red]Hello[/] [green]World[/]");

SpectreMarkupBridge

Bidirectional style conversion:

  • Style.ToAttribute() — Spectre → TG (colors + decorations)
  • Attribute.ToSpectreStyle() — TG → Spectre (round-trip safe)

UICatalog Scenario

"Spectre" scenario demonstrating Table, Panel, Rule, Tree, BarChart, Calendar, FigletText, and Markup rendering.

Architecture

  • Separate assembly (Terminal.Gui.Interop.Spectre) — no Spectre dependency in core TG
  • AOT-compatible, trimmable
  • NuGet package: Terminal.Gui.Interop.Spectre
  • Added to Terminal.sln

Tests

10 tests covering: style conversion, reverse conversion, round-trip, default/none colors, Markup rendering, Table/Panel/Rule/Tree/BarChart/FigletText, re-render on change, DimAuto content sizing, integration with Window.

Copilot AI changed the title [WIP] Add SpectreView to render IRenderable in Terminal.Gui app Add SpectreView to render Spectre.Console IRenderable inside Terminal.Gui May 24, 2026
Copilot finished work on behalf of tig May 24, 2026 00:35
Copilot AI requested a review from tig May 24, 2026 00:35
@tig
Copy link
Copy Markdown
Member

tig commented May 24, 2026

@copilot add a UICatalog scenario that shows this off.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 24, 2026

@copilot add a UICatalog scenario that shows this off.

Added in commit 18f49b7.

I introduced a new UICatalog scenario: SpectreView Interop (Examples/UICatalog/Scenarios/SpectreViewScenario.cs) and wired UICatalog.csproj to reference Terminal.Gui.Interop.Spectre.

Screenshot: https://github.com/user-attachments/assets/e3cb63b3-0e3d-4cb0-ad22-1841bedd581d

Copilot AI changed the title Add SpectreView to render Spectre.Console IRenderable inside Terminal.Gui Add SpectreView interop and UICatalog scenario for Spectre.Console renderables May 24, 2026
Copilot finished work on behalf of tig May 24, 2026 01:44
@tig
Copy link
Copy Markdown
Member

tig commented May 24, 2026

@copilot use gui-cs/tuirec to record a gif of the new scenario in action and add the gif to docs/images.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 24, 2026

@copilot use gui-cs/tuirec to record a gif of the new scenario in action and add the gif to docs/images.

Done in c6c6ff7.

I recorded the new SpectreView Interop scenario with gui-cs/tuirec and added the GIF at docfx/images/spectreview-interop.gif.

Preview: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/c6c6ff7/docfx/images/spectreview-interop.gif

Copilot AI changed the title Add SpectreView interop and UICatalog scenario for Spectre.Console renderables Add SpectreView interop, UICatalog scenario, and demo GIF for Spectre.Console renderables May 24, 2026
Copilot finished work on behalf of tig May 24, 2026 01:53
@tig
Copy link
Copy Markdown
Member

tig commented May 24, 2026

@copilot that video does not show anything. Keep trying. Document what you learned doing it.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 24, 2026

@copilot that video does not show anything. Keep trying. Document what you learned doing it.

Updated in b7eb9c5 with a new recording at docfx/images/spectreview-interop.gif.

Screenshot/GIF: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/b7eb9c5f1/docfx/images/spectreview-interop.gif

What I learned while retrying:

  • Recording dotnet run directly produced unusable output because startup/build timing and runtime resolution made captures inconsistent.
  • Running the scenario through a small dedicated runner that directly executes SpectreViewScenario.Main () produced a stable, visible capture.
  • I validated the cast before committing by checking it contained expected UI text (Spectre Widget, Preview, and Scenario: SpectreView Interop) and full interaction timing.

Copilot AI changed the title Add SpectreView interop, UICatalog scenario, and demo GIF for Spectre.Console renderables Add SpectreView interop, UICatalog scenario, and validated demo GIF for Spectre.Console renderables May 24, 2026
Copilot finished work on behalf of tig May 24, 2026 02:09
@tig
Copy link
Copy Markdown
Member

tig commented May 24, 2026

@copilot see the code cleanup .md doc in ./.claude and use it on all touched files.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 24, 2026

@copilot see the code cleanup .md doc in ./.claude and use it on all touched files.

Applied the .claude cleanup guidance across touched source/test files in 959e784.

I cleaned the touched files to align with the style checklist (notably brace placement and initializer formatting):

  • Examples/UICatalog/Scenarios/SpectreViewScenario.cs
  • Tests/UnitTestsParallelizable/Interop/Spectre/SpectreViewTests.cs

Validation run:

  • dotnet build Examples/UICatalog/UICatalog.csproj --no-restore /p:DisableGitVersionTask=true
  • dotnet test --project Tests/UnitTestsParallelizable --filter-class "*SpectreViewTests" /p:DisableGitVersionTask=true

Screenshot/GIF (current scenario preview): https://raw.githubusercontent.com/gui-cs/Terminal.Gui/959e784/docfx/images/spectreview-interop.gif

Copilot AI changed the title Add SpectreView interop, UICatalog scenario, and validated demo GIF for Spectre.Console renderables Add SpectreView interop, UICatalog scenario, validated demo GIF, and touched-file cleanup May 24, 2026
Copilot finished work on behalf of tig May 24, 2026 02:39
@tig
Copy link
Copy Markdown
Member

tig commented May 24, 2026

@copilot that video does not show anything. Keep trying. Document what you learned doing it.

Updated in b7eb9c5 with a new recording at docfx/images/spectreview-interop.gif.

Screenshot/GIF: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/b7eb9c5f1/docfx/images/spectreview-interop.gif

What I learned while retrying:

  • Recording dotnet run directly produced unusable output because startup/build timing and runtime resolution made captures inconsistent.
  • Running the scenario through a small dedicated runner that directly executes SpectreViewScenario.Main () produced a stable, visible capture.
  • I validated the cast before committing by checking it contained expected UI text (Spectre Widget, Preview, and Scenario: SpectreView Interop) and full interaction timing.

@copilot create ./scripts/tuirec.md. In it provide guidance to agents on using tuirec to record TG apps. See ./hero-gif.md and borrow from it as well, simplifying that file so it references tuirec.md.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 24, 2026

@copilot that video does not show anything. Keep trying. Document what you learned doing it.
...

Implemented in 248df34.

Added:

  • ./scripts/tuirec.md with agent-focused guidance for recording Terminal.Gui apps/scenarios with tuirec, including workflow, validation checklist, and retry guidance.

Simplified:

  • ./hero-gif.md to a minimal pointer to ./scripts/tuirec.md.

GIF preview link: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/248df34/docfx/images/spectreview-interop.gif

Copilot AI changed the title Add SpectreView interop, UICatalog scenario, validated demo GIF, and touched-file cleanup Add SpectreView interop, UICatalog scenario, validated demo GIF, and tuirec recording guidance docs May 24, 2026
Copilot finished work on behalf of tig May 24, 2026 02:46
tig and others added 2 commits May 24, 2026 07:44
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add SpectreMarkupBridge.ToSpectreStyle() for TG->Spectre conversion
- Add NuGet package metadata to interop project
- Add project to Terminal.sln
- Add tests for round-trip, Markup IRenderable, default/none colors
- Rename scenario to 'Spectre' / 'Demonstrates Spectre.Console integration'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tig tig changed the title Add SpectreView interop, UICatalog scenario, validated demo GIF, and tuirec recording guidance docs Fixes #5391, #5392. Add Terminal.Gui.Interop.Spectre with SpectreView and style bridge May 24, 2026
tig and others added 2 commits May 24, 2026 07:55
Cycles through Table, Panel, Rule, Tree, BarChart, Calendar, Figlet, Markup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tig tig marked this pull request as ready for review May 24, 2026 14:08
@tig tig requested review from BDisp and Copilot May 24, 2026 14:12
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 79cb212af2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +87 to +89
if (string.IsNullOrEmpty (segment.Text))
{
continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ignore control-code segments during rendering

Spectre renderables can emit control segments (IsControlCode == true) that represent ANSI cursor/control instructions rather than displayable text, but this loop only skips line breaks and empty strings. As a result, custom IRenderable implementations that yield control segments will have those escape bytes treated as visible text and will also shift subsequent content width calculations, causing garbled output and misaligned rendering in SpectreView.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Terminal.Gui.Interop.Spectre assembly to embed Spectre.Console renderables inside Terminal.Gui apps, plus a UICatalog scenario and unit tests to validate rendering and style conversion.

Changes:

  • Introduces SpectreView : View for rendering any Spectre IRenderable and reporting content size for Dim.Auto.
  • Adds SpectreMarkupBridge extension methods to convert between Spectre Style and Terminal.Gui Attribute (colors + decorations).
  • Wires the new project into the solution, UICatalog, and the parallelizable test project; adds a UICatalog “Spectre” scenario and corresponding tests.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj References the new interop project from the parallel test suite.
Tests/UnitTestsParallelizable/Interop/Spectre/SpectreViewTests.cs Adds tests for style conversion and basic render/output behaviors.
Terminal.sln Adds the new interop project to the solution.
Terminal.Gui.Interop.Spectre/Terminal.Gui.Interop.Spectre.csproj New project/packaging metadata and Spectre.Console dependency.
Terminal.Gui.Interop.Spectre/SpectreView.cs Implements the View that renders Spectre segments into Terminal.Gui drawing calls.
Terminal.Gui.Interop.Spectre/SpectreMarkupBridge.cs Implements Spectre Style ↔ Terminal.Gui Attribute conversion helpers.
Examples/UICatalog/UICatalog.csproj References the new interop project so scenarios can use it.
Examples/UICatalog/Scenarios/SpectreViewScenario.cs New scenario demonstrating multiple Spectre widgets rendered via SpectreView.
Directory.Packages.props Adds the centrally-managed Spectre.Console package version.

Comment on lines +92 to +94
DrawSegment (segment, row, col);
col += segment.Text.GetColumns ();
}
Comment on lines +145 to +149
private static (IReadOnlyList<Segment> Segments, int ContentWidth, int ContentHeight) RenderSegments (IRenderable renderable, int maxWidth)
{
RenderOptions renderOptions = RenderOptions.Create (global::Spectre.Console.AnsiConsole.Console, null);
Measurement measurement = renderable.Measure (renderOptions, maxWidth);
List<Segment> segments = [.. renderable.Render (renderOptions, maxWidth)];
Comment on lines +7 to +26
<ItemGroup>
<PackageReference Include="Spectre.Console" />
</ItemGroup>

<PropertyGroup>
<AssemblyName>Terminal.Gui.Interop.Spectre</AssemblyName>
<RootNamespace>Terminal.Gui.Interop.Spectre</RootNamespace>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsTrimmable>true</IsTrimmable>
<IsAotCompatible>true</IsAotCompatible>
<PackageId>Terminal.Gui.Interop.Spectre</PackageId>
<Description>Bridge package for rendering Spectre.Console IRenderable widgets inside Terminal.Gui applications.</Description>
<Authors>gui-cs contributors</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/gui-cs/Terminal.Gui</PackageProjectUrl>
<RepositoryUrl>https://github.com/gui-cs/Terminal.Gui</RepositoryUrl>
<PackageTags>terminal;gui;console;spectre;interop</PackageTags>
</PropertyGroup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants