Table of Contents

Interface IConsoleDriver

Namespace
SharpConsoleUI.Drivers
Assembly
SharpConsoleUI.dll

Defines the interface for console drivers that handle low-level console input/output operations.

public interface IConsoleDriver

Remarks

Console drivers abstract the platform-specific console functionality, providing a unified interface for keyboard input, mouse events, screen resizing, and console output.

Properties

ScreenSize

Gets the current size of the console screen.

Size ScreenSize { get; }

Property Value

Size

A Size representing the width and height of the console in characters.

Methods

Clear()

Clears the console screen or buffer.

void Clear()

Flush()

Flushes any buffered output to the console.

void Flush()

Remarks

For buffered render modes, this triggers the actual rendering to the console. For direct render modes, this may be a no-op.

GetDirtyCharacterCount()

Gets the count of dirty characters in the rendering buffer.

int GetDirtyCharacterCount()

Returns

int

The number of dirty characters, or 0 if not using buffered rendering.

Initialize(ConsoleWindowSystem)

Initializes the driver with a reference to the window system. Called by ConsoleWindowSystem after state services are created.

void Initialize(ConsoleWindowSystem windowSystem)

Parameters

windowSystem ConsoleWindowSystem

The window system instance

ResetCursorShape()

Resets the cursor to the default shape.

void ResetCursorShape()

SetCursorPosition(int, int)

Sets the cursor position on the console screen.

void SetCursorPosition(int x, int y)

Parameters

x int

The column position (0-based).

y int

The row position (0-based).

SetCursorShape(CursorShape)

Sets the cursor shape/style.

void SetCursorShape(CursorShape shape)

Parameters

shape CursorShape

The desired cursor shape.

SetCursorVisible(bool)

Sets the visibility of the cursor.

void SetCursorVisible(bool visible)

Parameters

visible bool

True to show the cursor, false to hide it.

Start()

Starts the console driver, initializing input handling and enabling mouse/keyboard events.

void Start()

Stop()

Stops the console driver, disabling input handling and restoring the console to its original state.

void Stop()

WriteToConsole(int, int, string)

Writes a string value to the console at the specified position.

void WriteToConsole(int x, int y, string value)

Parameters

x int

The horizontal position (column) to write at.

y int

The vertical position (row) to write at.

value string

The string value to write, which may include ANSI escape sequences.

Events

KeyPressed

Occurs when a key is pressed on the keyboard.

event EventHandler<ConsoleKeyInfo> KeyPressed

Event Type

EventHandler<ConsoleKeyInfo>

MouseEvent

Occurs when a mouse event is detected.

event IConsoleDriver.MouseEventHandler? MouseEvent

Event Type

IConsoleDriver.MouseEventHandler

ScreenResized

Occurs when the console screen is resized.

event EventHandler<Size>? ScreenResized

Event Type

EventHandler<Size>