RazorConsole.Core 0.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package RazorConsole.Core --version 0.2.2
                    
NuGet\Install-Package RazorConsole.Core -Version 0.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RazorConsole.Core" Version="0.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RazorConsole.Core" Version="0.2.2" />
                    
Directory.Packages.props
<PackageReference Include="RazorConsole.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RazorConsole.Core --version 0.2.2
                    
#r "nuget: RazorConsole.Core, 0.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RazorConsole.Core@0.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RazorConsole.Core&version=0.2.2
                    
Install as a Cake Addin
#tool nuget:?package=RazorConsole.Core&version=0.2.2
                    
Install as a Cake Tool

<div align="center">

<img src="./assets/razor_console logo.svg" alt="RazorConsole Logo" width="128" height="128" />

RazorConsole

NuGet (Stable) NuGet (Nightly) Component Gallery NuGet Downloads

GitHub Release License: MIT .NET codecov

Discord

Build rich, interactive console applications using familiar Razor syntax and the power of Spectre.Console

</div>

🎯 What is RazorConsole?

RazorConsole bridges the gap between modern web UI development and console applications. It lets you create sophisticated terminal interfaces using Razor components, complete with interactive elements, rich styling, and familiar development patterns.

📦 Install

dotnet add package RazorConsole.Core

🚀 Usage

Project Setup

RazorConsole requires the Microsoft.NET.Sdk.Razor SDK to compile Razor components. Update your project file (.csproj) to use the Razor SDK:

<Project Sdk="Microsoft.NET.Sdk.Razor">
    
</Project>

Basic Example

Here's a simple counter component to get you started:

Counter.razor
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Web
@using RazorConsole.Components

<Columns>
    <p>Current count</p>
    <Markup Content="@currentCount.ToString()" Foreground="@Spectre.Console.Color.Green" />
</Columns>
<TextButton Content="Click me"
            OnClick="IncrementCount"
            BackgroundColor="@Spectre.Console.Color.Grey"
            FocusedColor="@Spectre.Console.Color.Blue" />


@code {
    private int currentCount = 0;
    private void IncrementCount()
    {
        currentCount++;
    }
}
Program.cs
using Microsoft.Extensions.Hosting;
using RazorConsole.Core;

IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args)
    .UseRazorConsole<Counter>();
IHost host = hostBuilder.Build();
await host.RunAsync();

Image

For more complete sample applications, check out the Examples section below.

✨ Key Features

🧩 Component-Based Architecture

Build your console UI using familiar Razor components with full support for data binding, event handling, and component lifecycle methods.

🎮 Interactive Components

Create engaging user experiences with interactive elements like buttons, text inputs, selectors, and keyboard navigation - all with focus management handled automatically.

🎯 Built-in Component Library

Get started quickly with 20+ pre-built components covering layout, input, display, and navigation needs:

  • Layout (6): Align, Columns, Rows, Grid, Padder, Scrollable
  • Input (3): TextInput, TextButton, Select
  • Display (11): BarChart, BreakdownChart, StepChart, Border, Figlet, Markdown, Markup, Panel, SpectreCanvas, SyntaxHighlighter, Table
  • Utilities (2): Spinner, Newline

For a full list of components and usage details, see the Built-in Components section below.

Hot Reload Support

Experience rapid development with built-in hot reload support. See your UI changes instantly without restarting your application.

Explore all components hands-on with the included interactive gallery tool. Install globally and run razorconsole-gallery to see live examples of every component in action.

For more details, see the Component Gallery section below.

Built-in components

