SharpConsoleUI 0.2.2
See the version list below for details.
dotnet add package SharpConsoleUI --version 0.2.2
NuGet\Install-Package SharpConsoleUI -Version 0.2.2
<PackageReference Include="SharpConsoleUI" Version="0.2.2" />
<PackageVersion Include="SharpConsoleUI" Version="0.2.2" />
<PackageReference Include="SharpConsoleUI" />
paket add SharpConsoleUI --version 0.2.2
#r "nuget: SharpConsoleUI, 0.2.2"
#:package SharpConsoleUI@0.2.2
#addin nuget:?package=SharpConsoleUI&version=0.2.2
#tool nuget:?package=SharpConsoleUI&version=0.2.2
SharpConsoleUI
A simple console window system for .NET Core.
Overview
SharpConsoleUI is a lightweight console window system implementation for .NET Core applications. It provides a windowing system with support for multiple overlapping windows, keyboard and mouse input, and customizable themes.
Features
ConsoleWindowSystem
ConsoleWindowSystem is the core component that manages the console window environment:
Window Management
- Create and manage multiple windows
- Handle window activation and focus
- Support for overlapping windows with proper Z-order
- Window cycling (Alt+1-9, Ctrl+T)
Input Handling
- Keyboard input with modifier key support
- Mouse input capture and processing
- Input queuing system
Rendering
- Double-buffered rendering
- Efficient partial updates for dirty regions
- Support for different render modes (Direct or Buffer)
- Status bar rendering (top and bottom)
Layout
- Desktop environment simulation
- Dynamic window resizing and positioning
- Automatic window repositioning on console resize
UI
- Themeable interface
- Window flashing for notifications
Window
Window provides a container for content and handles rendering:
Appearance
- Customizable title
- Border drawing with active/inactive states
- Support for different background and foreground colors
- Theme integration
Window States
- Normal, minimized, and maximized states
- Window restoration
Content Management
- Content invalidation system for efficient updates
- Support for interactive content elements
- Sticky positioning for footer content
- Scrollable content with automatic scrolling
Input Handling
- Focus management between interactive elements
- Tab navigation between focusable elements
- Keyboard event dispatching
Window Operations
- Resizable windows (minimum/maximum size constraints)
- Movable windows
- Window closing with confirmation
NetConsoleDriver
NetConsoleDriver is the implementation of IConsoleDriver that interfaces with the .NET Console:
Input Management
- Mouse input handling
- Keyboard input processing with support for:
- Control characters
- Alt key combinations
- Arrow keys and function keys
- ANSI escape sequence parsing
Output Features
- ANSI color and formatting sequence support
- Virtual terminal processing
- Cursor positioning
Rendering Modes
- Direct mode (immediate console updates)
- Buffer mode (double buffering for flicker-free rendering)
Console Events
- Window resize detection
- Mouse event generation
- Keyboard event generation
Platform Support
- Windows console API integration
- Cross-platform compatibility considerations
Getting Started
Basic Setup
Here's a minimal example showing how to initialize the ConsoleWindowSystem and create a simple window with markup:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SharpConsoleUI;
using SharpConsoleUI.Controls;
using SharpConsoleUI.Themes;
using Spectre.Console;
namespace YourNamespace
{
class Program
{
static async Task Main(string[] args)
{
// Initialize the console window system
var consoleWindowSystem = new ConsoleWindowSystem(RenderMode.Buffer)
{
TopStatus = "SharpConsoleUI Example",
BottomStatus = "Ctrl-Q to Quit",
Theme = new Theme
{
DesktopBackroundChar = '.',
DesktopBackgroundColor = Color.Black,
DesktopForegroundColor = Color.Grey
}
};
// Create a simple window with markup content
var window = new Window(consoleWindowSystem, WindowThread)
{
Title = "Hello World",
Left = 10,
Top = 5,
Width = 50,
Height = 15,
IsResizable = true
};
// Add the window to the console window system
consoleWindowSystem.AddWindow(window);
// Make this window the active window
consoleWindowSystem.SetActiveWindow(window);
// Run the console window system (this blocks until the application exits)
int exitCode = consoleWindowSystem.Run();
Console.WriteLine($"Application exited with code: {exitCode}");
}
// Window thread function that adds content to the window
static void WindowThread(Window window)
{
// Create a markup control with formatted text
var markupContent = new MarkupControl(new List<string>
{
"[bold yellow]Welcome to SharpConsoleUI![/]",
"",
"This is a [green]simple[/] demonstration of using [cyan]markup[/] in a window.",
"",
"[red]Colors[/], [underline]formatting[/], and [bold]styles[/] are supported."
});
// Add the markup content to the window
window.AddContent(markupContent);
// Add a horizontal rule
window.AddContent(new RuleControl
{
Title = "Controls Demo",
TitleAlignment = Justify.Center
});
// Add a button control
var button = new ButtonControl
{
Text = "[blue]Click Me![/]",
Margin = new Margin(1, 0, 0, 0)
};
// Add button click handler
button.OnClick += (sender) =>
{
markupContent.SetContent(new List<string>
{
"[bold green]Button was clicked![/]",
$"Current time: {DateTime.Now}"
});
};
// Add the button to the window
window.AddContent(button);
}
}
}
Displaying Dynamic Content
You can update window content dynamically, for example to show system statistics:
public async void WindowThread(Window window)
{
// Create a markup control for content
var contentControl = new MarkupControl(new List<string> { "Loading data..." });
window.AddContent(contentControl);
// Update the content every few seconds
while (true)
{
var systemInfo = new List<string>
{
$"[yellow]CPU Usage:[/] [green]{GetCpuUsage()}%[/]",
$"[yellow]Memory Available:[/] [green]{GetAvailableMemory()} MB[/]",
$"[yellow]Time:[/] [cyan]{DateTime.Now:HH:mm:ss}[/]"
};
// Update the control with new content
contentControl.SetContent(systemInfo);
// Wait before updating again
await Task.Delay(1000);
}
}
License
MIT License
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 was computed. 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 was computed. 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. |
-
net8.0
- Spectre.Console (>= 0.49.1)
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.2.3 | 135 | 7/2/2025 |
0.2.2 | 155 | 3/16/2025 |
0.2.1 | 139 | 3/16/2025 |
0.2.0 | 140 | 3/16/2025 |
0.1.0 | 140 | 3/16/2025 |
0.1.0-ci0185 | 70 | 3/15/2025 |
0.1.0-ci0184 | 77 | 3/15/2025 |
0.1.0-ci0183 | 75 | 3/15/2025 |
0.1.0-ci0180 | 74 | 3/15/2025 |
0.1.0-ci0179 | 79 | 3/14/2025 |
Bug fixes and performance improvements