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); }
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; } }
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); }
internal static extern bool WriteConsoleOutput ( NakedWin32Handle consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion );
private static void WriteBufferLines(CHAR_INFO[] buffer, ref int top) { 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 writeRegion = new SMALL_RECT { Top = (short) top, Left = 0, Bottom = (short) (top + bufferLineCount - 1), Right = (short) bufferWidth }; NativeMethods.WriteConsoleOutput(handle, buffer, bufferSize, bufferCoord, ref writeRegion); }
public static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput, ref SMALL_RECT lpScrollRectangle, IntPtr lpClipRectangle, COORD dwDestinationOrigin, ref CHAR_INFO lpFill);
private static void ScrollBuffer(int lines) { var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); var scrollRectangle = new SMALL_RECT { Top = (short) lines, Left = 0, Bottom = (short) (lines + 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); }
private static void SetPrompt(string prompt) { if (string.IsNullOrEmpty(prompt)) return; var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); var lineCount = 1 + prompt.Count(c => c == '\n'); if (lineCount > 1) { var options = new SetPSReadlineOption {ExtraPromptLineCount = lineCount - 1}; PSConsoleReadLine.SetOptions(options); } int bufferWidth = Console.BufferWidth; var consoleBuffer = new CHAR_INFO[lineCount * bufferWidth]; int j = 0; for (int i = 0; i < prompt.Length; i++, j++) { if (prompt[i] == '\n') { for (; j % Console.BufferWidth != 0; j++) { consoleBuffer[j] = new CHAR_INFO(' ', Console.ForegroundColor, Console.BackgroundColor); } Console.CursorTop += 1; Console.CursorLeft = 0; j -= 1; // We don't actually write the newline } else { consoleBuffer[j] = new CHAR_INFO(prompt[i], Console.ForegroundColor, Console.BackgroundColor); Console.CursorLeft += 1; } } var bufferSize = new COORD { X = (short) bufferWidth, Y = (short) lineCount }; var bufferCoord = new COORD {X = 0, Y = 0}; var writeRegion = new SMALL_RECT { Top = 0, Left = 0, Bottom = (short) (lineCount - 1), Right = (short) bufferWidth }; NativeMethods.WriteConsoleOutput(handle, consoleBuffer, bufferSize, bufferCoord, ref writeRegion); }
private static CHAR_INFO[] ReadBufferLines(int top, int count) { var result = new CHAR_INFO[Console.BufferWidth * count]; var handle = NativeMethods.GetStdHandle((uint) StandardHandleId.Output); var readBufferSize = new COORD { X = (short)Console.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)(Console.BufferWidth - 1) }; NativeMethods.ReadConsoleOutput(handle, result, readBufferSize, readBufferCoord, ref readRegion); return result; }
public static extern bool WriteConsoleOutput(IntPtr consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
internal static extern bool SetConsoleScreenBufferSize(NakedWin32Handle consoleOutput, COORD size);
internal static extern bool SetConsoleCursorPosition(NakedWin32Handle consoleOutput, COORD cursorPosition);
internal static extern bool FillConsoleOutputCharacter ( NakedWin32Handle consoleOutput, Char character, DWORD length, COORD writeCoord, out DWORD numberOfCharsWritten );
internal static extern bool FillConsoleOutputAttribute ( NakedWin32Handle consoleOutput, WORD attribute, DWORD length, COORD writeCoord, out DWORD numberOfAttrsWritten );
/// <summary> /// Wrap Win32 ScrollConsoleScreenBuffer /// </summary> /// <param name="consoleHandle"> /// /// handle for the console where screen buffer is scrolled /// /// </param> /// <param name="scrollRectangle"> /// /// area to be scrolled /// /// </param> /// <param name="clipRectangle"> /// /// area to be updated after scrolling /// /// </param> /// <param name="destOrigin"> /// /// location to which the top left corner of scrollRectangle move /// /// </param> /// <param name="fill"> /// /// character and attribute to fill the area vacated by the scroll /// /// </param> /// <exception cref="HostException"> /// If Win32's ScrollConsoleScreenBuffer fails /// </exception> internal static void ScrollConsoleScreenBuffer ( ConsoleHandle consoleHandle, SMALL_RECT scrollRectangle, SMALL_RECT clipRectangle, COORD destOrigin, CHAR_INFO fill ) { Dbg.Assert(!consoleHandle.IsInvalid, "ConsoleHandle is not valid"); Dbg.Assert(!consoleHandle.IsClosed, "ConsoleHandle is closed"); bool result = NativeMethods.ScrollConsoleScreenBuffer( consoleHandle.DangerousGetHandle(), ref scrollRectangle, ref clipRectangle, destOrigin, ref fill); if (result == false) { int err = Marshal.GetLastWin32Error(); HostException e = CreateHostException(err, "ScrollConsoleScreenBuffer", ErrorCategory.WriteError, ConsoleControlStrings.ScrollConsoleScreenBufferExceptionTemplate); throw e; } }
public static extern bool ReadConsoleOutput(IntPtr consoleOutput, [Out] CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
internal static extern bool ReadConsoleOutput ( NakedWin32Handle consoleOutput, [Out] CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion );
internal static extern bool ScrollConsoleScreenBuffer ( NakedWin32Handle consoleOutput, ref SMALL_RECT scrollRectangle, ref SMALL_RECT clipRectangle, COORD destinationOrigin, ref CHAR_INFO fill );