示例#1
0
        public static Tuple <TerminalVt100Statement, Vt100OutputText> Factory(
            InputByteArray InputArray)
        {
            TerminalVt100Statement stmt   = null;
            Vt100OutputText        otStmt = null;

            var          escapeCmd = InputArray.PeekNextByte().ToTelnetCommand();
            Vt100Command?cmd       = null;

            if ((escapeCmd != null) && (escapeCmd.Value == TelnetCommand.ESCAPE) &&
                (InputArray.RemainingLength > 1))
            {
                InputArray.AdvanceIndex(1);
                var rv  = InputArray.GetBytesUntilCode(new byte[] { 0x1b });
                var buf = rv.Item1;
                int rx  = 0;

                var stmtText = buf.ToAscii();

                stmt = Factory_FromStmtText(stmtText);

                // process any output text that follows the stmt text.
                {
                    int lx = stmt.StmtText.Length;
                    if (stmtText.Length > lx)
                    {
                        stmtText = stmtText.Substring(lx);
                        otStmt   = new Vt100OutputText(stmtText);
                    }
                }
            }

            return(new Tuple <TerminalVt100Statement, Vt100OutputText>(stmt, otStmt));
        }
示例#2
0
        private static TerminalVt100Statement Factory_FromStmtText(string StmtText)
        {
            Vt100Command?          cmd  = null;
            TerminalVt100Statement stmt = null;
            string text1  = "";
            string text2  = "";
            string text3  = "";
            string text4  = "";
            string text20 = "";
            int    rx     = 0;

            if (StmtText.Length >= 1)
            {
                text1 = StmtText.Substring(0, 1);
            }
            if (StmtText.Length >= 2)
            {
                text2 = StmtText.Substring(0, 2);
            }
            if (StmtText.Length >= 3)
            {
                text3 = StmtText.Substring(0, 3);
            }
            if (StmtText.Length >= 4)
            {
                text4 = StmtText.Substring(0, 4);
            }

            int lx = IntExt.Min(StmtText.Length, 20);

            text20 = StmtText.Substring(0, lx);

            if (text4 == "[?3l")
            {
                cmd  = Vt100Command.SetCol80;
                stmt = new TerminalVt100Statement(StmtText.Substring(0, 4), cmd);
            }
            else if (text4 == "[?7h")
            {
                cmd  = Vt100Command.SetAutoWrap;
                stmt = new TerminalVt100Statement(StmtText.Substring(0, 4), cmd);
            }

            else if (text3 == "[0m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.CharAttrOff);
            }

            else if (text3 == "[1m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.BoldModeOn);
            }

            else if (text3 == "[4m")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.UnderlineModeOn);
            }

            else if (text3 == "[2J")
            {
                stmt = new TerminalVt100Statement(text3, Vt100Command.ClearScreen);
            }

            else if ((text1 == "[") && (StmtText.Length >= 5) &&
                     ((rx = StmtText.MatchRegExp(REGEXPCURSORPOSITION)) > 0))
            {
                stmt = new Vt100PosCursor(StmtText.Substring(0, rx));
            }

            else
            {
                stmt = new TerminalVt100Statement(StmtText, null);
            }


            return(stmt);
        }