RazorConsole ships with a catalog of ready-to-use components that wrap Spectre.Console constructs:

  • Align – position child content horizontally and vertically within a fixed box.
  • BarChart – Renders a horizontal bar chart with optional label, colors and value display.
  • Border – draw Spectre borders with customizable style, color, and padding.
  • BreakdownChart – Renders a colorful breakdown (pie-style) chart showing proportions with optional legend and values.
  • Columns – arrange items side-by-side, optionally stretching to fill the console width.
  • Figlet – render big ASCII art text using FIGlet fonts.
  • Grid – build multi-row, multi-column layouts with precise cell control.
  • Markup – emit styled text with Spectre markup tags.
  • Markdown - render markdown string.
  • Newline – insert intentional spacing between renderables.
  • Padder – add outer padding around child content without altering the child itself.
  • Panel – frame content inside a titled container with border and padding options.
  • Rows – stack child content vertically with optional expansion behavior.
  • Scrollable - enables keyboard-based vertical scrolling through the component's content, including nested components or HTML markup.
  • Select – present a focusable option list with keyboard navigation.
  • SpectreCanvas - draws an array of pixels with different colors.
  • Spinner – show animated progress indicators using Spectre spinner presets.
  • StepChart – Renders a terminal step chart using Unicode box-drawing characters. Perfect for displaying discrete value changes over time or categories.
  • SyntaxHighlighter – colorize code snippets using ColorCode themes.
  • Table – display structured data in formatted tables with headers, borders, and rich cell content.
  • TextButton – display clickable text with focus and pressed-state styling.
  • TextInput – capture user input with optional masking and change handlers.

See design-doc/builtin-components.md for the full reference, including parameters and customization tips.

Custom Translators

RazorConsole uses a Virtual DOM (VDOM) translation system to convert Razor components into Spectre.Console renderables. You can extend this system by creating custom translators to support additional Spectre.Console features or build entirely custom components.

Creating a Custom Translator

Implement the IVdomElementTranslator interface to create a custom translator:

using RazorConsole.Core.Rendering.Vdom;
using RazorConsole.Core.Vdom;
using Spectre.Console;
using Spectre.Console.Rendering;

public sealed class OverflowElementTranslator : IVdomElementTranslator
{
    // Lower priority values are processed first (1-1000+)
    public int Priority => 85;

    public bool TryTranslate(VNode node, TranslationContext context, out IRenderable? renderable)
    {
        renderable = null;

        // Check if this is a div with overflow attribute
        if (node.Kind != VNodeKind.Element || 
            !string.Equals(node.TagName, "div", StringComparison.OrdinalIgnoreCase))
        {
            return false;
        }

        if (!node.Attributes.TryGetValue("data-overflow", out var overflowType))
        {
            return false;
        }

        // Translate child nodes
        if (!VdomSpectreTranslator.TryConvertChildrenToRenderables(
            node.Children, context, out var children))
        {
            return false;
        }

        var content = VdomSpectreTranslator.ComposeChildContent(children);

        // Create renderable with overflow handling
        renderable = overflowType?.ToLowerInvariant() switch
        {
            "ellipsis" => new Padder(content).Overflow(Overflow.Ellipsis),
            "crop" => new Padder(content).Overflow(Overflow.Crop),
            "fold" => new Padder(content).Overflow(Overflow.Fold),
            _ => content
        };

        return true;
    }
}

Registering a Custom Translator

Register your translator in your application's service configuration:

using Microsoft.Extensions.Hosting;
using RazorConsole.Core;
using RazorConsole.Core.Vdom;

IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args)
    .UseRazorConsole<MyComponent>(configure: config => 
        {
            config.ConfigureServices(services =>
            { 
                // Register your custom translator
                services.AddVdomTranslator<OverflowElementTranslator>();   
            });
        }
    );

IHost host = hostBuilder.Build();
await host.RunAsync();

Using Custom Translators in Components

Once registered, use your custom translator in Razor components:

<div data-overflow="ellipsis">
    This text will be truncated with ellipsis if it's too long
</div>

Learn More

For comprehensive documentation on custom translators, including:

  • Architecture overview and translation pipeline
  • Complete reference of built-in translators and priorities
  • Utility methods for common translation tasks
  • Best practices and advanced scenarios
  • Troubleshooting and testing strategies

See the full guide at design-doc/custom-translators.md.

Explore the built-in components interactively with the RazorConsole Component Gallery. Install the tool globally and launch it from any terminal:

dotnet tool install --global RazorConsole.Gallery --version 0.0.3-alpha.4657e6

