ktsu.TUI
2.1.0
Prefix Reserved
See the version list below for details.
dotnet add package ktsu.TUI --version 2.1.0
NuGet\Install-Package ktsu.TUI -Version 2.1.0
<PackageReference Include="ktsu.TUI" Version="2.1.0" />
<PackageVersion Include="ktsu.TUI" Version="2.1.0" />
<PackageReference Include="ktsu.TUI" />
paket add ktsu.TUI --version 2.1.0
#r "nuget: ktsu.TUI, 2.1.0"
#:package ktsu.TUI@2.1.0
#addin nuget:?package=ktsu.TUI&version=2.1.0
#tool nuget:?package=ktsu.TUI&version=2.1.0
ktsu.TUI
A modern, extensible Text User Interface (TUI) library for .NET applications built on top of Spectre.Console. This library provides a clean, object-oriented approach to building interactive terminal applications with rich visual features.
Overview
ktsu.TUI is designed with SOLID principles and provides a modular architecture for creating terminal-based user interfaces. It features:
- Modular Architecture: Clean separation of concerns with contracts, models, services, and UI elements
- Event-Driven Rendering: Efficient rendering system that only updates when needed
- Extensible Design: Easy to extend with custom UI elements and layouts
- Provider Abstraction: Pluggable console providers (currently supports Spectre.Console)
- Dependency Injection Ready: Built with DI in mind for easy integration
Features
✓ Rich Text Styling: Bold, italic, underline, colors, and background colors
✓ Border Elements: Multiple border styles (single, double, rounded, thick, ASCII, none)
✓ Layout System: Stack panels with horizontal/vertical orientation and spacing
✓ Input Handling: Keyboard input processing with ESC to exit
✓ Alignment Support: Horizontal and vertical text alignment
✓ Padding & Positioning: Flexible positioning and padding system
✓ Responsive Design: Automatic sizing based on content and container dimensions
Architecture
Contracts → Models → Services
↓ ↓ ↓
Elements → Layouts → Primitives
↓
Provider Abstraction
- Contracts: Interfaces defining the core abstractions
- Models: Data structures for styling, positioning, and input
- Services: Core application logic and console providers
- Elements: UI components (primitives like borders/text, layouts like stack panels)
- Extensions: Helper methods and utilities
Installation
Add the NuGet package:
dotnet add package ktsu.TUI
Quick Start
using ktsu.TUI.Core.Services;
using ktsu.TUI.Core.Elements.Primitives;
using ktsu.TUI.Core.Elements.Layouts;
using ktsu.TUI.Core.Models;
// Create console provider
var consoleProvider = new SpectreConsoleProvider();
// Create a simple UI
var ui = new BorderElement
{
Title = "My TUI App",
BorderStyle = BorderStyle.DoubleLine,
Child = new TextElement
{
Text = "Hello, TUI World!",
Style = new TextStyle { IsBold = true, Foreground = "green" }
}
};
// Create and run application
var app = UIApplication.CreateBuilder(consoleProvider)
.UseRootElement(ui)
.Build();
await app.RunAsync();
Demo Applications
The library includes several demonstration applications:
- Sample App (default): Advanced demo showcasing architecture and features
- Interactive Demo: Interactive controls and real-time updates (
--interactive) - Showcase Demo: Visual demonstration of all styling features (
--showcase)
Run demos:
dotnet run --project TUI.App # Sample app
dotnet run --project TUI.App -- --interactive # Interactive demo
dotnet run --project TUI.App -- --showcase # Showcase demo
Key Components
UI Elements
TextElement: Styled text displayBorderElement: Bordered containers with titlesStackPanel: Horizontal/vertical layout container
Styling
TextStyle: Font styling (bold, italic, underline, colors)BorderStyle: Border appearance (single, double, rounded, etc.)Padding: Space around contentPosition: Element positioning
Input System
- Keyboard input handling
- ESC key to exit applications
- Extensible input event system
Contributing
This project follows clean architecture principles and emphasizes:
- SOLID design principles
- DRY (Don't Repeat Yourself) implementation
- Comprehensive testing
- Clear separation of concerns
License
MIT License. Copyright (c) ktsu.dev
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 11.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 11.0.0)
- Spectre.Console (>= 0.57.2)
- Spectre.Console.Ansi (>= 0.57.2)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 11.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 11.0.0)
- Spectre.Console (>= 0.57.2)
- Spectre.Console.Ansi (>= 0.57.2)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 11.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 11.0.0)
- Spectre.Console (>= 0.57.2)
- Spectre.Console.Ansi (>= 0.57.2)
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 |
|---|---|---|
| 2.1.1-pre.2 | 50 | 11/23/2026 |
| 2.1.1-pre.1 | 63 | 11/16/2026 |
| 2.1.0 | 98 | 11/13/2026 |
| 2.0.9 | 121 | 10/9/2026 |
| 2.0.8 | 101 | 10/8/2026 |
| 2.0.8-pre.1 | 64 | 10/7/2026 |
| 2.0.7 | 96 | 10/6/2026 |
| 2.0.6 | 106 | 10/5/2026 |
| 2.0.5 | 112 | 9/30/2026 |
| 2.0.4 | 106 | 9/30/2026 |
| 2.0.3 | 107 | 9/30/2026 |
| 2.0.2 | 105 | 9/30/2026 |
| 2.0.1 | 108 | 9/29/2026 |
| 2.0.0 | 112 | 9/29/2026 |
## v2.1.0 (minor)
Changes since v2.0.0:
- Suppress package-validation errors on Polyfill's embedded types [patch] (#261) (matt-edmondson)
- Keep a CJK or emoji border title inside the border [patch] (#262) (matt-edmondson)
- Clip WriteAt text to the screen in cells, never splitting a character [patch] (#263) (matt-edmondson)
- Give a hidden root element no input [patch] (#267) (matt-edmondson)
- Normalise control characters in a border title like TextElement text [patch] (#250) (matt-edmondson)
- Keep a hidden container from drawing its children or passing them input [patch] (#251) (matt-edmondson)
- Leave a hidden child out of BorderElement's and the default container measure [patch] (#252) (matt-edmondson)
- [patch] Fault the run when a render pass throws a foreign OperationCanceledException (#253) (matt-edmondson)
- [patch] Measure a container with no room past its padding as the padding alone (#254) (matt-edmondson)
- Treat a negative padding side as 0 [patch] (#256) (matt-edmondson)
- Delete TUI.Cli, which no PR build compiled, and require every project in TUI.sln [patch] (#257) (matt-edmondson)
- Compile the showcase demo again and run it for --showcase [patch] (#258) (matt-edmondson)
- Let an element's render failure end the run instead of erasing the frame [patch] (#247) (matt-edmondson)
- Clear the screen when the root element is removed [patch] (#245) (matt-edmondson)
- Leave a collapsed child out of a horizontal StackPanel's measured height [patch] (#244) (matt-edmondson)
- Count a cancelled read from this run as a failed read instead of skipping it [patch] (#243) (matt-edmondson)
- Treat U+2028 and U+2029 as line breaks instead of writing a raw line feed [patch] (Claude)
- Type AltGr+C as a character instead of exiting [patch] (Claude)
- Draw styled text as written instead of parsing it as markup [patch] (Claude)
- Add UIApplication.Post to change the tree from another thread [minor] (Claude)
- Use BorderStyle.DoubleLine in the README Quick Start, and compile it in the tests [patch] (Claude)
- Move WrapText's line break into a helper to keep it under the complexity limit (Claude)
- Keep a paragraph's indentation when its first word has to be broken [patch] (Claude)
- End a run on OperationCanceledException only when the run was cancelled [patch] (Claude)
- Refuse a cyclic BorderElement.Child before detaching the old one [patch] (Claude)
- Merge remote-tracking branch 'origin/main' into claude/tui-167-refuse-cyclic-add (Claude)
- Guard the run's token source with a lock instead of catching ObjectDisposedException [patch] (Claude)
- Claim only the padding when wrapped text has no column to draw in [patch] (Claude)
- Dispose the token source each run links to the caller's token [patch] (Claude)
- Lay a swapped-back root out at the terminal's current size [patch] (Claude)
- Invalidate on layout property changes and re-arrange on a padding change [patch] (Claude)
- Refuse a second child in BorderElement [patch] (Claude)
- Refuse adding a container to itself or one of its descendants [patch] (Claude)
- Combine the nested input-not-handled check [patch] (Claude)
- Give the pending read up when a run ends, so the next key is not swallowed [patch] (Claude)
- Wrap text inside a border or a horizontal stack to the width it gets [patch] (Claude)
- test: cover OffsetConsoleProvider and invisible elements in Render (Claude)
- Move the control-character helper and its provider tests to the end of their files (Claude)
- fix: draw an element at the position passed to IConsoleProvider.Render [patch] (Claude)
- fix: draw changes made outside a keypress by redrawing when the tree invalidates [patch] (Claude)
- fix: expand tabs and replace control characters in text before measuring and drawing [patch] (Claude)
- fix: stretch StackPanel children across the cross axis so alignment applies [patch] (Claude)
- fix: measure a titled BorderElement wide enough to draw its title [patch] (Claude)
- [patch] Leave the terminal's color for a transparent foreground or background (Claude)
- test: drive ReadInputAsync through an injected key reader [patch] (Claude)
- Merge remote-tracking branch 'origin/main' into fix/152-keychar (Claude)
- test: cover Ctrl+C and plain C in ToInputResult [patch] (Claude)
- fix: pass the typed character through with each key [patch] (Claude)
- fix: keep a BorderElement title with a line break on the top border row [patch] (Claude)
- fix: hide and show the cursor on the injected console without moving it [patch] (Claude)
- fix: arrange the tree on every render pass, not only on a resize [patch] (Claude)
- refactor: move overlong-word slicing out of WrapText [patch] (Claude)
- fix: keep indentation and spacing when TextElement wraps words [patch] (Claude)
- fix: invalidate each ancestor once instead of 2^depth times [patch] (Claude)
- test: cover the ArgumentException read-failure path [patch] (matt-edmondson)
- fix: end the run after repeated failed reads instead of spinning forever [patch] (matt-edmondson)