InputManager class Input
Manages raw terminal input handling, parsing, and dispatching.
The InputManager
is responsible for reading raw input bytes from
standard input, interpreting them as terminal input events (keyboard,
mouse, special sequences), and dispatching them via an InputDispatcher.
It also manages terminal modes and input features, such as enabling mouse input, ANSI processing (on Windows), and querying the cursor position.
Responsibilities:
- Configure terminal modes for raw input.
- Parse raw input bytes into high-level InputEvents.
- Dispatch events to registered handlers.
- Support cursor position querying and mouse event parsing.
- Handle input pausing and graceful shutdown.
Lifecycle:
- Constructed with an InputDispatcher to forward input events.
- Listens asynchronously on
stdin
for input data. - Supports Windows and Unix-like platforms with platform-specific setup.
- Cleans up and restores terminal state on stop.
Example
final dispatcher = InputDispatcher(renderer: renderManager);
final inputManager = InputManager(dispatcher: dispatcher);
// Subscribe to mouse events if needed:
inputManager.onEvent = (event) {
if (event is MouseEvent) {
print('Mouse event at (${event.x}, ${event.y})');
}
};
// Later, gracefully stop input handling:
inputManager.stop();
See also
- InputDispatcher: Receives and routes parsed input events.
- InputEvent: Represents keyboard, mouse, and other input types.
- RenderManager: Manages rendering that might respond to input events.
- MouseEvent: Represents mouse-specific input events.
Constructors
- InputManager.new({required InputDispatcher dispatcher})
-
Creates an InputManager forwarding parsed events to the given
dispatcher
.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- onEvent ↔ dynamic Function(MouseEvent)?
-
Optional callback for external subscription to mouse events.
getter/setter pair
- returnedCursorPositionX ↔ int
-
Last known cursor X position from terminal response (0-based).
getter/setter pair
- returnedCursorPositionY ↔ int
-
Last known cursor Y position from terminal response (0-based).
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
fetchCursorPosition(
) → Future< Point< int> > - Asynchronously fetches the current cursor position.
-
getCursorPosition(
void callback(int x, int y)) → void - Requests the terminal to send the current cursor position.
-
isCursorSupported(
) → Future< bool> - Returns a cached result indicating whether cursor position reporting is supported.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pauseInput(
) → void - Pauses input handling temporarily.
-
resumeInput(
) → void - Resumes input handling after pause.
-
stop(
) → void - Stops input handling, restores terminal to normal state, and exits the process.
-
supportsCursorResponse(
{Duration timeout = const Duration(milliseconds: 200)}) → Future< bool> -
Checks asynchronously if the terminal supports cursor position reporting,
with a configurable
timeout
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited