Esempio n. 1
0
        private static TerminalSequence ConsumeCompliance(XTermInputBuffer stream)
        {
            var next = stream.Read();

            var compliance = new OscSequence
            {
                Command = next.ToString()
            };

            stream.Commit();

            //System.Diagnostics.Debug.WriteLine(compliance.ToString());

            return(compliance);
        }
Esempio n. 2
0
        private static TerminalSequence ConsumeOSC(XTermInputBuffer stream)
        {
            stream.PushState();

            string command        = "";
            bool   readingCommand = false;
            bool   atStart        = true;
            bool   isQuery        = false;
            bool   isSend         = false;
            bool   isBang         = false;
            char?  modifier       = null;

            int        currentParameter = -1;
            List <int> Parameters       = new List <int>();

            while (!stream.AtEnd)
            {
                var next = stream.Read();

                if (readingCommand)
                {
                    if (next == 0x07 || next == 0x9C)        // BEL or ST
                    {
                        var osc = new OscSequence
                        {
                            Parameters = Parameters,
                            IsQuery    = isQuery,
                            IsSend     = isSend,
                            IsBang     = isBang,
                            Command    = command
                        };

                        stream.Commit();

                        //System.Diagnostics.Debug.WriteLine(osc.ToString());

                        return(osc);
                    }
                    else
                    {
                        command += next;
                    }
                }
                else
                {
                    if (atStart && next == '?')
                    {
                        isQuery = true;
                    }
                    else if (atStart && next == '>')
                    {
                        isSend = true;
                    }
                    else if (atStart && next == '!')
                    {
                        isBang = true;
                    }
                    else if (next == ';')
                    {
                        if (currentParameter == -1)
                        {
                            throw new EscapeSequenceException("Invalid position for ';' in OSC", stream.Stacked);
                        }

                        Parameters.Add(currentParameter);
                        currentParameter = -1;
                    }
                    else if (char.IsDigit(next))
                    {
                        atStart = false;
                        if (currentParameter == -1)
                        {
                            currentParameter = Convert.ToInt32(next - '0');
                        }
                        else
                        {
                            currentParameter = (currentParameter * 10) + Convert.ToInt32(next - '0');
                        }
                    }
                    else if (next == '$' || next == '"' || next == ' ')
                    {
                        if (modifier.HasValue)
                        {
                            throw new EscapeSequenceException("There appears to be two modifiers in a row", stream.Stacked);
                        }

                        if (currentParameter != -1)
                        {
                            Parameters.Add(currentParameter);
                            currentParameter = -1;
                        }

                        modifier = next;
                    }
                    else
                    {
                        if (currentParameter != -1)
                        {
                            Parameters.Add(currentParameter);
                            currentParameter = -1;
                        }

                        command       += next;
                        readingCommand = true;
                    }
                }
            }

            stream.PopState();
            return(null);
        }