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
- Extension Methods
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
Methods
Clear()
Clears the console screen or buffer.
void Clear()
FillCells(int, int, int, char, Color, Color)
Fills a horizontal run of cells at the specified position with the given character and colors.
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 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
windowSystemConsoleWindowSystemThe window system instance
InvalidateFrontBuffer()
Forces the next flush to re-emit every cell (used by watchdog recovery to repair the screen after stray terminal output). No-op for drivers that do not diff-render.
void InvalidateFrontBuffer()
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
SetCursorShape(CursorShape)
Sets the cursor shape/style.
void SetCursorShape(CursorShape shape)
Parameters
shapeCursorShapeThe desired cursor shape.
SetCursorShape(CursorShape, CursorBlink)
Sets the cursor shape/style together with its blink behavior.
void SetCursorShape(CursorShape shape, CursorBlink blink)
Parameters
shapeCursorShapeThe desired cursor shape.
blinkCursorBlinkThe desired blink behavior.
Remarks
The default implementation ignores blink and delegates to
SetCursorShape(CursorShape) so existing drivers keep working.
SetCursorVisible(bool)
Sets the visibility of the cursor.
void SetCursorVisible(bool visible)
Parameters
visibleboolTrue to show the cursor, false to hide it.
SetNarrowCell(int, int, char, Color, Color)
Sets a single cell at the specified position with the given character and colors.
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.
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()
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.
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.
WriteClipboardOsc52(string)
Writes a pre-built OSC 52 clipboard escape sequence to the terminal output stream (under the driver's output lock). Default no-op for drivers without terminal output.
void WriteClipboardOsc52(string sequence)
Parameters
sequencestringThe full escape sequence (already encoded/wrapped).
Events
KeyPressed
Occurs when a key is pressed on the keyboard.
event EventHandler<ConsoleKeyInfo> KeyPressed
Event Type
MouseEvent
Occurs when a mouse event is detected.
event IConsoleDriver.MouseEventHandler? MouseEvent
Event Type
Paste
Occurs when a bracketed-paste block is received (delivered atomically).
event EventHandler<string>? Paste
Event Type
ScreenResized
Occurs when the console screen is resized. Low-level driver event: fires on a background thread, before the framework repositions windows, and requires the subscriber to marshal to the UI thread and invalidate manually. Application code should prefer WindowResized, which fires on the UI thread after reposition and re-invalidates automatically.
event EventHandler<Size>? ScreenResized