Exemple #1
0
        public override void DrawChar(char c, int x, int y, Color foreground, Color background)
        {
            if (x < 0 || y < 0)
            {
                return;
            }

            int index = (y * Width) + x;

            if (!(index >= 0 && index < Buffer.Length))
            {
                return;
            }

            sb.Clear();

            if (background.Transparent)
            {
                string str = Buffer[index];
                // get the 2nd occurence of ESC
                int i = str.IndexOf('\u001b', 2); // we can hard code the start index since the structure never changes

                // retrieve only the background (which is first)
                str = str.Substring(0, i);
                sb.Append(str);
            }
            else
            {
                sb.Append(background.AsAnsiBackground());
            }

            if (foreground.Transparent)
            {
                string str = Buffer[index];
                // get the 2nd occurence of ESC
                int i = str.IndexOf('\u001b', 2); // we can hard code the start index since the structure never changes

                // retrieve only the foreground (which is second)
                str = str.Substring(i, str.Length - 2); // -2 since the last element is the character
                sb.Append(str);
            }
            else
            {
                sb.Append(foreground.AsAnsiForeground());
            }

            sb.Append(c);

            Buffer[index] = sb.ToString();
        }
Exemple #2
0
        public override void Clear(Color color)
        {
            string str = color.AsAnsiBackground() + color.AsAnsiForeground() + " ";

            Array.Fill(Buffer, str);
        }