Namespace Terminal.Gui.Drivers
The Drivers
namespace provides cross-platform terminal abstraction and console driver implementations.
Terminal.Gui.Drivers contains the platform abstraction layer that enables Terminal.Gui to run consistently across Windows, macOS, and Linux/Unix systems. This namespace includes console drivers, terminal capability detection, and platform-specific optimizations.
The driver system handles low-level terminal operations including cursor management, color support detection, input processing, and screen buffer management. It provides a unified API while accommodating the unique characteristics of different terminal environments.
Key Components
- ConsoleDriver: Base class for platform-specific terminal implementations
- WindowsDriver: Windows Console API implementation
- CursesDriver: Unix/Linux ncurses-based implementation
- NetDriver: Cross-platform .NET Console implementation
Example Usage
// Driver selection is typically automatic
Application.Init();
// Access current driver capabilities
var driver = Application.Driver;
bool supportsColors = driver.SupportsTrueColor;
Deep Dive
See the Cross-Platform Driver Model for comprehensive details.
Classes
- AnsiEscapeSequence
Describes an Ansi escape sequence. This is a 'blueprint'. If you want to send the sequence you should instead use AnsiEscapeSequenceRequest
- AnsiEscapeSequenceRequest
Describes an ongoing ANSI request sent to the console. Use ResponseReceived to handle the response when console answers the request.
- AnsiKeyboardParser
Parses ANSI escape sequence strings that describe keyboard activity into Key.
- AnsiKeyboardParserPattern
Base class for ANSI keyboard parsing patterns.
- AnsiMouseParser
Parses mouse ansi escape sequences into MouseEventArgs including support for pressed, released and mouse wheel.
- AnsiRequestScheduler
Manages AnsiEscapeSequenceRequest made to an IAnsiResponseParser. Ensures there are not 2+ outstanding requests with the same terminator, throttles request sends to prevent console becoming unresponsive and handles evicting ignored requests (no reply from terminal).
- ApplicationV2
Implementation of IApplication that boots the new 'v2' main loop architecture.
- ConsoleDriver
Base class for Terminal.Gui IConsoleDriver implementations.
- ConsoleInput<T>
Base class for reading console input in perpetual loop
- ConsoleKeyMapping
Helper class to handle the scan code and virtual key from a ConsoleKey.
- CsiCursorPattern
Detects ansi escape sequences in strings that have been read from the terminal (see IAnsiResponseParser). Handles navigation CSI key parsing such as
\x1b[A
(Cursor up) and\x1b[1;5A
(Cursor up with Ctrl)
- CsiKeyPattern
Detects ansi escape sequences in strings that have been read from the terminal (see IAnsiResponseParser). Handles CSI key parsing such as
\x1b[3;5~
(Delete with Ctrl)
- EscSeqReqStatus
Represents the status of an ANSI escape sequence request made to the terminal using EscSeqRequests.
- EscSeqRequests
Manages ANSI Escape Sequence requests and responses. The list of EscSeqReqStatus contains the status of the request. Each request is identified by the terminator (e.g. ESC[8t ... t is the terminator).
- EscSeqUtils
Provides a platform-independent API for managing ANSI escape sequences.
- FakeDriver
Implements a mock IConsoleDriver for unit testing
- InputProcessor<T>
Processes the queued input buffer contents - which must be of Type
T
. Is responsible for ProcessQueue() and translating into common Terminal.Gui events and data models.
- MainLoop<T>
Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.
- NetInputProcessor
Input processor for NetInput, deals in ConsoleKeyInfo stream
- NetOutput
Implementation of IConsoleOutput that uses native dotnet methods e.g. Console
- NotInitializedException
Thrown when user code attempts to access a property or perform a method that is only supported after Initialization e.g. of an IMainLoop<T>
- OutputBuffer
Stores the desired output state for the whole application. This is updated during draw operations before being flushed to the console as part of MainLoop<T> operation
- Ss3Pattern
Parser for SS3 terminal escape sequences. These describe specific keys e.g.
EscOP
is F1.
- ToplevelTransitionManager
Handles bespoke behaviours that occur when application top level changes.
Interfaces
- IAnsiResponseParser
When implemented in a derived class, allows watching an input stream of characters (i.e. console input) for ANSI response sequences (mouse input, cursor, query responses etc.).
- IConsoleDriver
Base interface for Terminal.Gui ConsoleDriver implementations.
- IConsoleDriverFacade
Interface for v2 driver abstraction layer
- IConsoleInput<T>
Interface for reading console input indefinitely - i.e. in an infinite loop. The class is responsible only for reading and storing the input in a thread safe input buffer which is then processed downstream e.g. on main UI thread.
- IConsoleOutput
Interface for writing console output
- IInputProcessor
Interface for main loop class that will process the queued input buffer contents. Is responsible for ProcessQueue() and translating into common Terminal.Gui events and data models.
- IKeyConverter<T>
Interface for subcomponent of a InputProcessor<T> which can translate the raw console input type T (which typically varies by driver) to the shared Terminal.Gui Key class.
- IMainLoopCoordinator
Interface for main Terminal.Gui loop manager in v2.
- IMainLoop<T>
Interface for main loop that runs the core Terminal.Gui UI loop.
- IOutputBuffer
Describes the screen state that you want the console to be in. Is designed to be drawn to repeatedly then manifest into the console once at the end of iteration after all drawing is finalized.
- IToplevelTransitionManager
Interface for class that handles bespoke behaviours that occur when application top level changes.
- IWindowSizeMonitor
Interface for classes responsible for reporting the current size of the terminal window.
Enums
- AnsiResponseParserState
Describes the current state of an IAnsiResponseParser
- ConsoleKeyMapping.VK
Generated from winuser.h. See https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
- CursorVisibility
Terminal Cursor Visibility settings.
- EscSeqUtils.ClearScreenOptions
Options for ANSI ESC "[xJ" - Clears part of the screen.
- EscSeqUtils.DECSCUSR_Style
Styles for ANSI ESC "[x q" - Set Cursor Style
- KeyCode
The KeyCode enumeration encodes key information from IConsoleDrivers and provides a consistent way for application code to specify keys and receive key events.
The Key class provides a higher-level abstraction, with helper methods and properties for common operations. For example, IsAlt and IsCtrl provide a convenient way to check whether the Alt or Ctrl modifier keys were pressed when a key was pressed.