English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

RazorConsole: Build Interactive Terminal UIs with Razor Components and Spectre.Console

Forum topic · ✨步子哥 · 2026-03-27

Summary

RazorConsole is an open-source .NET library that brings Razor component syntax from web development into terminal applications. Built on top of Spectre.Console, it uses a Virtual DOM translation pipeline to convert Razor components into IRenderable objects, enabling component-based UI, data binding, event handling, and lifecycle management in the console. The project positions itself between Spectre.Console (beautiful static output but limited interactivity) and traditional TUI frameworks like Gui.cs. It ships 25+ built-in components covering layout, containers, text, charts, and interactive elements such as buttons, text inputs, selects, spinners, and scrollable views. Official examples include a Counter demo, a Claude Code-style LLM agent chat interface (LLMAgentTUI) integrating Microsoft.Extensions.AI with OpenAI or Ollama, a LoginForm, a FileExplorer, and a multipage app. As of March 26, 2026, the project has 1.7k stars, 44 forks, an MIT license, and v0.5.0 released March 17. Hot reload, a component gallery tool, and an active Discord community round out the ecosystem.

RazorConsole is an open-source .NET library that lets developers build rich, interactive terminal user interfaces (TUIs) using familiar Razor component syntax — the same model behind Blazor web development — instead of manually handling keyboard events, screen refreshing, and layout math.

Key points

  • Core concept: RazorConsole translates Razor components (e.g., <Rows>, <TextButton>) into terminal-renderable objects. It sits on top of Spectre.Console and fills the gap between Spectre.Console's beautiful-but-mostly-static output and traditional TUI frameworks like Gui.cs.
  • How it works:
  • 1. Author components in Razor syntax. 2. At runtime, a Virtual DOM (a tree of VNodes) captures UI state and changes. 3. A Translator pipeline (built-in + custom) converts VNodes into Spectre.Console IRenderable objects. 4. Spectre.Console handles rendering and the keyboard/mouse event loop.
  • Custom translators implement IVdomElementTranslator; hot reload via metadata handlers makes iteration fast.
  • Getting started (roughly 10 minutes):
  • dotnet add package RazorConsole.Core
  • Change the SDK in the .csproj to Microsoft.NET.Sdk.Razor.
  • In Program.cs, build a host and call .UseRazorConsole<Counter>(), then Build() and RunAsync().
  • Built-in components (25+):
  • Layout: Rows, Columns, FlexBox, Grid, Align, Padder
  • Containers: Panel, Border
  • Text: Markup, Figlet, Newline
  • Charts: BarChart, BreakdownChart, StepChart, SpectreCanvas
  • Interactive: TextButton (OnClick), TextInput (ValueChanged, password masking), Select, Spinner, Scrollable
  • Tables/code: Table, SyntaxHighlighter (HTML-like <thead><tr><th> syntax)
  • Highlighted examples:
  • LLMAgentTUI: a Claude Code-style LLM chat TUI integrating the Microsoft.Extensions.AI SDK with OpenAI or Ollama, featuring streaming output, conversation history, and spinner loading states.
  • LoginForm: form validation, password masking, error messages.
  • FileExplorer and MultipageApp: keyboard-navigable file browsing and multi-page structure.
  • A Counter demo demonstrates state management and event binding in a few lines of Razor.
  • Ecosystem: a razorconsole-gallery global dotnet tool previews all components interactively; a Discord community, Git LFS-based contribution workflow, xUnit tests, and Codecov coverage support the project. A developer used it to build the game *Waves* for GitHub Game Off 2025.

Project status

As of March 26, 2026: ~1.7k GitHub stars, 44 forks, MIT license, latest stable release v0.5.0 (March 17), with active rapid iteration. Documentation is still maturing; the design doc covers advanced features.

Assessment

For developers who already know Razor/Blazor, RazorConsole offers a low learning curve, strong extensibility, and Spectre.Console's polished rendering for free. Weaknesses are the early version and incomplete docs. It is particularly well suited to building agentic TUIs — AI assistant interfaces, live dashboards, and keyboard-driven tools.

References

1. GitHub repository: https://github.com/RazorConsole/RazorConsole 2. Official site: https://razorconsole.github.io/RazorConsole/ 3. Spectre.Console documentation (underlying rendering engine) 4. Microsoft.Extensions.AI SDK integration (LLMAgentTUI basis) 5. .NET Razor SDK and Blazor component model documentation

Tags

#razorconsole#dotnet#terminal-ui#spectre-console#blazor#razor-components#virtual-dom#ai-agents

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177169088