mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
* Fixes #1763. Allowing read console inputs before idle handlers. * Locking FakeConsole.MockKeyPresses after the Application.Init. * Adding scenario checking failed for iterations.
This commit is contained in:
@@ -174,12 +174,12 @@ namespace Terminal.Gui {
|
||||
|
||||
bool IMainLoopDriver.EventsPending (bool wait)
|
||||
{
|
||||
UpdatePollMap ();
|
||||
|
||||
if (CheckTimers (wait, out var pollTimeout)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
UpdatePollMap ();
|
||||
|
||||
var n = poll (pollmap, (uint)pollmap.Length, pollTimeout);
|
||||
|
||||
if (n == KEY_RESIZE) {
|
||||
|
||||
@@ -58,24 +58,39 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
bool IMainLoopDriver.EventsPending (bool wait)
|
||||
{
|
||||
keyResult = null;
|
||||
waitForProbe.Set ();
|
||||
|
||||
if (CheckTimers (wait, out var waitTimeout)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
keyReady.WaitOne (waitTimeout);
|
||||
return keyResult.HasValue;
|
||||
}
|
||||
|
||||
bool CheckTimers (bool wait, out int waitTimeout)
|
||||
{
|
||||
long now = DateTime.UtcNow.Ticks;
|
||||
|
||||
int waitTimeout;
|
||||
if (mainLoop.timeouts.Count > 0) {
|
||||
waitTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
|
||||
if (waitTimeout < 0)
|
||||
return true;
|
||||
} else
|
||||
} else {
|
||||
waitTimeout = -1;
|
||||
}
|
||||
|
||||
if (!wait)
|
||||
waitTimeout = 0;
|
||||
|
||||
keyResult = null;
|
||||
waitForProbe.Set ();
|
||||
keyReady.WaitOne (waitTimeout);
|
||||
return keyResult.HasValue;
|
||||
int ic;
|
||||
lock (mainLoop.idleHandlers) {
|
||||
ic = mainLoop.idleHandlers.Count;
|
||||
}
|
||||
|
||||
return ic > 0;
|
||||
}
|
||||
|
||||
void IMainLoopDriver.MainIteration ()
|
||||
|
||||
@@ -1840,13 +1840,13 @@ namespace Terminal.Gui {
|
||||
|
||||
bool IMainLoopDriver.EventsPending (bool wait)
|
||||
{
|
||||
waitForProbe.Set ();
|
||||
winChange.Set ();
|
||||
|
||||
if (CheckTimers (wait, out var waitTimeout)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
waitForProbe.Set ();
|
||||
winChange.Set ();
|
||||
|
||||
try {
|
||||
if (!tokenSource.IsCancellationRequested) {
|
||||
eventReady.Wait (waitTimeout, tokenSource.Token);
|
||||
|
||||
@@ -48,15 +48,16 @@ namespace Terminal.Gui {
|
||||
List<Type> scenarioClasses = Scenario.GetDerivedClasses<Scenario> ();
|
||||
Assert.NotEmpty (scenarioClasses);
|
||||
|
||||
lock (FakeConsole.MockKeyPresses) {
|
||||
foreach (var scenarioClass in scenarioClasses) {
|
||||
foreach (var scenarioClass in scenarioClasses) {
|
||||
|
||||
// Setup some fake keypresses
|
||||
// Passing empty string will cause just a ctrl-q to be fired
|
||||
FakeConsole.MockKeyPresses.Clear ();
|
||||
int stackSize = CreateInput ("");
|
||||
// Setup some fake keypresses
|
||||
// Passing empty string will cause just a ctrl-q to be fired
|
||||
FakeConsole.MockKeyPresses.Clear ();
|
||||
int stackSize = CreateInput ("");
|
||||
|
||||
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
|
||||
|
||||
lock (FakeConsole.MockKeyPresses) {
|
||||
|
||||
int iterations = 0;
|
||||
Application.Iteration = () => {
|
||||
@@ -96,6 +97,8 @@ namespace Terminal.Gui {
|
||||
|
||||
if (abortCount != 0) {
|
||||
output.WriteLine ($"Scenario {scenarioClass} had abort count of {abortCount}");
|
||||
} else if (iterations > 1) {
|
||||
output.WriteLine ($"Scenario {scenarioClass} had iterations count of {iterations}");
|
||||
}
|
||||
|
||||
Assert.Equal (0, abortCount);
|
||||
|
||||
Reference in New Issue
Block a user