Table of Contents

Class CursorStateService

Namespace
SharpConsoleUI.Core
Assembly
SharpConsoleUI.dll

Centralized service for managing cursor state across the window system. Provides a single source of truth for cursor visibility, position, and ownership.

public class CursorStateService : IDisposable
Inheritance
CursorStateService
Implements
Inherited Members

Constructors

CursorStateService(IConsoleDriver)

Initializes a new instance of the CursorStateService class.

public CursorStateService(IConsoleDriver driver)

Parameters

driver IConsoleDriver

The console driver to use for cursor operations.

Properties

CurrentState

Gets the current cursor state

public CursorState CurrentState { get; }

Property Value

CursorState

Methods

ApplyCursorToConsole(int, int)

Applies the current cursor state to the console. This method should be called after updating state to reflect changes in the actual console.

public bool ApplyCursorToConsole(int screenWidth, int screenHeight)

Parameters

screenWidth int

The screen width for bounds checking

screenHeight int

The screen height for bounds checking

Returns

bool

True if cursor was applied successfully

ClearHistory()

Clears the state history

public void ClearHistory()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetDebugInfo()

Gets a debug string representation of current cursor state

public string GetDebugInfo()

Returns

string

GetHistory()

Gets recent cursor state history for debugging

public IReadOnlyList<CursorState> GetHistory()

Returns

IReadOnlyList<CursorState>

HideCursor()

Hides the cursor and clears ownership

public void HideCursor()

SetShape(CursorShape)

Sets cursor shape without changing other properties

public void SetShape(CursorShape shape)

Parameters

shape CursorShape

SetVisible(bool)

Sets cursor visibility without changing other properties

public void SetVisible(bool visible)

Parameters

visible bool

UpdateFromWindowSystem(Window?, Point?, Point?, IWindowControl?, CursorShape)

Updates cursor state from the window system. This is the primary method for updating cursor state based on focused controls.

public void UpdateFromWindowSystem(Window? ownerWindow, Point? logicalPosition, Point? absolutePosition, IWindowControl? ownerControl, CursorShape shape = CursorShape.Block)

Parameters

ownerWindow Window

The window containing the cursor (if any)

logicalPosition Point?

The logical position within the owner control

absolutePosition Point?

The absolute screen position

ownerControl IWindowControl

The control that owns the cursor (if any)

shape CursorShape

The cursor shape to use

Events

OwnerChanged

Event fired specifically when cursor owner (control/window) changes

public event EventHandler? OwnerChanged

Event Type

EventHandler

PositionChanged

Event fired specifically when cursor position changes

public event EventHandler? PositionChanged

Event Type

EventHandler

StateChanged

Event fired when any aspect of cursor state changes

public event EventHandler<CursorStateChangedEventArgs>? StateChanged

Event Type

EventHandler<CursorStateChangedEventArgs>

VisibilityChanged

Event fired specifically when cursor visibility changes

public event EventHandler? VisibilityChanged

Event Type

EventHandler