示例#1
0
        public void Buffer_Scroll_Test()
        {
            var process = new Process { StartInfo = { FileName = "cmd.exe" } };
            process.Start();

            AttachConsole(process.Id);
            var buffer = JConsole.GetActiveScreenBuffer();

            Thread.Sleep(1000);

            var chars = new ConsoleCharInfo[300, 120];
            buffer.ReadBlock(chars, 0, 0, 0, 0, 120, 299);

            //            for (int i = 0; i < 500; i++)
            //            {
            //                var chars = new ConsoleCharInfo[1, 120];
            //                buffer.ReadBlock(chars, 0, 0, 0, i, 120, i);
            //            }

            //            for (int i = 0; i < 25; i++)
            //            {
            //                var events = new List<EventArgs>();
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'd' });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'd' });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'i' });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'i' });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'r' });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'r' });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = (char)13 });
            //                events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = (char)13 });
            //
            //                var inputBuffer = JConsole.GetInputBuffer();
            //                inputBuffer.WindowInput = true;
            //                inputBuffer.WriteEvents(events, events.Count());
            //
            //                Thread.Sleep(500);
            //                buffer.WriteLine(buffer.WindowTop.ToString());
            //
            //            }
        }
示例#2
0
        /// <summary>
        /// Copies a specified source area of the screen buffer to a specified destination area.
        /// Vacated character cells are filled with the specified character and color attributes.
        /// </summary>
        /// <param name="sourceLeft">Column position of the source area's top-left corner.</param>
        /// <param name="sourceTop">Row position of the source arean't top-left corner.</param>
        /// <param name="sourceWidth">Width, in character columns, of the source area.</param>
        /// <param name="sourceHeight">Height, in character rows, of the source area.</param>
        /// <param name="targetLeft">Column position of the target's top-left corner.</param>
        /// <param name="targetTop">Row position of the target's top-left corner.</param>
        /// <param name="sourceChar">Character with which to fill vacated character positions.</param>
        /// <param name="sourceForeColor">Foreground color to use for filling.</param>
        /// <param name="sourceBackColor">Background color to use for filling.</param>
        public void MoveBufferArea(
            int sourceLeft,
            int sourceTop,
            int sourceWidth,
            int sourceHeight,
            int targetLeft,
            int targetTop,
            char sourceChar,
            ConsoleColor sourceForeColor,
            ConsoleColor sourceBackColor
            )
        {
            SmallRect sourceRect = new SmallRect((short)sourceLeft, (short)sourceTop,
                                                 (short)(sourceLeft + sourceWidth - 1), (short)(sourceTop + sourceHeight - 1));
            Coord           dest = new Coord((short)targetLeft, (short)targetTop);
            ConsoleCharInfo cci  = new ConsoleCharInfo(sourceChar, new ConsoleCharAttribute(sourceForeColor, sourceBackColor));

            if (!WinCon.ScrollConsoleScreenBuffer(_handle, sourceRect, null, dest, ref cci))
            {
                throw new IOException("Error scrolling screen buffer", Marshal.GetLastWin32Error());
            }
        }
示例#3
0
        private static string GetContent(ConsoleCharInfo[,] block, int width, int height)
        {
            var builder = new StringBuilder(width + 2);
            builder.Append(Environment.NewLine);
            for (int i = 0; i < width; i++)
            {
                builder.Append(block[0, i].UnicodeChar);
            }

            return builder.ToString();
        }
