static Crt() { CheckBreak = true; CheckEof = false; DirectVideo = true; LastMode = CO80; WindMax = 79 + (24 << 8); WindMin = 0; // Get the standard input/output handles if (OSUtils.IsWindows) { _StdInputHandle = NativeMethods.GetStdHandle(NativeMethods.STD_INPUT_HANDLE); _StdOutputHandle = NativeMethods.GetStdHandle(NativeMethods.STD_OUTPUT_HANDLE); } // Get the console screen buffer info and eliminate the scroll buffer if (OSUtils.IsWindows) { NativeMethods.CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo = new NativeMethods.CONSOLE_SCREEN_BUFFER_INFO(); NativeMethods.GetConsoleScreenBufferInfo(_StdOutputHandle, out ConsoleScreenBufferInfo); _ScreenSize.X = (short)(ConsoleScreenBufferInfo.srWindow.Right - ConsoleScreenBufferInfo.srWindow.Left + 1); _ScreenSize.Y = (short)(ConsoleScreenBufferInfo.srWindow.Bottom - ConsoleScreenBufferInfo.srWindow.Top + 1); NativeMethods.SetConsoleScreenBufferSize(_StdOutputHandle, _ScreenSize); } else { try { _ScreenSize.X = (short)Console.WindowWidth; _ScreenSize.Y = (short)Console.WindowHeight; Console.SetBufferSize(_ScreenSize.X, _ScreenSize.Y); } catch (NotImplementedException) { // Can't do that } } // Find the WindMin/WindMax records WindMin = 0; WindMax = (_ScreenSize.X - 1) | ((_ScreenSize.Y - 1) << 8); // Determine the starting text attribute _NormAttr = GetAttrAt(WhereX(), WhereY()); // Initialize the text attribute NormVideo(); }
/// <summary> /// Returns the CP's Y coordinate of the current cursor location. /// </summary> /// <remarks> /// WhereYA is now window-specific. /// </remarks> /// <returns>The 1-based row of the screen the cursor is currently in</returns> public static int WhereYA() { lock (_Lock) { if (OSUtils.IsWindows) { NativeMethods.CONSOLE_SCREEN_BUFFER_INFO CSBI = new NativeMethods.CONSOLE_SCREEN_BUFFER_INFO(); NativeMethods.GetConsoleScreenBufferInfo(_StdOutputHandle, out CSBI); return CSBI.dwCursorPosition.Y + 1; } else { try { return Console.CursorTop + 1; } catch (NotImplementedException) { // Can't do that return 1; } } } }