Browse Source

Prevents an alone escape being eating by the response.

BDisp 8 months ago
parent
commit
a3c961ef3f
1 changed files with 8 additions and 4 deletions
  1. 8 4
      Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsConsole.cs

+ 8 - 4
Terminal.Gui/ConsoleDrivers/WindowsDriver/WindowsConsole.cs

@@ -91,14 +91,15 @@ internal class WindowsConsole
                             // Check if input is part of an ANSI escape sequence
                             if (inputChar == '\u001B') // Escape character
                             {
-                                // Peek to check if there is any input available with key event and bKeyDown
+                                // Peek to check if there is any input available with key event and bKeyDown and not Escape character
                                 if (PeekConsoleInput (_inputHandle, out InputRecord peekRecord, BUFFER_SIZE, out eventsRead) && eventsRead > 0)
                                 {
-                                    if (peekRecord is { EventType: EventType.Key, KeyEvent.bKeyDown: true })
+                                    if (peekRecord is { EventType: EventType.Key, KeyEvent.bKeyDown: true, KeyEvent.UnicodeChar: not '\u001B' })
                                     {
                                         // It's really an ANSI request response
                                         readingSequence = true;
-                                        ansiSequence.Clear (); // Start a new sequence
+                                        // Start a new sequence ensuring in the cases where wasn't clear by reading the terminator
+                                        ansiSequence.Clear ();
                                         ansiSequence.Append (inputChar);
 
                                         continue;
@@ -127,7 +128,10 @@ internal class WindowsConsole
                                     }
                                 }
 
-                                continue;
+                                if (readingSequence)
+                                {
+                                    continue;
+                                }
                             }
                         }
                     }