示例#4
0
        private string Read(int lineNumber, int width)
        {
            if (width <= 0)
                return string.Empty;

            var buffer = new ConsoleCharInfo[1, width];
            _outputBuffer.ReadBlock(buffer, 0, 0, 0, lineNumber, width-1, lineNumber);

            return GetContent(buffer, width, 1);
        }
 /// <summary>
 /// Writes character and attribute information to a rectangular portion of the screen buffer.
 /// </summary>
 /// <param name="buff">The array that contains characters and attributes to be written.</param>
 /// <param name="buffX">Column position of the first character to be written from the array.</param>
 /// <param name="buffY">Row position of the first character to be written from the array.</param>
 /// <param name="left">Column position of the top-left corner of the screen buffer area where characters are to be written.</param>
 /// <param name="top">Row position of the top-left corner of the screen buffer area where characters are to be written.</param>
 /// <param name="right">Column position of the bottom-right corner of the screen buffer area where characters are to be written.</param>
 /// <param name="bottom">Row position of the bottom-right corner of the screen buffer area where characters are to be written.</param>
 public void WriteBlock(ConsoleCharInfo[,] buff, int buffX, int buffY, int left, int top, int right, int bottom)
 {
     if (disposed)
     {
         throw new ObjectDisposedException(this.ToString());
     }
     Coord bufferSize = new Coord((short)buff.GetLength(1), (short)buff.GetLength(0));
     Coord bufferPos = new Coord((short)buffX, (short)buffY);
     SmallRect writeRegion = new SmallRect((short)left, (short)top, (short)right, (short)bottom);
     if (!WinCon.WriteConsoleOutput(_handle, buff, bufferSize, bufferPos, writeRegion))
     {
         throw new IOException("Write error.", Marshal.GetLastWin32Error());
     }
 }
 /// <summary>
 /// Copies a specified source area of the screen buffer to a specified destination area.
 /// Vacated character cells are filled with the specified character and color attributes.
 /// </summary>
 /// <param name="sourceLeft">Column position of the source area's top-left corner.</param>
 /// <param name="sourceTop">Row position of the source arean't top-left corner.</param>
 /// <param name="sourceWidth">Width, in character columns, of the source area.</param>
 /// <param name="sourceHeight">Height, in character rows, of the source area.</param>
 /// <param name="targetLeft">Column position of the target's top-left corner.</param>
 /// <param name="targetTop">Row position of the target's top-left corner.</param>
 /// <param name="sourceChar">Character with which to fill vacated character positions.</param>
 /// <param name="sourceForeColor">Foreground color to use for filling.</param>
 /// <param name="sourceBackColor">Background color to use for filling.</param>
 public void MoveBufferArea(
     int sourceLeft,
     int sourceTop,
     int sourceWidth,
     int sourceHeight,
     int targetLeft,
     int targetTop,
     char sourceChar,
     ConsoleColor sourceForeColor,
     ConsoleColor sourceBackColor
     )
 {
     SmallRect sourceRect = new SmallRect((short)sourceLeft, (short)sourceTop,
         (short)(sourceLeft + sourceWidth - 1), (short)(sourceTop + sourceHeight - 1));
     Coord dest = new Coord((short)targetLeft, (short)targetTop);
     ConsoleCharInfo cci = new ConsoleCharInfo(sourceChar, new ConsoleCharAttribute(sourceForeColor, sourceBackColor));
     if (!WinCon.ScrollConsoleScreenBuffer(_handle, sourceRect, null, dest, ref cci))
     {
         throw new IOException("Error scrolling screen buffer", Marshal.GetLastWin32Error());
     }
 }
示例#7
0
        public void Write_To_Buffer()
        {
            var process = new Process { StartInfo = { FileName = "cmd.exe" } };
            process.Start();

            AttachConsole(process.Id);
            var buffer = JConsole.GetActiveScreenBuffer();
            buffer.WriteLine("dir");

            var block = new ConsoleCharInfo[buffer.Height,buffer.Width];
            buffer.ReadBlock(block, 0, 0, 0, 0, buffer.Height, buffer.Width);
        }
示例#8
0
 public static extern bool ScrollConsoleScreenBuffer(
     IntPtr hConsoleOutput,
     [In][MarshalAs(UnmanagedType.LPStruct)] SmallRect lpScrollRectangle,
     [In][MarshalAs(UnmanagedType.LPStruct)] SmallRect lpClipRectangle,
     Coord dwDestinationOrigin,
     ref ConsoleCharInfo lpFill);
示例#9
0
 public static extern bool ScrollConsoleScreenBuffer(
     IntPtr hConsoleOutput,
     [In][MarshalAs(UnmanagedType.LPStruct)]SmallRect lpScrollRectangle,
     [In][MarshalAs(UnmanagedType.LPStruct)]SmallRect lpClipRectangle,
     Coord dwDestinationOrigin,
     ref ConsoleCharInfo lpFill);