Beispiel #1
0
        void ProcessingCSI(List <string> Params, List <char> Intermediate, char FinalByte)
        {
            switch (FinalByte)
            {
            case 'R':       // CPR – Cursor Position Report
                break;

            case 'A':       // CUU – Cursor Up
                CursorUp(GetParam(Params, 0, 1));
                break;

            case 'B':       // CUD – Cursor Down
                CursorDown(GetParam(Params, 0, 1));
                break;

            case 'C':       // CUF – Cursor Forward
                CursorForward(GetParam(Params, 0, 1));
                break;

            case 'D':       // CUB - Cursor Backward
                CursorBackward(GetParam(Params, 0, 1));
                break;

            case 'H':       // CUP – Cursor Position
            case 'f':       // HVP – Horizontal and Vertical Position
                SetCursor(GetParam(Params, 1, 1), GetParam(Params, 0, 1));
                break;

            case 'J':       // ED – Erase In Display
                EraseInDisplay(GetParam(Params, 0));
                break;

            case 'K':       // EL – Erase In Line
                EraseInLine(GetParam(Params, 0));
                break;

            case 'h':     // SM – Set Mode
                if (Params.Count >= 1 && Params[0] == "?1")
                {
                    BaseTerminal.CursorKeys = TerminalEmulator.InputMode.Application;
                }
                else if (Params.Count >= 1 && Params[0] == "?12")
                {
                    // Blinking
                    break;
                }
                else if (Params.Count >= 1 && Params[0] == "?25")
                {
                    // Show Cursor
                    base.CursorVisible = true;
                }
                else if (Params.Count >= 1 && Params[0] == "?1049")
                {
                    BaseTerminal.SwitchToAlternateBuffer();
                }
                else
                {
                    break;
                }

                break;

            case 'l':     // RM – Reset Mode
                if (Params.Count >= 1 && Params[0] == "?1")
                {
                    BaseTerminal.CursorKeys = TerminalEmulator.InputMode.Normal;
                }
                else if (Params.Count >= 1 && Params[0] == "?12")
                {
                    // Don't blink
                    break;
                }
                else if (Params.Count >= 1 && Params[0] == "?25")
                {
                    // Hide Cursor
                    base.CursorVisible = false;
                }
                else if (Params.Count >= 1 && Params[0] == "?1049")
                {
                    BaseTerminal.SwitchToMainBuffer();
                }
                else
                {
                    break;
                }

                break;

            case 'm':     // SGR – Select Graphic Rendition
                for (int x = 0; x < Params.Count; x++)
                {
                    int Val = GetParam(Params, x);
                    if (Val == 0)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Foreground = ConsoleColor.Gray;
                        Temp.Background = ConsoleColor.Black;
                        this.Attribute  = Temp;
                    }

                    else if (Val == 1)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Value    |= CharacterAttributeEnum.FOREGROUND_INTENSITY;
                        this.Attribute = Temp;
                    }
                    else if (Val == 4)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Value    |= CharacterAttributeEnum.BACKGROUND_INTENSITY;
                        this.Attribute = Temp;
                    }
                    else if (Val == 24)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Value    &= ~CharacterAttributeEnum.BACKGROUND_INTENSITY;
                        this.Attribute = Temp;
                    }
                    else if (Val == 2 || Val == 22)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Value    &= ~CharacterAttributeEnum.FOREGROUND_INTENSITY;
                        this.Attribute = Temp;
                    }
                    else if (Val == 7 || Val == 27)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Foreground = this.Attribute.Background;
                        Temp.Background = this.Attribute.Foreground;
                        this.Attribute  = Temp;
                    }
                    else if (Val >= 30 && Val <= 39)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        if (Val == 38)
                        {
                            x++;
                            if (GetParam(Params, x) == 2)
                            {
                            }
                            else if (GetParam(Params, x) == 5)
                            {
                                x++;
                                Temp.Foreground = ConvertColor(GetParam(Params, x));
                            }
                        }
                        else if (Val == 39)
                        {
                            Temp.Foreground = ConsoleColor.Gray;
                        }
                        else
                        {
                            Temp.Foreground = ConvertColor(Val - 30);
                            if (this.Attribute.Foreground >= ConsoleColor.DarkGray)
                            {
                                Temp.Foreground += 8;
                            }
                        }
                        this.Attribute = Temp;
                    }
                    else if (Val >= 40 && Val <= 49)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        if (Val == 48)
                        {
                            x++;
                            if (GetParam(Params, x) == 2)
                            {
                            }
                            else if (GetParam(Params, x) == 5)
                            {
                                x++;
                                Temp.Background = ConvertColor(GetParam(Params, x));
                            }
                        }
                        else if (Val == 49)
                        {
                            Temp.Background = ConsoleColor.Black;
                        }
                        else
                        {
                            Temp.Background = ConvertColor(Val - 40);
                            if (this.Attribute.Background >= ConsoleColor.DarkGray)
                            {
                                Temp.Background += 8;
                            }
                        }
                        this.Attribute = Temp;
                    }
                    else if (Val >= 90 && Val <= 97)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Foreground = ConvertColor(Val - 90 + 8);
                        this.Attribute  = Temp;
                    }
                    else if (Val >= 100 && Val <= 107)
                    {
                        CharacterAttribute Temp = this.Attribute;
                        Temp.Background = ConvertColor(Val - 100 + 8);
                        this.Attribute  = Temp;
                    }
                    else
                    {
                        break;
                    }
                }

                break;

            case 'n':       // DSR – Device Status Report
            {
                string Response = "";
                switch (GetParam(Params, 0))
                {
                case 0:
                case 1:
                    break;

                case 5:
                    Response = string.Format("\x1b[{0};{1}R", this.CursorTop - this.WindowTop, this.CursorLeft - this.WindowLeft);
                    break;

                case 6:
                    Response = string.Format("\x1b[0n");
                    break;
                }

                BaseTerminal.SendResponse(Response);
            }
            break;

            case '`':
            {
                int Value = GetParam(Params, 0, 1);
                if (Value == 0)
                {
                    Value = 1;
                }

                if (Value > this.WindowWidth)
                {
                    Value = this.WindowWidth;
                }

                this.CursorLeft = this.WindowLeft + Value - 1;
            }
            break;

            case 'd':
            {
                int Value = GetParam(Params, 0, 1);
                if (Value == 0)
                {
                    Value = 1;
                }

                if (Value > this.WindowHeight)
                {
                    Value = this.WindowHeight;
                }

                this.CursorTop = this.WindowTop + Value - 1;
            }
            break;

            case 't':
                BaseTerminal.SetWindowAndBufferSize(GetParam(Params, 2, 0), GetParam(Params, 1, 0));
                break;

            default:
                break;
            }
        }