|
@@ -208,7 +208,7 @@ internal class NetEvents : IDisposable
|
|
|
|
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
{
|
|
{
|
|
- Task.Delay (100);
|
|
|
|
|
|
+ Task.Delay (100, cancellationToken).Wait (cancellationToken);
|
|
|
|
|
|
if (Console.KeyAvailable)
|
|
if (Console.KeyAvailable)
|
|
{
|
|
{
|
|
@@ -223,7 +223,7 @@ internal class NetEvents : IDisposable
|
|
|
|
|
|
private void ProcessInputQueue ()
|
|
private void ProcessInputQueue ()
|
|
{
|
|
{
|
|
- while (!_inputReadyCancellationTokenSource.Token.IsCancellationRequested)
|
|
|
|
|
|
+ while (_inputReadyCancellationTokenSource is { IsCancellationRequested: false })
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -242,13 +242,8 @@ internal class NetEvents : IDisposable
|
|
ConsoleModifiers mod = 0;
|
|
ConsoleModifiers mod = 0;
|
|
ConsoleKeyInfo newConsoleKeyInfo = default;
|
|
ConsoleKeyInfo newConsoleKeyInfo = default;
|
|
|
|
|
|
- while (true)
|
|
|
|
|
|
+ while (_inputReadyCancellationTokenSource is { IsCancellationRequested: false })
|
|
{
|
|
{
|
|
- if (_inputReadyCancellationTokenSource.Token.IsCancellationRequested)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
ConsoleKeyInfo consoleKeyInfo;
|
|
ConsoleKeyInfo consoleKeyInfo;
|
|
|
|
|
|
try
|
|
try
|
|
@@ -338,7 +333,7 @@ internal class NetEvents : IDisposable
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
while (!cancellationToken.IsCancellationRequested)
|
|
{
|
|
{
|
|
// Wait for a while then check if screen has changed sizes
|
|
// Wait for a while then check if screen has changed sizes
|
|
- Task.Delay (500, cancellationToken);
|
|
|
|
|
|
+ Task.Delay (500, cancellationToken).Wait (cancellationToken);
|
|
|
|
|
|
int buffHeight, buffWidth;
|
|
int buffHeight, buffWidth;
|
|
|
|
|
|
@@ -367,13 +362,8 @@ internal class NetEvents : IDisposable
|
|
cancellationToken.ThrowIfCancellationRequested ();
|
|
cancellationToken.ThrowIfCancellationRequested ();
|
|
}
|
|
}
|
|
|
|
|
|
- while (true)
|
|
|
|
|
|
+ while (_inputReadyCancellationTokenSource is { IsCancellationRequested: false })
|
|
{
|
|
{
|
|
- if (_inputReadyCancellationTokenSource.IsCancellationRequested)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
_winChange.Wait (_inputReadyCancellationTokenSource.Token);
|
|
_winChange.Wait (_inputReadyCancellationTokenSource.Token);
|
|
@@ -852,11 +842,37 @@ internal class NetDriver : ConsoleDriver
|
|
{ }
|
|
{ }
|
|
}
|
|
}
|
|
|
|
|
|
- #region Not Implemented
|
|
|
|
|
|
+ public override void Suspend ()
|
|
|
|
+ {
|
|
|
|
+ if (Environment.OSVersion.Platform != PlatformID.Unix)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StopReportingMouseMoves ();
|
|
|
|
|
|
- public override void Suspend () { throw new NotImplementedException (); }
|
|
|
|
|
|
+ if (!RunningUnitTests)
|
|
|
|
+ {
|
|
|
|
+ Console.ResetColor ();
|
|
|
|
+ Console.Clear ();
|
|
|
|
|
|
- #endregion
|
|
|
|
|
|
+ //Disable alternative screen buffer.
|
|
|
|
+ Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndRestoreAltBufferWithBackscroll);
|
|
|
|
+
|
|
|
|
+ //Set cursor key to cursor.
|
|
|
|
+ Console.Out.Write (EscSeqUtils.CSI_ShowCursor);
|
|
|
|
+
|
|
|
|
+ Platform.Suspend ();
|
|
|
|
+
|
|
|
|
+ //Enable alternative screen buffer.
|
|
|
|
+ Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
|
|
|
|
+
|
|
|
|
+ SetContentsAsDirty ();
|
|
|
|
+ Refresh ();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StartReportingMouseMoves ();
|
|
|
|
+ }
|
|
|
|
|
|
public override void UpdateScreen ()
|
|
public override void UpdateScreen ()
|
|
{
|
|
{
|
|
@@ -877,7 +893,7 @@ internal class NetDriver : ConsoleDriver
|
|
Attribute? redrawAttr = null;
|
|
Attribute? redrawAttr = null;
|
|
int lastCol = -1;
|
|
int lastCol = -1;
|
|
|
|
|
|
- CursorVisibility? savedVisibitity = _cachedCursorVisibility;
|
|
|
|
|
|
+ CursorVisibility? savedVisibility = _cachedCursorVisibility;
|
|
SetCursorVisibility (CursorVisibility.Invisible);
|
|
SetCursorVisibility (CursorVisibility.Invisible);
|
|
|
|
|
|
for (int row = top; row < rows; row++)
|
|
for (int row = top; row < rows; row++)
|
|
@@ -1006,7 +1022,7 @@ internal class NetDriver : ConsoleDriver
|
|
|
|
|
|
SetCursorPosition (0, 0);
|
|
SetCursorPosition (0, 0);
|
|
|
|
|
|
- _cachedCursorVisibility = savedVisibitity;
|
|
|
|
|
|
+ _cachedCursorVisibility = savedVisibility;
|
|
|
|
|
|
void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
|
|
void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
|
|
{
|
|
{
|
|
@@ -1333,12 +1349,9 @@ internal class NetDriver : ConsoleDriver
|
|
{
|
|
{
|
|
_cachedCursorVisibility = visibility;
|
|
_cachedCursorVisibility = visibility;
|
|
|
|
|
|
- bool isVisible = RunningUnitTests
|
|
|
|
- ? visibility == CursorVisibility.Default
|
|
|
|
- : Console.CursorVisible = visibility == CursorVisibility.Default;
|
|
|
|
- Console.Out.Write (isVisible ? EscSeqUtils.CSI_ShowCursor : EscSeqUtils.CSI_HideCursor);
|
|
|
|
|
|
+ Console.Out.Write (visibility == CursorVisibility.Default ? EscSeqUtils.CSI_ShowCursor : EscSeqUtils.CSI_HideCursor);
|
|
|
|
|
|
- return isVisible;
|
|
|
|
|
|
+ return visibility == CursorVisibility.Default;
|
|
}
|
|
}
|
|
|
|
|
|
public override bool EnsureCursorVisibility ()
|
|
public override bool EnsureCursorVisibility ()
|
|
@@ -1667,7 +1680,7 @@ internal class NetMainLoop : IMainLoopDriver
|
|
private readonly CancellationTokenSource _inputHandlerTokenSource = new ();
|
|
private readonly CancellationTokenSource _inputHandlerTokenSource = new ();
|
|
private readonly Queue<InputResult?> _resultQueue = new ();
|
|
private readonly Queue<InputResult?> _resultQueue = new ();
|
|
private readonly ManualResetEventSlim _waitForProbe = new (false);
|
|
private readonly ManualResetEventSlim _waitForProbe = new (false);
|
|
- private CancellationTokenSource _eventReadyTokenSource = new ();
|
|
|
|
|
|
+ private readonly CancellationTokenSource _eventReadyTokenSource = new ();
|
|
private MainLoop _mainLoop;
|
|
private MainLoop _mainLoop;
|
|
|
|
|
|
/// <summary>Initializes the class with the console driver.</summary>
|
|
/// <summary>Initializes the class with the console driver.</summary>
|
|
@@ -1719,14 +1732,13 @@ internal class NetMainLoop : IMainLoopDriver
|
|
_eventReady.Reset ();
|
|
_eventReady.Reset ();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ _eventReadyTokenSource.Token.ThrowIfCancellationRequested ();
|
|
|
|
+
|
|
if (!_eventReadyTokenSource.IsCancellationRequested)
|
|
if (!_eventReadyTokenSource.IsCancellationRequested)
|
|
{
|
|
{
|
|
return _resultQueue.Count > 0 || _mainLoop.CheckTimersAndIdleHandlers (out _);
|
|
return _resultQueue.Count > 0 || _mainLoop.CheckTimersAndIdleHandlers (out _);
|
|
}
|
|
}
|
|
|
|
|
|
- _eventReadyTokenSource.Dispose ();
|
|
|
|
- _eventReadyTokenSource = new CancellationTokenSource ();
|
|
|
|
-
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1783,26 +1795,21 @@ internal class NetMainLoop : IMainLoopDriver
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ _inputHandlerTokenSource.Token.ThrowIfCancellationRequested ();
|
|
|
|
+
|
|
if (_resultQueue.Count == 0)
|
|
if (_resultQueue.Count == 0)
|
|
{
|
|
{
|
|
_resultQueue.Enqueue (_netEvents.DequeueInput ());
|
|
_resultQueue.Enqueue (_netEvents.DequeueInput ());
|
|
}
|
|
}
|
|
|
|
|
|
- try
|
|
|
|
|
|
+ while (_resultQueue.Count > 0 && _resultQueue.Peek () is null)
|
|
{
|
|
{
|
|
- while (_resultQueue.Peek () is null)
|
|
|
|
- {
|
|
|
|
- _resultQueue.Dequeue ();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (_resultQueue.Count > 0)
|
|
|
|
- {
|
|
|
|
- _eventReady.Set ();
|
|
|
|
- }
|
|
|
|
|
|
+ _resultQueue.Dequeue ();
|
|
}
|
|
}
|
|
- catch (InvalidOperationException)
|
|
|
|
|
|
+
|
|
|
|
+ if (_resultQueue.Count > 0)
|
|
{
|
|
{
|
|
- // Ignore
|
|
|
|
|
|
+ _eventReady.Set ();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|