Skip to content

Commit

Permalink
Restore console input cancellation settings (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibayan authored Jul 13, 2022
1 parent f8d8405 commit b61d2c9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sharprompt/Drivers/DefaultConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ static DefaultConsoleDriver()
throw new InvalidOperationException(Resource.Message_NotSupportedEnvironment);
}

Console.TreatControlCAsInput = true;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var hConsole = NativeMethods.GetStdHandle(NativeMethods.STD_OUTPUT_HANDLE);
Expand All @@ -30,6 +28,15 @@ static DefaultConsoleDriver()
}
}

public DefaultConsoleDriver()
{
_previousTreatControlCAsInput = Console.TreatControlCAsInput;

Console.TreatControlCAsInput = true;
}

private readonly bool _previousTreatControlCAsInput;

#region IDisposable

public void Dispose() => Reset();
Expand All @@ -44,6 +51,8 @@ public void Reset()
{
Console.CursorVisible = true;
Console.ResetColor();

Console.TreatControlCAsInput = _previousTreatControlCAsInput;
}

public void ClearLine(int top)
Expand Down

0 comments on commit b61d2c9

Please sign in to comment.