Browse Source

Fix ResetState and add DispatchResponse

tznind 10 months ago
parent
commit
6cef9d72fe
1 changed files with 9 additions and 4 deletions
  1. 9 4
      Terminal.Gui/ConsoleDrivers/AnsiResponseParser.cs

+ 9 - 4
Terminal.Gui/ConsoleDrivers/AnsiResponseParser.cs

@@ -135,8 +135,6 @@ class AnsiResponseParser
     {
         currentState = ParserState.Normal;
         held.Clear ();
-        currentTerminator = null;
-        currentResponse = null;
     }
 
     /// <summary>
@@ -147,8 +145,7 @@ class AnsiResponseParser
         // If we're expecting a specific terminator, check if the content matches
         if (currentTerminator != null && held.ToString ().EndsWith (currentTerminator))
         {
-            // If it matches the expected response, invoke the callback and return nothing for output
-            currentResponse?.Invoke (held.ToString ());
+            DispatchResponse ();
             return string.Empty;
         }
 
@@ -165,6 +162,14 @@ class AnsiResponseParser
         return string.Empty;
     }
 
+    private void DispatchResponse ()
+    {
+        // If it matches the expected response, invoke the callback and return nothing for output
+        currentResponse?.Invoke (held.ToString ());
+        currentResponse = null;
+        currentTerminator = null;
+        ResetState ();
+    }
 
     /// <summary>
     /// Registers a new expected ANSI response with a specific terminator and a callback for when the response is completed.