After installation, run razorconsole-gallery to open the showcase and browse component examples rendered in the console. The gallery includes quick links back to this README for more details.

Component Gallery

Examples

Check out the examples/ folder for complete sample applications that demonstrate RazorConsole in action:

Counter

A simple counter application that demonstrates the basics of RazorConsole:

  • Interactive buttons with keyboard navigation
  • State management and event handling
  • Layout with Rows, Columns, and Panels
  • Styled text with Markup and Figlet components

Perfect for getting started with RazorConsole. See examples/Counter/ for the complete implementation.

LLM Agent TUI

A Claude Code-inspired chat interface that demonstrates:

  • Integration with Microsoft.Extensions.AI SDK
  • Support for multiple LLM providers (OpenAI, Ollama)
  • Interactive chat with conversation history
  • Real-time message updates and loading states
  • Professional TUI design with panels and styled components

See examples/LLMAgentTUI/ for the complete implementation and setup instructions.

Login Form

A CLI login screen that demonstrates form validation and input handling:

  • TextInput for username entry with validation
  • Password input using TextInput with masking (MaskInput=true)
  • Interactive TextButton components for actions
  • Input validation with minimum length requirements
  • Error highlighting with dynamic border colors
  • Real-time validation feedback and error messages
  • Login/logout state management

See examples/LoginForm/ for the complete implementation.

HotReload

RazorConsole supports hotreload via metadata update handler so you can apply UI changes on the fly.

Development

Code Coverage

This project uses Codecov for code coverage reporting. Coverage reports are automatically generated during CI builds using Microsoft Testing Platform (MTP) code coverage extension with xUnit.net v3. Coverage data is collected in Cobertura format and uploaded to Codecov for tracking and visualization.

You can view the latest coverage reports at codecov.io/gh/RazorConsole/RazorConsole.

Git LFS

This repository uses Git LFS for tracking large media files. If you're contributing or cloning the repository, make sure you have Git LFS installed:

# Install Git LFS (if not already installed)
git lfs install

# Clone the repository (LFS files will be downloaded automatically)
git clone https://github.com/RazorConsole/RazorConsole.git

The following file types are automatically tracked by Git LFS:

  • Images: *.gif, *.png, *.jpg, *.jpeg
  • Videos: *.mp4, *.mov, *.avi
  • Archives: *.zip, *.tar.gz
  • Documents: *.pdf

Showcase

Projects built with RazorConsole:

  • Waves - GitHub Game Off 2025 entry

Want to showcase your project? Submit a PR to add it here!

Community & support

License

