public BufferChar[] 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(ToBufferCharBuffer(result)); }
public CHAR_INFO ToCharInfo() { int fg = (int)ForegroundColor; int bg = (int)BackgroundColor; if (fg < 0 || fg > 0xf || bg < 0 || bg > 0xf) { throw new InvalidOperationException(); } if (Inverse) { // TODO: check $host.UI.SupportsVirtualTerminal and maybe set Inverse instead (it does look weird) fg = fg ^ 7; bg = bg ^ 7; } ushort attrs = (ushort)(fg | (bg << 4)); if (IsLeadByte) { attrs |= (ushort)CHAR_INFO_Attributes.COMMON_LVB_LEADING_BYTE; } if (IsTrailByte) { attrs |= (ushort)CHAR_INFO_Attributes.COMMON_LVB_TRAILING_BYTE; } CHAR_INFO result = new CHAR_INFO { UnicodeChar = UnicodeChar, Attributes = attrs, }; return(result); }
public static BufferChar FromCharInfo(CHAR_INFO charInfo) { BufferChar result = new BufferChar { UnicodeChar = (char)charInfo.UnicodeChar, ForegroundColor = (ConsoleColor)(charInfo.Attributes & 0xf), BackgroundColor = (ConsoleColor)((charInfo.Attributes & 0x00f0) >> 4), }; return(result); }
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 static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput, ref SMALL_RECT lpScrollRectangle, IntPtr lpClipRectangle, COORD dwDestinationOrigin, ref CHAR_INFO lpFill);
public static extern bool WriteConsoleOutput(IntPtr consoleOutput, CHAR_INFO[] buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
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; }
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 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) { WriteBufferLines(buffer, ref top, true); }
public static extern bool ScrollConsoleScreenBuffer(IntPtr hConsoleOutput, ref SMALL_RECT lpScrollRectangle, IntPtr lpClipRectangle, COORD dwDestinationOrigin, ref CHAR_INFO lpFill);
private BufferChar[] ToBufferCharBuffer(CHAR_INFO[] buffer) { var result = new BufferChar[buffer.Length]; for (int i = 0; i < buffer.Length; i++) { result[i] = BufferChar.FromCharInfo(buffer[i]); } return result; }
public static BufferChar FromCharInfo(CHAR_INFO charInfo) { BufferChar result = new BufferChar { UnicodeChar = (char) charInfo.UnicodeChar, ForegroundColor = (ConsoleColor)(charInfo.Attributes & 0xf), BackgroundColor = (ConsoleColor)((charInfo.Attributes & 0x00f0) >> 4), }; return result; }
public CHAR_INFO ToCharInfo() { int fg = (int) ForegroundColor; int bg = (int) BackgroundColor; if (fg < 0 || fg > 0xf || bg < 0 || bg > 0xf) throw new InvalidOperationException(); if (Inverse) { // TODO: check $host.UI.SupportsVirtualTerminal and maybe set Inverse instead (it does look weird) fg = fg ^ 7; bg = bg ^ 7; } ushort attrs = (ushort)(fg | (bg << 4)); if (IsLeadByte) attrs |= (ushort)CHAR_INFO_Attributes.COMMON_LVB_LEADING_BYTE; if (IsTrailByte) attrs |= (ushort)CHAR_INFO_Attributes.COMMON_LVB_TRAILING_BYTE; CHAR_INFO result = new CHAR_INFO { UnicodeChar = UnicodeChar, Attributes = attrs, }; return result; }