public void SetBufferSize(int width, int height)
        {
            ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo();

            GetConsoleScreenBufferInfo(outputHandle, out info);

            if (width - 1 > info.Window.Right)
            {
                throw new ArgumentOutOfRangeException("width");
            }

            if (height - 1 > info.Window.Bottom)
            {
                throw new ArgumentOutOfRangeException("height");
            }

            Coord coord = new Coord(width, height);

            if (!SetConsoleScreenBufferSize(outputHandle, coord))
            {
                throw new ArgumentOutOfRangeException("height/width", "Cannot be smaller than the window size.");
            }
        }
        public WindowsConsoleDriver()
        {
            outputHandle = GetStdHandle(Handles.STD_OUTPUT);
            errorHandle  = GetStdHandle(Handles.STD_ERROR);
            inputHandle  = GetStdHandle(Handles.STD_INPUT);
            ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo();

            GetConsoleScreenBufferInfo(outputHandle, out info);
            defaultAttribute = info.Attribute; // Not sure about this...

            //logWriter = new StreamWriter(@"D:\temp\unity.log", true) {AutoFlush = true};
            //logWriter.WriteLine("Windows Console Driver Startup");

            //int mode = -1;
            //if (!GetConsoleMode(inputHandle, out mode))
            //    throw new Exception("Failed in GetConsoleMode: " + Marshal.GetLastWin32Error());
            //   logWriter.WriteLine("ConsoleMode: Input  {0}",mode);
            //   if (!GetConsoleMode(outputHandle, out mode))
            //       throw new Exception("Failed in GetConsoleMode: " + Marshal.GetLastWin32Error());
            //   logWriter.WriteLine("ConsoleMode: Output {0}", mode);
            //   if (!GetConsoleMode(errorHandle, out mode))
            //       throw new Exception("Failed in GetConsoleMode: " + Marshal.GetLastWin32Error());
            //   logWriter.WriteLine("ConsoleMode: Error  {0}", mode);
        }
 extern static bool GetConsoleScreenBufferInfo(IntPtr handle, out ConsoleScreenBufferInfo info);