Terminal abstractions and widgets for console applications - IConsole, ITerminal, panels, tables, rules, and ANSI color support.
Basic console I/O abstraction for testable console applications.
public interface IConsole
{
void Write(string message);
void WriteLine(string? message = null);
void WriteErrorLine(string? message = null);
string? ReadLine();
}Extended terminal interface with cursor control, colors, and hyperlinks.
public interface ITerminal : IConsole
{
ConsoleKeyInfo ReadKey(bool intercept);
void SetCursorPosition(int left, int top);
(int Left, int Top) GetCursorPosition();
int WindowWidth { get; }
bool IsInteractive { get; }
bool SupportsColor { get; }
bool SupportsHyperlinks { get; }
void Clear();
}| Class | Description |
|---|---|
NuruConsole |
Production IConsole wrapping System.Console |
TimeWarpTerminal |
Production ITerminal with full terminal capabilities |
TestConsole |
Test implementation with captured output |
TestTerminal |
Test implementation for interactive scenarios |
var terminal = new TestTerminal();
terminal.QueueInput("user input");
// Run code that uses ITerminal
myCommand.Execute(terminal);
// Verify output
Assert.Contains("expected text", terminal.GetOutput());Bordered panel with title and content.
terminal.WritePanel(panel => panel
.WithTitle("Status")
.WithContent("All systems operational")
.WithBorder(BorderStyle.Rounded));Formatted table with columns and rows.
terminal.WriteTable(table => table
.AddColumn("Name")
.AddColumn("Value")
.AddRow("CPU", "45%")
.AddRow("Memory", "2.1 GB"));Horizontal rule with optional title.
terminal.WriteRule(rule => rule
.WithTitle("Section")
.WithStyle(LineStyle.Double));Extension methods for colored console output.
terminal.WriteLine("Success!".Green());
terminal.WriteLine("Warning!".Yellow().Bold());
terminal.WriteLine("Error!".Red().OnWhite());Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
Bright variants: BrightRed, BrightGreen, etc.
Bold(), Dim(), Italic(), Underline(), Strikethrough()
OnRed(), OnGreen(), OnBlue(), etc.
Terminal hyperlinks (OSC 8) for supported terminals.
terminal.WriteHyperlink("Click here", "https://example.com");
// Or using extension method
terminal.WriteLine("Visit ".WithHyperlink("our site", "https://example.com"));