Rich Spectre.Console integration: renderables, visualizations, and interactive prompts
This sample showcases the Repl.Spectre package with 21 Spectre.Console features
across 15 commands. It demonstrates both direct IAnsiConsole usage for custom
renderables and the transparent prompt upgrade where IReplInteractionChannel calls
are automatically rendered as Spectre prompts.
dotnet run --project samples/07-spectre/SpectreOpsSample.csprojA multi-step flow chaining 10 Spectre features sequentially:
- FigletText — ASCII art welcome banner
- TextPrompt — ask user's name (via
AskTextAsync) - Panel — greeting panel with the name
- SelectionPrompt — choose a data category (via
AskChoiceAsync) - Table — display contacts for the chosen category
- BarChart — domain distribution visualization
- Tree — hierarchical contact breakdown
- ConfirmationPrompt — "Continue to summary?" (via
AskConfirmationAsync) - Calendar — current month with today highlighted
- Rule + Panel — divider and summary
Returns a collection; the "spectre" output transformer renders it as a bordered
table automatically. Zero rendering code in the handler.
Returns a synthetic activity feed through IReplPagingContext and
IReplPageSource<T>. The Spectre output transformer renders the requested page,
and the integrated pager can fetch more data in the same run.
dotnet run --project samples/07-spectre/SpectreOpsSample.csproj -- activity --result:page-size=8
dotnet run --project samples/07-spectre/SpectreOpsSample.csproj -- activity --result:page-size=8 --result:cursor=8Uses IAnsiConsole to render a Panel containing a Grid of contact details.
Renders a BarChart of contact counts per domain and a BreakdownChart
of email provider distribution.
Renders a Tree of contacts grouped by email domain.
Renders syntax-highlighted JSON for a contact using Spectre.Console.Json.JsonText.
Renders file paths with TextPath (syntax-highlighted path components) in a Columns layout.
Renders a Calendar with today and event dates highlighted.
Renders large ASCII art from user input.
Uses IAnsiConsole with Status().StartAsync() to show a spinner progressing
through named stages with changing colors.
Uses IAnsiConsole with Progress().StartAsync() to show multi-task progress
bars with description, percentage, and spinner columns.
Uses IReplInteractionChannel for AskTextAsync + AskChoiceAsync. With
Spectre registered, these are automatically rendered as rich Spectre prompts —
no Spectre-specific code in the handler.
Uses AskMultiChoiceAsync which renders as a Spectre MultiSelectionPrompt
with checkbox-style selection.
Shows what the terminal-integration layer detected for the current session via
IReplSessionInfo: whether shell-integration marks are active and which dialect was
negotiated (OSC 133, OSC 633 (VS Code), or off (<gate>) naming the gate that
disabled them), plus the reported identity, capabilities, and window size. It also
shows the console plumbing the framework detected — the active session writer's
encoding (name + codepage), the stdout/stdin redirection states, and the box-drawing
verdict (SpectreTerminalDetection.CurrentBoxDrawingSupport: Rounded, Square, or
Ascii transliteration) — which makes it the first thing to run when an IDE console
shows garbled output. Run it from Windows Terminal and from the VS Code integrated
terminal to see the detection change.
Uses AskSecretAsync which renders as a Spectre TextPrompt with masked input.
| Feature | Class | Used in |
|---|---|---|
| FigletText | FigletText |
tour, figlet, banner |
| Table | Table |
tour |
| Table (auto) | via output transformer | list, activity |
| Tree | Tree |
tour, tree |
| Panel | Panel |
tour, detail, json, calendar, chart |
| Rule | Rule |
tour |
| BarChart | BarChart |
tour, chart |
| BreakdownChart | BreakdownChart |
chart |
| Calendar | Calendar |
tour, calendar |
| JsonText | JsonText |
json |
| TextPath | TextPath |
path |
| Columns | Columns |
path |
| Grid | Grid |
detail |
| Markup | Markup |
throughout |
| Status | Status |
status |
| Progress | Progress |
progress |
| SelectionPrompt | via AskChoiceAsync |
tour, add |
| MultiSelectionPrompt | via AskMultiChoiceAsync |
configure |
| ConfirmationPrompt | via AskConfirmationAsync |
tour |
| TextPrompt | via AskTextAsync |
tour, add |
| TextPrompt.Secret | via AskSecretAsync |
login |
Inject IAnsiConsole into any command handler to use any Spectre renderable:
app.Map("chart", (IAnsiConsole console, IContactStore store) =>
{
var chart = new BarChart().Label("Contacts per Domain");
// ... add items ...
console.Write(chart);
});Call IReplInteractionChannel methods as usual — with Spectre registered,
they render as rich Spectre prompts automatically:
app.Map("add", async (IReplInteractionChannel channel) =>
{
var name = await channel.AskTextAsync("name", "Contact name?");
var dept = await channel.AskChoiceAsync("dept", "Department?",
["Engineering", "Sales", "Marketing"]);
});No Spectre-specific code in the handler — the same handler works with or without Spectre.
The sample uses IAnsiConsole directly in the banner callback to render
a FigletText header at startup:
.WithBanner((IAnsiConsole console) =>
{
console.Write(new FigletText("Spectre").Color(Color.Blue));
console.MarkupLine(" [grey]Commands:[/] tour, list, detail, ...");
})UseSpectreConsole() accepts an optional configuration callback:
// Default: Unicode enabled, UTF-8 output encoding
.UseSpectreConsole()
// Disable Unicode for terminals that don't support it
.UseSpectreConsole(o => o.Unicode = false)When Unicode is true (the default), UseSpectreConsole sets
Console.OutputEncoding to UTF-8 so that box-drawing characters,
progress bars, and spinners render correctly on Windows.
You now have the full progressive path:
- Routing and parsing (01)
- Scopes and DI (02)
- Composable modules (03)
- Interaction channel (04)
- Remote hosting (05)
- Testing toolkit (06)
- Spectre.Console integration (07)
See also: Repl.Spectre package README
for the integration API reference.