Termina 0.16.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Termina --version 0.16.0
                    
NuGet\Install-Package Termina -Version 0.16.0
                    
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="Termina" Version="0.16.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Termina" Version="0.16.0" />
                    
Directory.Packages.props
<PackageReference Include="Termina" />
                    
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 Termina --version 0.16.0
                    
#r "nuget: Termina, 0.16.0"
                    
#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 Termina@0.16.0
                    
#: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=Termina&version=0.16.0
                    
Install as a Cake Addin
#tool nuget:?package=Termina&version=0.16.0
                    
Install as a Cake Tool

Termina

Termina Logo

NuGet Downloads GitHub License GitHub Actions Workflow Status GitHub Release

Termina is a reactive terminal UI (TUI) framework for .NET with declarative layouts and surgical region-based rendering. It provides an MVVM architecture with reactive properties, ASP.NET Core-style routing, and seamless integration with Microsoft.Extensions.Hosting.

See It In Action

Termina component gallery: keyboard-driven menus, live spinners, and selection lists

A guided tour of the Termina component gallery.

Documentation

Full Documentation

Features

  • Reactive MVVM Architecture - ViewModels with ReactiveProperty<T> for observable state management
  • Declarative Layouts - Tree-based layout system with size constraints (Fixed, Fill, Auto, Percent)
  • Surgical Rendering - Only changed regions re-render, enabling smooth streaming updates
  • ASP.NET Core-Style Routing - Route templates with parameters (/tasks/{id:int}) and type constraints
  • Source Generators - AOT-compatible code generation for route parameters
  • Streaming Support - Native StreamingTextNode for real-time content like LLM output
  • Dependency Injection - Full integration with Microsoft.Extensions.DependencyInjection
  • Hosting Integration - Works with Microsoft.Extensions.Hosting for clean lifecycle management

Installation

dotnet add package Termina
dotnet add package Microsoft.Extensions.Hosting

Upgrading to 0.7.0? This release migrates from System.Reactive to R3 with breaking API changes. See the Migration Guide for details.

Quick Start

1. Define a ViewModel

using R3;
using Termina.Input;
using Termina.Reactive;

public class CounterViewModel : ReactiveViewModel
{
    public ReactiveProperty<int> Count { get; } = new(0);
    public ReactiveProperty<string> Message { get; } = new("Press Up/Down to change count");

    public override void OnActivated()
    {
        Input.OfType<IInputEvent, KeyPressed>()
            .Subscribe(HandleKey)
            .DisposeWith(Subscriptions);
    }

    private void HandleKey(KeyPressed key)
    {
        switch (key.KeyInfo.Key)
        {
            case ConsoleKey.UpArrow:
                Count.Value++;
                Message.Value = $"Count: {Count.Value}";
                break;
            case ConsoleKey.DownArrow:
                Count.Value--;
                Message.Value = $"Count: {Count.Value}";
                break;
            case ConsoleKey.Escape:
                Shutdown();
                break;
        }
    }

    public override void Dispose()
    {
        Count.Dispose();
        Message.Dispose();
        base.Dispose();
    }
}

ReactiveProperty<T> is both a value holder and an Observable<T> — subscribe directly in your Page for reactive UI bindings.

2. Define a Page

using R3;
using Termina.Extensions;
using Termina.Layout;
using Termina.Reactive;
using Termina.Rendering;
using Termina.Terminal;

public class CounterPage : ReactivePage<CounterViewModel>
{
    public override ILayoutNode BuildLayout()
    {
        return Layouts.Vertical()
            .WithChild(
                new PanelNode()
                    .WithTitle("Counter Demo")
                    .WithBorder(BorderStyle.Rounded)
                    .WithBorderColor(Color.Cyan)
                    .WithContent(
                        ViewModel.Count
                            .Select<int, ILayoutNode>(count => new TextNode($"Count: {count}")
                                .WithForeground(Color.BrightCyan))
                            .AsLayout())
                    .Height(5))
            .WithChild(
                ViewModel.Message
                    .Select<string, ILayoutNode>(msg => new TextNode(msg))
                    .AsLayout()
                    .Height(1));
    }
}

3. Configure and Run

using Microsoft.Extensions.Hosting;
using Termina.Hosting;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddTermina("/counter", termina =>
{
    termina.RegisterRoute<CounterPage, CounterViewModel>("/counter");
});

await builder.Build().RunAsync();

Layout System

Termina uses a declarative tree-based layout system:

Layouts.Vertical()
    .WithChild(header.Height(3))           // Fixed height
    .WithChild(content.Fill())             // Take remaining space
    .WithChild(sidebar.Width(20))          // Fixed width
    .WithChild(footer.Height(1));          // Fixed height

Layouts.Horizontal()
    .WithChild(menu.Width(30))
    .WithChild(main.Fill(2))               // 2x weight
    .WithChild(aside.Fill(1));             // 1x weight

Routing

ASP.NET Core-style route templates with parameter support:

builder.Services.AddTermina("/", termina =>
{
    termina.RegisterRoute<HomePage, HomeViewModel>("/");
    termina.RegisterRoute<TasksPage, TasksViewModel>("/tasks");
    termina.RegisterRoute<TaskDetailPage, TaskDetailViewModel>("/tasks/{id:int}");
    termina.RegisterRoute<UserPage, UserViewModel>("/users/{name}");
});