This project is distributed under the MIT License. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 24 12/29/2025
0.3.0-alpha.20251226-7c4c625 58 12/26/2025
0.3.0-alpha.20251225-4d1e971 114 12/25/2025
0.3.0-alpha.20251224-afd4d89 115 12/24/2025
0.3.0-alpha.20251223-1266b08 116 12/23/2025
0.3.0-alpha.20251219-6a98e88 135 12/19/2025
0.3.0-alpha.20251219-69401b4 133 12/19/2025
0.3.0-alpha.20251212-21ba89b 80 12/12/2025
0.3.0-alpha.20251210-74235ee 373 12/10/2025
0.3.0-alpha.20251207-3e3336f 173 12/7/2025
0.2.2 458 12/7/2025
0.2.2-alpha.20251206-143ae7a 79 12/6/2025
0.2.2-alpha.20251205-b59b3d9 116 12/5/2025
0.2.2-alpha.20251201-0ed2924 446 12/1/2025
0.2.2-alpha.20251130-9bef8c6 208 11/30/2025
0.2.2-alpha.20251129-a981b67 65 11/29/2025
0.2.2-alpha.20251127-b80d413 139 11/27/2025
0.2.2-alpha.20251127-17fde83 128 11/27/2025
0.2.1 329 11/27/2025
0.2.1-alpha.20251127-d2fed02 122 11/27/2025
0.2.0 181 11/26/2025
0.2.0-alpha.20251127-cd8f714 125 11/27/2025
0.2.0-alpha.20251126-fa619cb 133 11/26/2025
0.2.0-alpha.20251126-b4b1984 126 11/26/2025
0.2.0-alpha.20251126-26d43f5 126 11/26/2025
0.2.0-alpha.20251125-e5c704f 129 11/25/2025
0.2.0-alpha.20251125-c25ad97 130 11/25/2025
0.2.0-alpha.20251125-bbb9e7c 127 11/25/2025
0.2.0-alpha.20251125-84fb574 131 11/25/2025
0.2.0-alpha.20251125-0bad317 123 11/25/2025
0.2.0-alpha.20251125-08dc71f 134 11/25/2025
0.2.0-alpha.20251123-7f8b119 136 11/23/2025
0.2.0-alpha.20251122-d8272b4 176 11/22/2025
0.2.0-alpha.20251122-a040cbe 108 11/22/2025
0.2.0-alpha.20251122-9b41b57 152 11/22/2025
0.2.0-alpha.20251122-635aa9b 133 11/22/2025
0.2.0-alpha.20251121-df09098 260 11/21/2025
0.2.0-alpha.20251120-d077a93 350 11/20/2025
0.2.0-alpha.20251119-f6d845f 347 11/19/2025
0.2.0-alpha.20251117-df58687 361 11/17/2025
0.2.0-alpha.20251117-d2534db 227 11/17/2025
0.2.0-alpha.20251117-a9abd93 251 11/17/2025
0.2.0-alpha.20251117-3206094 233 11/17/2025
0.2.0-alpha.20251116-7ce0d4a 227 11/16/2025
0.2.0-alpha.20251116-7ae0dd3 226 11/16/2025
0.2.0-alpha.20251116-10046cb 228 11/16/2025
0.1.1 352 11/16/2025
0.1.1-alpha.20251116-f9cb29d 183 11/16/2025
0.1.1-alpha.20251115-eb1d27d 119 11/15/2025
0.1.1-alpha.20251115-97d556b 130 11/15/2025
0.1.1-alpha.20251114-781370f 199 11/14/2025
0.1.1-alpha.20251110-6f995d0 365 11/10/2025
0.1.1-alpha.20251109-363603e 166 11/9/2025
0.1.1-alpha.20251106-45c53f1 155 11/6/2025
0.1.1-alpha.20251106-03d860f 143 11/6/2025
0.1.1-alpha.20251105-9f39f7a 141 11/5/2025
0.1.1-alpha.20251101-6267aeb 90 11/1/2025
0.1.1-alpha.20251031-1c63e9c 65 10/31/2025
0.1.1-alpha.20251027-f0b7dde 182 10/27/2025
0.1.1-alpha.20251027-c4362c8 133 10/27/2025
0.1.1-alpha.20251025-152b4af 71 10/25/2025
0.1.1-alpha.20251024-b70cc56 82 10/24/2025
0.1.0 1,338 10/24/2025
0.1.0-alpha.20251024-3cefb17 76 10/24/2025
0.1.0-alpha.20251024-314457e 94 10/24/2025
0.1.0-alpha.20251023-a8f600c 145 10/23/2025
0.1.0-alpha.20251023-892bcfc 120 10/23/2025
0.1.0-alpha.20251023-5044536 128 10/23/2025
0.1.0-alpha.20251022-7043ca5 125 10/22/2025
0.1.0-alpha.20251020-bf49057 188 10/20/2025
0.1.0-alpha.20251020-8f891f5 177 10/20/2025
0.0.6-alpha.20251016-b45532a 323 10/16/2025
0.0.6-alpha.20251016-900b836 116 10/16/2025
0.0.6-alpha.20251016-5f28e95 125 10/16/2025
0.0.5 638 10/16/2025
0.0.5-alpha.nightly-2025101... 127 10/16/2025
0.0.5-alpha.29ae57 274 10/14/2025
0.0.4-alpha.9d402f 174 10/12/2025
0.0.3-alpha.4657e6 439 10/11/2025
0.0.2-alpha.181b79 116 10/5/2025
0.0.1 355 10/5/2025
0.0.1-alpha.52aa24 123 10/5/2025