Browse Source

Tidy up code.

BDisp 8 months ago
parent
commit
70e91f2b6f

+ 5 - 2
Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs

@@ -181,8 +181,6 @@ internal class UnixMainLoop (ConsoleDriver consoleDriver) : IMainLoopDriver
             {
                 return;
             }
-
-            _eventReady.Set ();
         }
     }
 
@@ -278,6 +276,11 @@ internal class UnixMainLoop (ConsoleDriver consoleDriver) : IMainLoopDriver
                 }
             }
         }
+
+        if (_pollDataQueue.Count > 0)
+        {
+            _eventReady.Set ();
+        }
     }
 
     private void ProcessEnqueuePollData (string pollData)

+ 1 - 1
Terminal.Gui/ConsoleDrivers/NetDriver/NetEvents.cs

@@ -245,7 +245,7 @@ internal class NetEvents : IDisposable
                     break;
                 }
 
-                if (!_inputReady.IsSet)
+                if (_inputQueue.Count > 0)
                 {
                     _inputReady.Set ();
                 }

+ 22 - 18
Terminal.Gui/ConsoleDrivers/NetDriver/NetMainLoop.cs

@@ -120,34 +120,38 @@ internal class NetMainLoop : IMainLoopDriver
             {
                 if (!_inputHandlerTokenSource.IsCancellationRequested && !((IMainLoopDriver)this)._forceRead)
                 {
-                    _waitForProbe.Wait (_inputHandlerTokenSource.Token);
-                }
-
-                if (_resultQueue?.Count == 0 || ((IMainLoopDriver)this)._forceRead)
-                {
-                    NetEvents.InputResult? result = _netEvents!.DequeueInput ();
-
-                    if (result.HasValue)
+                    try
                     {
-                        _resultQueue?.Enqueue (result.Value);
+                        _waitForProbe.Wait (_inputHandlerTokenSource.Token);
+                    }
+                    catch (OperationCanceledException)
+                    {
+                        return;
                     }
-                }
 
-                if (!_inputHandlerTokenSource.IsCancellationRequested && _resultQueue?.Count > 0)
-                {
-                    _eventReady.Set ();
+                    _waitForProbe.Reset ();
                 }
+
+                ProcessInputQueue ();
             }
             catch (OperationCanceledException)
             {
                 return;
             }
-            finally
+        }
+    }
+
+    private void ProcessInputQueue ()
+    {
+        if (_resultQueue?.Count == 0 || ((IMainLoopDriver)this)._forceRead)
+        {
+            NetEvents.InputResult? result = _netEvents!.DequeueInput ();
+
+            if (result.HasValue)
             {
-                if (_inputHandlerTokenSource is { IsCancellationRequested: false })
-                {
-                    _waitForProbe.Reset ();
-                }
+                _resultQueue?.Enqueue (result.Value);
+
+                _eventReady.Set ();
             }
         }
     }

+ 16 - 10
Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsMainLoop.cs

@@ -168,22 +168,28 @@ internal class WindowsMainLoop : IMainLoopDriver
                     ((IMainLoopDriver)this)._waitForInput.Reset ();
                 }
 
-                if (_resultQueue?.Count == 0 || _forceRead)
-                {
-                    WindowsConsole.InputRecord? result = _winConsole!.DequeueInput ();
-
-                    if (result.HasValue)
-                    {
-                        _resultQueue!.Enqueue (result.Value);
-                    }
-                }
+                ProcessInputQueue ();
             }
             catch (OperationCanceledException)
             {
                 return;
             }
 
-            _eventReady.Set ();
+        }
+    }
+
+    private void ProcessInputQueue ()
+    {
+        if (_resultQueue?.Count == 0 || _forceRead)
+        {
+            WindowsConsole.InputRecord? result = _winConsole!.DequeueInput ();
+
+            if (result.HasValue)
+            {
+                _resultQueue!.Enqueue (result.Value);
+
+                _eventReady.Set ();
+            }
         }
     }