Skip to content
ConsoleMonster

API Reference

Class

ConsoleInput

Namespace ConsoleMonster.Input
Assembly ConsoleMonster
Modifiers static

The single owner of keyboard input. Prompts, menus and forms read the console through a lease from ConsoleInput.Acquire, so two components never fight over the keyboard: nested prompts on the same thread share the lease, and a second thread that tries to read while a prompt is open gets a clear error instead of stolen keys. A lease for an explicit source (a script, an embedding host's own input) does not touch the console and is independent of the console owner.

Inheritance

  • Object
  • ConsoleInput

Methods

public static InputLease Acquire(IInputSource? source = null) #
Returns: InputLease

Takes the keyboard. The first lease opens the source (switching the Windows console to raw key input); the last release restores it. Reentrant on the owning thread. With an explicit source the lease simply reads that source.

Parameters

source ConsoleMonster.Input.IInputSource? = null optionalposition: 0
A source for this lease, or null for ConsoleInput.Override or the console.

Returns

The lease; dispose it when done.

Exceptions

  • InvalidOperationException – Another thread holds the keyboard, or no console input exists.
public static IInputSource? OpenConsole() #
Returns: IInputSource?

Opens the platform console reader: WindowsConsoleInput on Windows, ConsoleKeyInput elsewhere.

Returns

The source, or null when standard input is not a console.

Properties

public static IInputSource? Override { get; set; } #

A source to use instead of the console (a script in tests or demos, or an embedding host's own input). Null uses the console.

public static Boolean IsAcquired { get; } #

Whether the console (or ConsoleInput.Override) is currently leased.