ConsoleInput
ConsoleMonster.Input
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) #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
- A source for this lease, or null for ConsoleInput.Override or the console.
Exceptions
InvalidOperationException– Another thread holds the keyboard, or no console input exists.
public static IInputSource? OpenConsole() #Opens the platform console reader: WindowsConsoleInput on Windows, ConsoleKeyInput elsewhere.
Inherited Methods
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 CONSOLEMONSTER_INPUT when set, otherwise the console. The environment variable accepts ScriptedInput syntax and supplies one shared sequence for the process, including successive prompts. An explicit override always wins. Clear the variable when returning to keyboard input.
public static bool IsAcquired { get; } #Whether the console (or ConsoleInput.Override) is currently leased.