Skip to content
ConsoleMonster
Class

TerminalGuard

ConsoleMonster.Output

Namespace
ConsoleMonster.Output
Assembly
ConsoleMonster
Implements
IDisposable
Modifiers
sealed

Restores the screen and saved Windows output mode on disposal, termination or a second Ctrl+C.

Inheritance

  • object
  • TerminalGuard

Constructors

public TerminalGuard(Action restore, bool handleCancelKey = true) #

Creates a guard, saving the output mode and hooking process termination events.

Parameters

restore System.Action required
Restores the screen, cursor, attributes and host output routing.
handleCancelKey bool = true optional
Whether to intercept Ctrl+C.

Methods

public void Dispose() #

Releases the guard after any restoration already running on another thread completes.

public void Restore() #

Restores once; callback and native errors never escape this method.

Properties

public CancellationToken Cancellation { get; } #

Cancelled on the first Ctrl+C or when the guard is disposed.

public bool RestoreCompleted { get; } #

Whether the restore callback and mode-restoration attempt have completed.