Table of Contents

Class HeadlessConsoleDriver

Namespace
SharpConsoleUI.Drivers
Assembly
SharpConsoleUI.dll

A headless console driver that captures output instead of writing to the real console. Useful for testing, CI/CD pipelines, and scenarios where no terminal is available. Provides inspection methods for validating rendering output.

public class HeadlessConsoleDriver : IConsoleDriver, IDisposable
Inheritance
HeadlessConsoleDriver
Implements
Inherited Members
Extension Methods

Constructors

HeadlessConsoleDriver()

Creates a new headless console driver with default size 200x50.

public HeadlessConsoleDriver()

HeadlessConsoleDriver(int, int)

Creates a new headless console driver with specified size.

public HeadlessConsoleDriver(int width, int height)

Parameters

width int
height int

Properties

CursorPosition

Gets or sets the cursor position.

public Point CursorPosition { get; set; }

Property Value

Point

CursorVisible

Gets or sets the cursor visibility.

public bool CursorVisible { get; set; }

Property Value

bool

FullOutput

Gets the concatenated output from all calls.

public string FullOutput { get; }

Property Value

string

OutputHistory

Gets the history of output operations (legacy, no longer populated).

public IReadOnlyList<string> OutputHistory { get; }

Property Value

IReadOnlyList<string>

ScreenSize

Gets the screen size.

public Size ScreenSize { get; }

Property Value

Size

TotalBytesWritten

Gets the total number of bytes written across all calls.

public int TotalBytesWritten { get; }

Property Value

int

WriteCallCount

Gets the number of output operations recorded (legacy, no longer populated).

public int WriteCallCount { get; }

Property Value

int

Methods

Clear()

Clears the output history.

public void Clear()

ClearHistory()

Clears the output history (alias for Clear()).

public void ClearHistory()

Dispose()

Disposes of the headless console driver and releases resources.

public void Dispose()

FillCells(int, int, int, char, Color, Color)

Fills a horizontal run of cells at the specified position with the given character and colors.

public void FillCells(int x, int y, int width, char character, Color fg, Color bg)

Parameters

x int

The starting horizontal position (column).

y int

The vertical position (row).

width int

The number of cells to fill.

character char

The character to fill with.

fg Color

The foreground color.

bg Color

The background color.

Flush()

Flushes the console buffer, triggering actual rendering with diagnostics capture.

public void Flush()

GetDirtyCharacterCount()

Returns the count of dirty characters from the ConsoleBuffer.

public int GetDirtyCharacterCount()

Returns

int

GetLastOutput()

Gets the most recent output string.

public string? GetLastOutput()

Returns

string

GetOutput(int)

Gets output from a specific call index.

public string? GetOutput(int index)

Parameters

index int

Returns

string

Initialize(ConsoleWindowSystem)

Initializes the driver with a reference to the window system.

public void Initialize(ConsoleWindowSystem windowSystem)

Parameters

windowSystem ConsoleWindowSystem

ResetCursorShape()

Resets the cursor shape (no-op for headless).

public void ResetCursorShape()

SetCursorPosition(int, int)

Sets the cursor position.

public void SetCursorPosition(int x, int y)

Parameters

x int
y int

SetCursorShape(CursorShape)

Sets the cursor shape (no-op for headless).

public void SetCursorShape(CursorShape shape)

Parameters

shape CursorShape

SetCursorVisible(bool)

Sets the cursor visibility.

public void SetCursorVisible(bool visible)

Parameters

visible bool

SetNarrowCell(int, int, char, Color, Color)

Sets a single cell at the specified position with the given character and colors.

public void SetNarrowCell(int x, int y, char character, Color fg, Color bg)

Parameters

x int

The horizontal position (column).

y int

The vertical position (row).

character char

The character to write.

fg Color

The foreground color.

bg Color

The background color.

SimulateKeyPress(ConsoleKeyInfo)

Simulates a key press event.

public void SimulateKeyPress(ConsoleKeyInfo keyInfo)

Parameters

keyInfo ConsoleKeyInfo

SimulateMouseEvent(List<MouseFlags>, Point)

Simulates a mouse event.

public void SimulateMouseEvent(List<MouseFlags> flags, Point point)

Parameters

flags List<MouseFlags>
point Point

SimulateScreenResize(int, int)

Simulates a screen resize event.

public void SimulateScreenResize(int width, int height)

Parameters

width int
height int

Start()

Starts the driver (no-op for headless).

public void Start()

Stop()

Stops the driver (no-op for headless).

public void Stop()

WriteBufferRegion(int, int, CharacterBuffer, int, int, int, Color)

Copies a horizontal strip of cells from a CharacterBuffer directly to the console output buffer, bypassing ANSI string serialization and parsing.

public void WriteBufferRegion(int destX, int destY, CharacterBuffer source, int srcX, int srcY, int width, Color fallbackBg)

Parameters

destX int

Destination screen X position.

destY int

Destination screen Y position.

source CharacterBuffer

The source CharacterBuffer.

srcX int

Source X offset within the buffer.

srcY int

Source Y (row) within the buffer.

width int

Number of cells to write.

fallbackBg Color

Background color for padding when source is out of bounds.

Events

KeyPressed

Occurs when a key is pressed on the keyboard.

public event EventHandler<ConsoleKeyInfo>? KeyPressed

Event Type

EventHandler<ConsoleKeyInfo>

MouseEvent

Occurs when a mouse event is detected.

public event IConsoleDriver.MouseEventHandler? MouseEvent

Event Type

IConsoleDriver.MouseEventHandler

ScreenResized

Occurs when the console screen is resized.

public event EventHandler<Size>? ScreenResized

Event Type

EventHandler<Size>