Back to Terminal Gui

Namespace Drivers

docfx/apispec/namespace-drivers.md

2.4.72.2 KB
Original Source

The Drivers namespace provides the platform abstraction layer enabling Terminal.Gui to run consistently across Windows, macOS, and Linux/Unix.

Key Types

  • IDriver - Main driver interface for terminal operations
  • DriverRegistry - Registry of available drivers with metadata
  • AnsiResponseParser - ANSI escape sequence parsing for input
  • AnsiKeyboardParser / AnsiMouseParser - Keyboard and mouse input parsing
  • EscSeqUtils - ANSI escape sequence constants and utilities
  • Cursor / CursorStyle - Terminal cursor management
  • IOutput / IOutputBuffer - Output surfaces, including raster image dispatch

Available Drivers

DriverPlatformDescription
windowsWindowsNative Win32 Console API with highest performance
unixUnix/Linux/macOSDirect syscalls with ANSI sequences
dotnetAllCross-platform using System.Console
ansiAllPure ANSI implementation, ideal for testing

Driver Selection

csharp
// Automatic (recommended)
app.Init ();  // Selects best driver for platform

// Explicit selection
app.Init (DriverRegistry.Names.ANSI);

// Via configuration
app.ForceDriver = DriverRegistry.Names.UNIX;
app.Init ();

Raster Graphics Capabilities

Drivers expose raster protocol detection through IDriver.KittyGraphicsSupport and IDriver.SixelSupport, plus matching change events. Kitty graphics is the preferred raster protocol when supported. Sixel remains the fallback for terminals that do not support Kitty graphics. IOutput.UseKittyGraphics selects the Kitty output path; when it is false and Sixel is supported, raster commands are emitted as Sixel.

See Also

Threading Model

The driver architecture uses a multi-threaded design:

  • Input Thread: Asynchronously reads console input without blocking the UI
  • Main UI Thread: Processes events, performs layout, and renders output

This separation ensures responsive input handling even during intensive UI operations.

Deep Dive

See the Cross-Platform Driver Model for comprehensive details.