Re-enabled -1 result

This commit is contained in:
Tigger Kindel
2023-10-05 08:20:06 -06:00
committed by Tig
parent 1c133ba364
commit f90ddd520b
5 changed files with 24 additions and 15 deletions

View File

@@ -464,8 +464,8 @@ namespace Terminal.Gui {
/// To make a <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call <see cref="Application.RequestStop"/>.
/// </para>
/// <para>
/// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling <see cref="Begin(Toplevel)"/>, followed by <see cref="RunLoop(RunState, bool)"/>,
/// and then calling <see cref="End(RunState)"/>.
/// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling <see cref="Begin(Toplevel)"/>,
/// followed by <see cref="RunLoop(RunState)"/>, and then calling <see cref="End(RunState)"/>.
/// </para>
/// <para>
/// Alternatively, to have a program control the main loop and
@@ -481,7 +481,7 @@ namespace Terminal.Gui {
/// this method will exit.
/// </para>
/// </remarks>
/// <param name="view">The <see cref="Toplevel"/> to run modally.</param>
/// <param name="view">The <see cref="Toplevel"/> to run as a modal.</param>
/// <param name="errorHandler">RELEASE builds only: Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
public static void Run (Toplevel view, Func<Exception, bool> errorHandler = null)
{

View File

@@ -1301,9 +1301,9 @@ internal class NetDriver : ConsoleDriver {
/// This implementation is used for NetDriver.
/// </remarks>
internal class NetMainLoop : IMainLoopDriver {
ManualResetEventSlim _keyReady = new ManualResetEventSlim (false);
ManualResetEventSlim _waitForProbe = new ManualResetEventSlim (false);
Queue<NetEvents.InputResult?> _inputResult = new Queue<NetEvents.InputResult?> ();
readonly ManualResetEventSlim _keyReady = new ManualResetEventSlim (false);
readonly ManualResetEventSlim _waitForProbe = new ManualResetEventSlim (false);
readonly Queue<NetEvents.InputResult?> _inputResult = new Queue<NetEvents.InputResult?> ();
MainLoop _mainLoop;
CancellationTokenSource _tokenSource = new CancellationTokenSource ();
internal NetEvents _netEvents;
@@ -1369,6 +1369,8 @@ internal class NetMainLoop : IMainLoopDriver {
try {
if (!_tokenSource.IsCancellationRequested) {
// Note: ManualResetEventSlim.Wait will wait indefinitely if the timeout is -1. The timeout is -1 when there
// are no timers, but there IS an idle handler waiting.
_keyReady.Wait (waitTimeout, _tokenSource.Token);
}
} catch (OperationCanceledException) {

View File

@@ -1765,18 +1765,18 @@ internal class WindowsDriver : ConsoleDriver {
/// This implementation is used for WindowsDriver.
/// </remarks>
internal class WindowsMainLoop : IMainLoopDriver {
ManualResetEventSlim _eventReady = new ManualResetEventSlim (false);
ManualResetEventSlim _waitForProbe = new ManualResetEventSlim (false);
ManualResetEventSlim _winChange = new ManualResetEventSlim (false);
readonly ManualResetEventSlim _eventReady = new ManualResetEventSlim (false);
readonly ManualResetEventSlim _waitForProbe = new ManualResetEventSlim (false);
readonly ManualResetEventSlim _winChange = new ManualResetEventSlim (false);
MainLoop _mainLoop;
ConsoleDriver _consoleDriver;
WindowsConsole _winConsole;
readonly ConsoleDriver _consoleDriver;
readonly WindowsConsole _winConsole;
bool _winChanged;
Size _windowSize;
CancellationTokenSource _eventReadyTokenSource = new CancellationTokenSource ();
// The records that we keep fetching
Queue<WindowsConsole.InputRecord []> _resultQueue = new Queue<WindowsConsole.InputRecord []> ();
readonly Queue<WindowsConsole.InputRecord []> _resultQueue = new Queue<WindowsConsole.InputRecord []> ();
/// <summary>
/// Invoked when a Key is pressed or released.
@@ -1790,7 +1790,7 @@ internal class WindowsMainLoop : IMainLoopDriver {
public WindowsMainLoop (ConsoleDriver consoleDriver = null)
{
_consoleDriver = consoleDriver ?? throw new ArgumentNullException ("Console driver instance must be provided.");
_consoleDriver = consoleDriver ?? throw new ArgumentNullException (nameof(consoleDriver));
_winConsole = ((WindowsDriver)consoleDriver).WinConsole;
}
@@ -1851,6 +1851,8 @@ internal class WindowsMainLoop : IMainLoopDriver {
try {
if (!_eventReadyTokenSource.IsCancellationRequested) {
// Note: ManualResetEventSlim.Wait will wait indefinitely if the timeout is -1. The timeout is -1 when there
// are no timers, but there IS an idle handler waiting.
_eventReady.Wait (waitTimeout, _eventReadyTokenSource.Token);
}
} catch (OperationCanceledException) {
@@ -1874,7 +1876,7 @@ internal class WindowsMainLoop : IMainLoopDriver {
{
while (_resultQueue.Count > 0) {
var inputRecords = _resultQueue.Dequeue ();
if (inputRecords != null && inputRecords.Length > 0) {
if (inputRecords is { Length: > 0 }) {
var inputEvent = inputRecords [0];
ProcessInput?.Invoke (inputEvent);
}

View File

@@ -226,7 +226,8 @@ namespace Terminal.Gui {
/// <summary>
/// Called from <see cref="IMainLoopDriver.EventsPending"/> to check if there are any outstanding timers or idle handlers.
/// </summary>
/// <param name="waitTimeout">Returns the number of milliseconds remaining in the current timer (if any).</param>
/// <param name="waitTimeout">Returns the number of milliseconds remaining in the current timer (if any). Will be -1 if
/// there are no active timers.</param>
/// <returns><see langword="true"/> if there is a timer or idle handler active.</returns>
public bool CheckTimersAndIdleHandlers (out int waitTimeout)
{
@@ -245,6 +246,9 @@ namespace Terminal.Gui {
}
return true;
}
// ManualResetEventSlim.Wait, which is called by IMainLoopDriver.EventsPending, will wait indefinitely if
// the timeout is -1.
waitTimeout = -1;
}
// There are no timers set, check if there are any idle handlers

View File

@@ -113,6 +113,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=CAF4ECB3AC41AE43BD233D613AC1562C/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=CAF4ECB3AC41AE43BD233D613AC1562C/AbsolutePath/@EntryValue">Terminal.sln.DotSettings</s:String>
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=CAF4ECB3AC41AE43BD233D613AC1562C/RelativePath/@EntryValue"></s:String>