Ejemplo n.º 1
0
        public void ScrollBuffer(int lines)
        {
            var handle = NativeMethods.GetStdHandle((uint)StandardHandleId.Output);

            var scrollRectangle = new SMALL_RECT
            {
                Top    = (short)lines,
                Left   = 0,
                Bottom = (short)(Console.BufferHeight - 1),
                Right  = (short)Console.BufferWidth
            };
            var destinationOrigin = new COORD {
                X = 0, Y = 0
            };
            var fillChar = new CHAR_INFO(' ', Console.ForegroundColor, Console.BackgroundColor);

            NativeMethods.ScrollConsoleScreenBuffer(handle, ref scrollRectangle, IntPtr.Zero, destinationOrigin, ref fillChar);
        }
Ejemplo n.º 2
0
        public void WriteBufferLines(BufferChar[] buffer, ref int top, bool ensureBottomLineVisible)
        {
            int bufferWidth     = Console.BufferWidth;
            int bufferLineCount = buffer.Length / bufferWidth;

            if ((top + bufferLineCount) > Console.BufferHeight)
            {
                var scrollCount = (top + bufferLineCount) - Console.BufferHeight;
                ScrollBuffer(scrollCount);
                top -= scrollCount;
            }

            var handle     = NativeMethods.GetStdHandle((uint)StandardHandleId.Output);
            var bufferSize = new COORD
            {
                X = (short)bufferWidth,
                Y = (short)bufferLineCount
            };
            var bufferCoord = new COORD {
                X = 0, Y = 0
            };
            var bottom      = top + bufferLineCount - 1;
            var writeRegion = new SMALL_RECT
            {
                Top    = (short)top,
                Left   = 0,
                Bottom = (short)bottom,
                Right  = (short)(bufferWidth - 1)
            };

            NativeMethods.WriteConsoleOutput(handle, ToCharInfoBuffer(buffer),
                                             bufferSize, bufferCoord, ref writeRegion);

            // Now make sure the bottom line is visible
            if (ensureBottomLineVisible &&
                (bottom >= (Console.WindowTop + Console.WindowHeight)))
            {
                Console.CursorTop = bottom;
            }
        }
Ejemplo n.º 3
0
        public CHAR_INFO[] ReadBufferLines(int top, int count)
        {
            var result = new CHAR_INFO[BufferWidth * count];
            var handle = NativeMethods.GetStdHandle((uint)StandardHandleId.Output);

            var readBufferSize = new COORD {
                X = (short)BufferWidth,
                Y = (short)count
            };
            var readBufferCoord = new COORD {
                X = 0, Y = 0
            };
            var readRegion = new SMALL_RECT
            {
                Top    = (short)top,
                Left   = 0,
                Bottom = (short)(top + count),
                Right  = (short)(BufferWidth - 1)
            };

            NativeMethods.ReadConsoleOutput(handle, result,
                                            readBufferSize, readBufferCoord, ref readRegion);
            return(result);
        }
Ejemplo n.º 4
0
 public static extern bool ReadConsoleOutput(IntPtr consoleOutput, [Out] CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
Ejemplo n.º 5
0
 public static extern bool WriteConsoleOutput(IntPtr consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
Ejemplo n.º 6
0
 public static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput,
                                                     ref SMALL_RECT lpScrollRectangle,
                                                     IntPtr lpClipRectangle,
                                                     COORD dwDestinationOrigin,
                                                     ref CHAR_INFO lpFill);
Ejemplo n.º 7
0
 public static extern bool ReadConsoleOutput(IntPtr consoleOutput, [Out] CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
Ejemplo n.º 8
0
        public CHAR_INFO[] ReadBufferLines(int top, int count)
        {
            var result = new CHAR_INFO[BufferWidth * count];
            var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output);

            var readBufferSize = new COORD {
                X = (short)BufferWidth,
                Y = (short)count};
            var readBufferCoord = new COORD {X = 0, Y = 0};
            var readRegion = new SMALL_RECT
            {
                Top = (short)top,
                Left = 0,
                Bottom = (short)(top + count),
                Right = (short)(BufferWidth - 1)
            };
            NativeMethods.ReadConsoleOutput(handle, result,
                readBufferSize, readBufferCoord, ref readRegion);
            return result;
        }
Ejemplo n.º 9
0
 public static extern bool WriteConsoleOutput(IntPtr consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
Ejemplo n.º 10
0
        public void ScrollBuffer(int lines)
        {
            var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output);

            var scrollRectangle = new SMALL_RECT
            {
                Top = (short) lines,
                Left = 0,
                Bottom = (short)(Console.BufferHeight - 1),
                Right = (short)Console.BufferWidth
            };
            var destinationOrigin = new COORD {X = 0, Y = 0};
            var fillChar = new CHAR_INFO(' ', Console.ForegroundColor, Console.BackgroundColor);
            NativeMethods.ScrollConsoleScreenBuffer(handle, ref scrollRectangle, IntPtr.Zero, destinationOrigin, ref fillChar);
        }
Ejemplo n.º 11
0
        public void WriteBufferLines(CHAR_INFO[] buffer, ref int top, bool ensureBottomLineVisible)
        {
            var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output);

            int bufferWidth = Console.BufferWidth;
            int bufferLineCount = buffer.Length / bufferWidth;
            if ((top + bufferLineCount) > Console.BufferHeight)
            {
                var scrollCount = (top + bufferLineCount) - Console.BufferHeight;
                ScrollBuffer(scrollCount);
                top -= scrollCount;
            }
            var bufferSize = new COORD
            {
                X = (short) bufferWidth,
                Y = (short) bufferLineCount
            };
            var bufferCoord = new COORD {X = 0, Y = 0};
            var bottom = top + bufferLineCount - 1;
            var writeRegion = new SMALL_RECT
            {
                Top = (short) top,
                Left = 0,
                Bottom = (short) bottom,
                Right = (short) (bufferWidth - 1)
            };
            NativeMethods.WriteConsoleOutput(handle, buffer,
                                             bufferSize, bufferCoord, ref writeRegion);

            // Now make sure the bottom line is visible
            if (ensureBottomLineVisible &&
                (bottom >= (Console.WindowTop + Console.WindowHeight)))
            {
                Console.CursorTop = bottom;
            }
        }
Ejemplo n.º 12
0
 public static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput,
     ref SMALL_RECT lpScrollRectangle,
     IntPtr lpClipRectangle,
     COORD dwDestinationOrigin,
     ref CHAR_INFO lpFill);