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
driverIConsoleDriverThe console driver to use for cursor operations.
Properties
CurrentState
Gets the current cursor state
public CursorState CurrentState { get; }
Property Value
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
screenWidthintThe screen width for bounds checking
screenHeightintThe 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
GetHistory()
Gets recent cursor state history for debugging
public IReadOnlyList<CursorState> GetHistory()
Returns
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
shapeCursorShape
SetVisible(bool)
Sets cursor visibility without changing other properties
public void SetVisible(bool visible)
Parameters
visiblebool
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
ownerWindowWindowThe window containing the cursor (if any)
logicalPositionPoint?The logical position within the owner control
absolutePositionPoint?The absolute screen position
ownerControlIWindowControlThe control that owns the cursor (if any)
shapeCursorShapeThe cursor shape to use
Events
OwnerChanged
Event fired specifically when cursor owner (control/window) changes
public event EventHandler? OwnerChanged
Event Type
PositionChanged
Event fired specifically when cursor position changes
public event EventHandler? PositionChanged
Event Type
StateChanged
Event fired when any aspect of cursor state changes
public event EventHandler<CursorStateChangedEventArgs>? StateChanged
Event Type
VisibilityChanged
Event fired specifically when cursor visibility changes
public event EventHandler? VisibilityChanged