Skip to content
ConsoleMonster
Class

ConsoleInput

ConsoleMonster.Input

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) #

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 optional
A source for this lease, or null for ConsoleInput.Override or the console.

Returns

InputLease The lease; dispose it when done.

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.

Returns

IInputSource? 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 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.