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
Properties
CursorPosition
Gets or sets the cursor position.
public Point CursorPosition { get; set; }
Property Value
CursorVisible
Gets or sets the cursor visibility.
public bool CursorVisible { get; set; }
Property Value
FullOutput
Gets the concatenated output from all calls.
public string FullOutput { get; }
Property Value
OutputHistory
Gets the history of output operations (legacy, no longer populated).
public IReadOnlyList<string> OutputHistory { get; }
Property Value
ScreenSize
Gets the screen size.
public Size ScreenSize { get; }
Property Value
TotalBytesWritten
Gets the total number of bytes written across all calls.
public int TotalBytesWritten { get; }
Property Value
WriteCallCount
Gets the number of output operations recorded (legacy, no longer populated).
public int WriteCallCount { get; }
Property Value
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
xintThe starting horizontal position (column).
yintThe vertical position (row).
widthintThe number of cells to fill.
charactercharThe character to fill with.
fgColorThe foreground color.
bgColorThe 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
GetLastOutput()
Gets the most recent output string.
public string? GetLastOutput()
Returns
GetOutput(int)
Gets output from a specific call index.
public string? GetOutput(int index)
Parameters
indexint
Returns
Initialize(ConsoleWindowSystem)
Initializes the driver with a reference to the window system.
public void Initialize(ConsoleWindowSystem windowSystem)
Parameters
windowSystemConsoleWindowSystem
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
SetCursorShape(CursorShape)
Sets the cursor shape (no-op for headless).
public void SetCursorShape(CursorShape shape)
Parameters
shapeCursorShape
SetCursorVisible(bool)
Sets the cursor visibility.
public void SetCursorVisible(bool visible)
Parameters
visiblebool
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
xintThe horizontal position (column).
yintThe vertical position (row).
charactercharThe character to write.
fgColorThe foreground color.
bgColorThe background color.
SimulateKeyPress(ConsoleKeyInfo)
Simulates a key press event.
public void SimulateKeyPress(ConsoleKeyInfo keyInfo)
Parameters
keyInfoConsoleKeyInfo
SimulateMouseEvent(List<MouseFlags>, Point)
Simulates a mouse event.
public void SimulateMouseEvent(List<MouseFlags> flags, Point point)
Parameters
flagsList<MouseFlags>pointPoint
SimulateScreenResize(int, int)
Simulates a screen resize event.
public void SimulateScreenResize(int width, int height)
Parameters
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
destXintDestination screen X position.
destYintDestination screen Y position.
sourceCharacterBufferThe source CharacterBuffer.
srcXintSource X offset within the buffer.
srcYintSource Y (row) within the buffer.
widthintNumber of cells to write.
fallbackBgColorBackground 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
MouseEvent
Occurs when a mouse event is detected.
public event IConsoleDriver.MouseEventHandler? MouseEvent
Event Type
ScreenResized
Occurs when the console screen is resized.
public event EventHandler<Size>? ScreenResized