Termina.Generators 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Termina.Generators --version 0.2.0
                    
NuGet\Install-Package Termina.Generators -Version 0.2.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.Generators" Version="0.2.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Termina.Generators" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Termina.Generators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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.Generators --version 0.2.0
                    
#r "nuget: Termina.Generators, 0.2.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.Generators@0.2.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.Generators&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Termina.Generators&version=0.2.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 source-generated reactive properties, ASP.NET Core-style routing, and seamless integration with Microsoft.Extensions.Hosting.

Documentation

Full Documentation

Features

  • Reactive MVVM Architecture - ViewModels with [Reactive] attribute for source-generated observable properties
  • 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 reactive properties and 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

Quick Start

1. Define a ViewModel

using System.Reactive.Linq;
using Termina.Input;
using Termina.Reactive;

public partial class CounterViewModel : ReactiveViewModel
{
    [Reactive] private int _count;
    [Reactive] private string _message = "Press Up/Down to change count";

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

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

The [Reactive] attribute generates:

  • A BehaviorSubject<T> backing field
  • A public property Count with get/set
  • An IObservable<T> property CountChanged for subscriptions

2. Define a Page

using System.Reactive.Linq;
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.CountChanged
                            .Select(count => new TextNode($"Count: {count}")
                                .WithForeground(Color.BrightCyan))
                            .AsLayout())
                    .Height(5))
            .WithChild(
                ViewModel.MessageChanged
                    .Select(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:

public StreamingTextNode Output { get; } = StreamingTextNode.Create();

private async Task StreamResponse()
{
    await foreach (var chunk in GetStreamingData())
    {
        Output.Append(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.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Termina.Generators:

Package Downloads
Termina

Reactive terminal UI (TUI) framework for .NET with custom ANSI rendering, MVVM architecture, source-generated reactive properties, and ASP.NET Core-style routing.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.1 278 12/19/2025
0.5.0 287 12/18/2025
0.4.0 330 12/18/2025
0.3.0 264 12/17/2025
0.2.1 263 12/16/2025
0.2.0 272 12/16/2025
0.1.0 292 12/16/2025
0.1.0-beta1 106 12/12/2025

**Breaking Changes**:
- **Pure reactive architecture** ([#50](https://github.com/Aaronontheweb/Termina/pull/50))
 - All .NET events migrated to `IObservable<T>` for consistency with System.Reactive
 - `IInvalidatingNode.Invalidated`: `event Action?` → `IObservable<Unit>`
 - `TextInputNode`: `Submitted`, `TextChanged`, `Invalidated` now use observables
 - Other components (`SpinnerNode`, `ConditionalNode`, `ReactiveLayoutNode`, `ScrollableContainerNode`, `StreamingTextNode`) migrated to observables
 - Rendering layer events migrated: `OnSubmit` → `Submitted`, `OnDirty` → `Dirty`
 - **Migration required**: Replace event subscriptions (`+=`) with observable subscriptions (`.Subscribe()`)
 - Use `.DisposeWith()` for automatic subscription cleanup in ViewModels

**New Features**:
- **Focus management system** ([#51](https://github.com/Aaronontheweb/Termina/pull/51))
 - Stack-based focus management for interactive components
 - `IFocusable` interface for components that can receive keyboard focus
 - `IFocusManager` with priority-based focus routing
 - `TerminaApplication` now routes keyboard input through focus manager
 - `ReactiveViewModel` exposes `Focus` property for managing focus state
- **ModalNode component** ([#51](https://github.com/Aaronontheweb/Termina/pull/51))
 - Overlay component for modal dialogs and selection prompts
 - Configurable backdrop styles: Transparent, Dim, Solid
 - Positioning options: Center, Top, Bottom
 - Escape key dismissal support
 - Integrates with focus management system
 - Created via `Layouts.Modal()` factory method
- **SelectionListNode component** ([#51](https://github.com/Aaronontheweb/Termina/pull/51))
 - Keyboard-navigable selection lists with single/multi-select modes
 - Number key shortcuts (1-9) for quick selection
 - Home/End navigation and automatic scrolling
 - Optional "Other" option for custom text input
 - Typed items support with `SelectionListNode<T>`
 - Created via `Layouts.SelectionList()` factory methods
 - Exposes `SelectionConfirmed` and `SelectionCancelled` observables
- **DeferredNode component** ([#51](https://github.com/Aaronontheweb/Termina/pull/51))
 - Non-owning node delegation pattern for reactive layouts
 - Prevents `ObjectDisposedException` when conditionally showing/hiding nodes
 - Useful for modal dialogs that shouldn't be disposed when hidden
 - Created via `Layouts.Deferred()` factory method
- **Inline styled text support** ([#48](https://github.com/Aaronontheweb/Termina/pull/48))
 - Structured API for colored and decorated text in `StreamingTextNode`
 - `TextDecoration` flags: Bold, Dim, Italic, Underline, Strikethrough
 - `TextStyle` record combining foreground, background, and decorations
 - `StyledSegment` and `StyledLine` for composing styled text
 - `StyledWordWrapper` preserves styles across word wrap boundaries
 - New styled `Append`/`AppendLine` overloads on `StreamingTextNode`
 - Avoids escaping issues with LLM output and user content

**Bug Fixes**:
- **Fix auto-disposal of reactive fields** ([#49](https://github.com/Aaronontheweb/Termina/pull/49))
 - Source generator now creates `DisposeReactiveFields()` method for classes with `[Reactive]` fields
 - Auto-generates `Dispose()` override for `ReactiveViewModel` subclasses
 - Added TERMINA001 compiler error when custom `Dispose()` doesn't call `DisposeReactiveFields()`
 - Prevents `BehaviorSubject` backing field leaks

**Improvements**:
- Updated documentation with new components (ModalNode, SelectionListNode, DeferredNode)
- Added `WithChild()` method to `StackLayout` for fluent API consistency
- `TextInputNode` now implements `IFocusable` for modal integration
- Enhanced Todo demo showcasing modal dialogs and two-step input flows
- 48 new unit tests covering focus management, modals, and selection lists

---