Route Parameter Injection

public partial class TaskDetailViewModel : ReactiveViewModel
{
    [FromRoute] private int _id;  // Injected from route

    public override void OnActivated()
    {
        LoadTask(Id);  // Id is already populated
    }
}
Navigate("/tasks/42");
NavigateWithParams("/tasks/{id}", new { id = 42 });
Shutdown();  // Exit the application

Streaming Content

For real-time content like LLM output, Pages own StreamingTextNode and subscribe to ViewModel observables:

// In Page
private StreamingTextNode _output = null!;

protected override void OnBound()
{
    _output = StreamingTextNode.Create();
    ViewModel.StreamOutput.Subscribe(chunk => _output.Append(chunk));
}

// In ViewModel
public Observable<string> StreamOutput => _streamOutput;
private readonly Subject<string> _streamOutput = new();

private async Task StreamResponse()
{
    await foreach (var chunk in GetStreamingData())
    {
        _streamOutput.OnNext(chunk);  // Character-level updates
    }
}

Testing

VirtualInputSource enables automated testing:

var scriptedInput = new VirtualInputSource();
builder.Services.AddTerminaVirtualInput(scriptedInput);

scriptedInput.EnqueueKey(ConsoleKey.UpArrow);
scriptedInput.EnqueueString("Hello World");
scriptedInput.EnqueueKey(ConsoleKey.Enter);
scriptedInput.Complete();

await host.RunAsync();

Requirements

  • .NET 10.0 or later
  • AOT-compatible (Native AOT publishing supported)

License

Apache 2.0 - See LICENSE for details.

Contributing

Contributions are welcome! See CONTRIBUTING.md for development setup and guidelines.

Product Compatible and additional computed target framework versions.
.NET 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 (1)

Showing the top 1 popular GitHub repositories that depend on Termina:

Repository Stars
netclaw-dev/netclaw
Simple, secure, reliable agents. Self-hosted. Open source. Built with .NET.
Version Downloads Last Updated
0.16.1 0 8/8/2026
0.16.0 0 8/7/2026
0.15.1 1,400 7/21/2026
0.15.0 5,899 7/1/2026
0.15.0-beta1 1,022 6/26/2026
0.14.0 1,002 6/23/2026
0.14.0-beta3 732 6/22/2026
0.14.0-beta.2 84 6/20/2026
0.14.0-beta.1 614 6/18/2026
0.13.0 128 6/18/2026
0.12.1 1,601 6/11/2026
0.12.0 124 6/9/2026
0.11.1 967 6/8/2026
0.11.0 490 6/7/2026
0.10.2 2,788 5/30/2026
0.10.1 1,394 5/24/2026
0.10.0 452 5/23/2026
0.9.0 2,676 5/18/2026
0.8.0 8,180 3/17/2026
0.7.2 2,251 3/1/2026
Loading failed

**New Features**

- **Roslyn analyzers now ship with the Termina library** ([#346](https://github.com/Aaronontheweb/termina/pull/346))
 - Termina now includes its Roslyn analyzers in the package.
 - The compiler runs the analyzers on your project and reports common layout node mistakes at build time.
 - This change also fixes a node that Termina did not dispose when content switched.

- **New analyzer TERMINA003 for layout node child disposal** ([#343](https://github.com/Aaronontheweb/termina/pull/343))
 - TERMINA003 warns when code disposes a child layout node outside `Dispose()`.
 - `Dispose()` destroys the node, so the node can no longer render or handle input.
 - The analyzer tells you to call `OnDeactivate()` to switch content.

- **New analyzer TERMINA004 for stateful node recreation** ([#337](https://github.com/Aaronontheweb/termina/pull/337))
 - TERMINA004 warns when a dynamic layout factory creates a new stateful node on each run.
 - A new node resets state such as the scroll position.
 - The analyzer tells you to reuse the node, to invalidate a smaller child, or to use `KeyedDynamicLayoutNode`.

**Bug Fixes**

- **Fixed glyph corruption when word-wrap breaks a long word that contains wide characters** ([#351](https://github.com/Aaronontheweb/termina/pull/351))
 - `StyledLine.SliceByColumns` no longer drops or reorders glyphs.
 - The corruption occurred when a long word contained wide characters (CJK or emoji) across segments.
 - Streamed text now keeps the correct content and order.

- **Fixed the style of word-wrap space separators** ([#349](https://github.com/Aaronontheweb/termina/pull/349))
 - Word-wrap space separators now inherit the whitespace style from the source text.
 - A wrapped line keeps the correct foreground and background for the space between words.

- **Guarded dynamic layout nodes against re-entrant Invalidate** ([#348](https://github.com/Aaronontheweb/termina/pull/348))
 - `DynamicLayoutNode` and `KeyedDynamicLayoutNode` no longer re-enter `Invalidate()`.
 - The guard prevents a stack overflow and inconsistent layout during a factory run.

- **Fixed GridNode cell subscription tracking on content swap** ([#347](https://github.com/Aaronontheweb/termina/pull/347))
 - `GridNode` now tracks cell subscriptions per content node.
 - The grid deactivates the old subscriptions when it swaps a cell.
 - This change prevents stale updates and resource leaks.

**Documentation**

- **Documented the built-in back navigation APIs** ([#350](https://github.com/Aaronontheweb/termina/pull/350))
 - New documentation explains the back navigation APIs.