#nullable enable namespace Terminal.Gui; /// /// Represents the status of an ANSI escape sequence request made to the terminal using /// . /// /// public class EscSeqReqStatus { /// Creates a new state of escape sequence request. /// The object. public EscSeqReqStatus (AnsiEscapeSequenceRequest ansiRequest) { AnsiRequest = ansiRequest; } /// Gets the Escape Sequence Terminator (e.g. ESC[8t ... t is the terminator). public AnsiEscapeSequenceRequest AnsiRequest { get; } } // TODO: This class is a singleton. It should use the singleton pattern. /// /// Manages ANSI Escape Sequence requests and responses. The list of contains the /// status of the request. Each request is identified by the terminator (e.g. ESC[8t ... t is the terminator). /// public class EscSeqRequests { /// /// Adds a new request for the ANSI Escape Sequence defined by . Adds a /// instance to list. /// /// The object. public void Add (AnsiEscapeSequenceRequest ansiRequest) { lock (Statuses) { Statuses.Enqueue (new (ansiRequest)); Console.Out.Write (ansiRequest.Request); Console.Out.Flush (); Thread.Sleep (100); // Allow time for the terminal to respond } } /// /// Indicates if a with the exists in the /// list. /// /// /// /// if exist, otherwise. public bool HasResponse (string terminator, out EscSeqReqStatus? seqReqStatus) { lock (Statuses) { Statuses.TryPeek (out seqReqStatus); var result = seqReqStatus?.AnsiRequest.Terminator == terminator; if (result) { return true; } seqReqStatus = null; return false; } } /// /// Removes a request defined by . If a matching is /// found and the number of outstanding requests is greater than 0, the number of outstanding requests is decremented. /// If the number of outstanding requests is 0, the is removed from /// . /// /// The object. public void Remove (EscSeqReqStatus? seqReqStatus) { lock (Statuses) { Statuses.Dequeue (); } } /// Gets the list. public Queue Statuses { get; } = new (); }