Example #1
0
        }         // proc Set

        public void Fill(int left, int top, int right, int bottom, char fill, ConsoleColor foreground = ConsoleColor.Gray, ConsoleColor background = ConsoleColor.Black)
        {
            var attr = ConsoleOutputBuffer.GetCharAttributes(foreground, background);

            for (var y = top; y <= bottom; y++)
            {
                for (var x = left; x <= right; x++)
                {
                    chars[y, x].Char       = fill;
                    chars[y, x].Attributes = attr;
                }
            }
        }         // proc Fill
Example #2
0
        public ConsoleOutputBuffer Copy()
        {
            GetConsoleScreenBufferInfoEx(DangerousGetHandle, out var bufferInfo);

            // create new console with same attributes
            var newConsolePtr = CreateConsoleScreenBufferCore();

            SetConsoleScreenBufferInfoEx(newConsolePtr, true, ref bufferInfo);

            var newConsole = new ConsoleOutputBuffer(new SafeFileHandle(newConsolePtr, true));

            // copy content
            newConsole.WriteBuffer(0, 0, ReadBuffer(0, 0, bufferInfo.dwSize.X - 1, bufferInfo.dwSize.Y - 1));

            return(newConsole);
        }         // proc Copy
Example #3
0
        }         // proc Fill

        public (int endLeft, int endTop) Write(int left, int top, string value, int?lineBreakTo = null, ConsoleColor foreground = ConsoleColor.Gray, ConsoleColor background = ConsoleColor.Black)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(left, top);
            }

            var attr = ConsoleOutputBuffer.GetCharAttributes(foreground, background);

            var y = top;
            var x = left;
            var l = value.Length;

            for (var i = 0; i < l; i++)
            {
                if (x >= Width)
                {
                    if (lineBreakTo.HasValue)
                    {
                        y++;
                        x = lineBreakTo.Value;
                    }
                    else
                    {
                        return(x, y);
                    }
                }
                if (y >= Height)
                {
                    return(x, y);
                }

                chars[y, x].Char       = value[i];
                chars[y, x].Attributes = attr;
                x++;
            }
            return(x, y);
        }         // proc Write