Stanza.TerminalGui 0.1.0

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

Stanza.TerminalGui

Stanza is a small, reflection-free MVVM binding library for Terminal.Gui v2. It uses C# Source Generators to eliminate boilerplate, providing a declarative way to wire up UI controls to ViewModels.

Features

  • Reflection-free enables NativeAOT compilation
  • No framework dependencies: extensions are dependent on standard .NET APIs; INotifyPropertyChanged, ICommand meaning CommunityToolkit.Mvvm or Reactive Extensions can be used.
  • Automatic binding management or manual management by opting out of source generator usage

Installation

Add the package to your project:

dotnet add package Stanza.TerminalGui

Quick Start

1. Define a ViewModel

Using CommunityToolkit.Mvvm (optional but recommended) to handle property notifications.

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

public partial class MainViewModel : ObservableObject
{
    [ObservableProperty]
    public partial string Username { get; set; } = "Stanza User";

    [RelayCommand]
    private void Reset() => Username = "Guest";
}

2. Create a View

Declare your UI using standard Terminal.Gui code, and use Stanza attributes to bind the data.

using Stanza.TerminalGui;
using Terminal.Gui.Views;

// 1. Mark as partial
// 2. Use the generic StanzaView attribute to specify your ViewModel
[StanzaView<MainViewModel>]
public partial class MainView : Window
{
    // Bind the Text property of this Label to ViewModel.Username
    [BindText(nameof(MainViewModel.Username))]
    public Label NameLabel { get; set; } = new();

    // Bind the Button trigger to the ResetCommand
    [BindCommand(nameof(MainViewModel.ResetCommand))]
    public Button ResetButton { get; set; } = new() { Text = "Reset" };

    public MainView()
    {
        Title = "Stanza Quickstart";
        
        ResetButton.Y = Pos.Bottom(NameLabel);
        Add(NameLabel, ResetButton);
    }
}

3. Initialize and Run

Simply assign the ViewModel property. Stanza handles the subscription logic automatically.

var viewModel = new MainViewModel();
var view = new MainView { ViewModel = viewModel };

Application.Run(view);

Available Bindings

Attribute Target Property Support
[BindText] Text Two-Way (TextField), One-Way (Label)
[BindChecked] Checked / Value Two-Way (CheckBox)
[BindEnabled] Enabled One-Way
[BindVisible] Visible One-Way
[BindCommand] Accepting / Enabled Execute + CanExecute (Button)

Advanced: Manual Bindings

If you need logic that doesn't fit a standard attribute, you can use the OnApplyBindings hook provided by the generator. This method is called automatically whenever a new ViewModel is attached.

public partial class MainView
{
    // This partial method is called by the generated code
    partial void OnApplyBindings(BindingContext context)
    {
        // Manual binding with custom logic
        this.Bind(ViewModel, vm => vm.Username, val => {
            Title = $"Editing: {val}";
        }).AddTo(context);
        
        // Context is automatically disposed when the VM changes 
        // or the View is disposed.
    }
}

Why Stanza?

In standard Terminal.Gui, you often find yourself writing code like this:

// The "Old" Way (Manual, Leak-prone, No Thread Safety)
viewModel.PropertyChanged += (s, e) => {
    if (e.PropertyName == "Name") {
        Application.Invoke(() => label.Text = viewModel.Name);
    }
};

Stanza replaces this with a single attribute. It handles the property name check, the thread marshalling, the initial synchronization, and the event unsubscription for you.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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.1.1-preview.2 114 6/30/2026
0.1.1-preview.1 93 6/25/2026
0.1.0 151 6/17/2026
0.1.0-preview.8 85 6/14/2026
0.1.0-preview.7 74 6/14/2026
0.1.0-preview.6 78 6/9/2026
0.1.0-preview.5 73 6/9/2026
0.1.0-preview.4 72 6/8/2026
0.1.0-preview.2 84 6/6/2026
0.1.0-preview.1 78 6/2/2026