Skip to content

Commit

Permalink
Fix ResetState and add DispatchResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Oct 11, 2024
1 parent a0c3363 commit 6cef9d7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Terminal.Gui/ConsoleDrivers/AnsiResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ private void ResetState ()
{
currentState = ParserState.Normal;
held.Clear ();
currentTerminator = null;
currentResponse = null;
}

/// <summary>
Expand All @@ -147,8 +145,7 @@ private string HandleHeldContent ()
// 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;
}

Expand All @@ -165,6 +162,14 @@ private string HandleHeldContent ()
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.
Expand Down

0 comments on commit 6cef9d7

Please sign in to comment.