Fixes #5391, #5392. Add Terminal.Gui.Interop.Spectre with SpectreView and style bridge#5393
Fixes #5391, #5392. Add Terminal.Gui.Interop.Spectre with SpectreView and style bridge#5393Copilot wants to merge 11 commits into
Conversation
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/7113b76f-a6aa-4ba6-a74f-c5cdbaf39f4a Co-authored-by: tig <585482+tig@users.noreply.github.com>
|
@copilot add a UICatalog scenario that shows this off. |
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/8f20c41f-e3ce-4e4a-a667-bdf8cfbeaabd Co-authored-by: tig <585482+tig@users.noreply.github.com>
Added in commit I introduced a new UICatalog scenario: Screenshot: https://github.com/user-attachments/assets/e3cb63b3-0e3d-4cb0-ad22-1841bedd581d |
|
@copilot use gui-cs/tuirec to record a gif of the new scenario in action and add the gif to docs/images. |
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/f35cf387-5838-43a1-8bd9-28c882fe97af Co-authored-by: tig <585482+tig@users.noreply.github.com>
Done in I recorded the new Preview: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/c6c6ff7/docfx/images/spectreview-interop.gif |
|
@copilot that video does not show anything. Keep trying. Document what you learned doing it. |
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/b17a0837-992b-4a05-92f2-b1d8b62b83f2 Co-authored-by: tig <585482+tig@users.noreply.github.com>
Updated in Screenshot/GIF: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/b7eb9c5f1/docfx/images/spectreview-interop.gif What I learned while retrying:
|
|
@copilot see the code cleanup .md doc in ./.claude and use it on all touched files. |
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/588b85ed-beb4-452b-9967-f8f75eac4f93 Co-authored-by: tig <585482+tig@users.noreply.github.com>
Applied the I cleaned the touched files to align with the style checklist (notably brace placement and initializer formatting):
Validation run:
Screenshot/GIF (current scenario preview): https://raw.githubusercontent.com/gui-cs/Terminal.Gui/959e784/docfx/images/spectreview-interop.gif |
@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. |
Agent-Logs-Url: https://github.com/gui-cs/Terminal.Gui/sessions/e51b923f-3781-4315-8458-2ffa6138ea61 Co-authored-by: tig <585482+tig@users.noreply.github.com>
Implemented in Added:
Simplified:
GIF preview link: https://raw.githubusercontent.com/gui-cs/Terminal.Gui/248df34/docfx/images/spectreview-interop.gif |
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>
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>
There was a problem hiding this comment.
💡 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".
| if (string.IsNullOrEmpty (segment.Text)) | ||
| { | ||
| continue; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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 : Viewfor rendering any SpectreIRenderableand reporting content size forDim.Auto. - Adds
SpectreMarkupBridgeextension methods to convert between SpectreStyleand Terminal.GuiAttribute(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. |
| DrawSegment (segment, row, col); | ||
| col += segment.Text.GetColumns (); | ||
| } |
| 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)]; |
| <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> |
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
What's Included
SpectreView : ViewA read-only View that renders any Spectre.Console
IRenderable:SpectreMarkupBridgeBidirectional 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
Terminal.Gui.Interop.Spectre) — no Spectre dependency in core TGTerminal.Gui.Interop.SpectreTerminal.slnTests
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.