AnsiCorrectPrintColor() public method

Forces the Background of the print appearance to be the darkened color and the foreground to be bright or not based on the Attribute_Bold property.
public AnsiCorrectPrintColor ( ) : void
return void
Beispiel #1
0
        /// <summary>
        /// Interprets an individual ansi code.
        /// </summary>
        /// <param name="code">The ANSI.SYS code to read.</param>
        public void AnsiInterpret(string code)
        {
            if (code[0] == (char)27 && code[1] == '[')
            {
                string   data   = code.Substring(2, code.Length - 3);
                string[] values = data.Split(';');

                switch (code[code.Length - 1])
                {
                case 'H':
                case 'h':
                    if (values.Length == 2)
                    {
                        if (values[1] == "")
                        {
                            _cursor.Position = new Point(0, _cursor.Position.Y);
                        }
                        else
                        {
                            _cursor.Position = new Point(Convert.ToInt32(values[1]) - 1, _cursor.Position.Y);
                        }

                        if (values[0] == "")
                        {
                            _cursor.Position = new Point(_cursor.Position.X, 0);
                        }
                        else
                        {
                            _cursor.Position = new Point(_cursor.Position.X, Convert.ToInt32(values[0]) - 1);
                        }
                    }
                    //else
                    //    System.Diagnostics.Debugger.Break();
                    break;

                case 'F':
                case 'f':
                    break;

                case 'A':
                case 'a':
                    if (data.Length == 0)
                    {
                        _cursor.Up(1);
                    }
                    else
                    {
                        _cursor.Up(Convert.ToInt32(data));
                    }
                    break;

                case 'B':
                case 'b':
                    if (data.Length == 0)
                    {
                        _cursor.Down(1);
                    }
                    else
                    {
                        _cursor.Down(Convert.ToInt32(data));
                    }
                    break;

                case 'C':
                case 'c':
                    if (data.Length == 0)
                    {
                        _cursor.Right(1);
                    }
                    else
                    {
                        _cursor.Right(Convert.ToInt32(data));
                    }
                    break;

                case 'D':
                case 'd':
                    if (data.Length == 0)
                    {
                        _cursor.Left(1);
                    }
                    else
                    {
                        _cursor.Left(Convert.ToInt32(data));
                    }
                    break;

                case 'J':
                case 'j':
                    if (data == "" || data == "0")
                    {
                        for (int i = _cursor.Position.X; i < _editor.TextSurface.Width; i++)
                        {
                            _editor.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "1")
                    {
                        for (int i = _cursor.Position.X; i >= 0; i--)
                        {
                            _editor.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "2")
                    {
                        _editor.Clear();
                        _cursor.Position = new Point(0, 0);
                    }
                    break;

                case 'K':
                case 'k':
                    if (data == "" || data == "0")
                    {
                        for (int i = _cursor.Position.X; i < _editor.TextSurface.Width; i++)
                        {
                            _editor.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "1")
                    {
                        for (int i = _cursor.Position.X; i >= 0; i--)
                        {
                            _editor.Clear(i, _cursor.Position.Y);
                        }
                    }

                    else if (data == "2")
                    {
                        for (int i = 0; i < _editor.TextSurface.Width; i++)
                        {
                            _editor.Clear(i, _cursor.Position.Y);
                        }
                    }
                    break;

                case 'S':
                case 's':
                    _storedCursorLocation = _cursor.Position;
                    break;

                case 'U':
                case 'u':
                    _cursor.Position = _storedCursorLocation;
                    break;

                case 'M':
                case 'm':

                    if (data == "")
                    {
                        _ansiState.AnsiResetVideo();
                    }

                    else
                    {
                        for (int i = 0; i < values.Length; i++)
                        {
                            int value = Convert.ToInt32(values[i]);
                            switch (value)
                            {
                            case 0:
                                _ansiState.AnsiResetVideo();
                                break;

                            case 1:
                                _ansiState.Bold = true;
                                _ansiState.AnsiCorrectPrintColor();
                                break;

                            case 5:
                                //Appearance.Effect = BlinkEffect;
                                break;

                            case 7:
                                Color tempFore = _ansiState.Foreground;
                                _ansiState.Foreground = Helpers.AnsiAdjustColor(_ansiState.Background, _ansiState.Bold);
                                _ansiState.Background = Helpers.AnsiJustNormalColor(tempFore);
                                break;

                            case 30:
                            case 31:
                            case 32:
                            case 33:
                            case 34:
                            case 35:
                            case 36:
                            case 37:
                                Helpers.AnsiConfigurePrintColor(false, value - 30, _ansiState);
                                break;

                            case 40:
                            case 41:
                            case 42:
                            case 43:
                            case 44:
                            case 45:
                            case 46:
                            case 47:
                                Helpers.AnsiConfigurePrintColor(true, value - 40, _ansiState);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    break;

                default:
                    System.Diagnostics.Debugger.Break();
                    break;
                }
            }
        }