void GetCursorPosition ()
{
int row = 0, col = 0;
int b;
// First, get any data in the input buffer. Merely reduces the likelyhood of getting an error
int inqueue = ConsoleDriver.InternalKeyAvailable (0);
while (inqueue-- > 0){
b = stdin.Read ();
AddToBuffer (b);
}
// Then try to probe for the cursor coordinates
WriteConsole ("\x1b[6n");
if (ConsoleDriver.InternalKeyAvailable (1000) <= 0) {
noGetPosition = true;
return;
}
b = stdin.Read ();
while (b != '\x1b') {
AddToBuffer (b);
if (ConsoleDriver.InternalKeyAvailable (100) <= 0)
return;
b = stdin.Read ();
}
b = stdin.Read ();
if (b != '[') {
AddToBuffer ('\x1b');
AddToBuffer (b);
return;
}
b = stdin.Read ();
if (b != ';') {
row = b - '0';
b = stdin.Read ();
while ((b >= '0') && (b <= '9')) {
row = row * 10 + b - '0';
b = stdin.Read ();
}
// Row/col is 0 based
row --;
}
b = stdin.Read ();
if (b != 'R') {
col = b - '0';
b = stdin.Read ();
while ((b >= '0') && (b <= '9')) {
col = col * 10 + b - '0';
b = stdin.Read ();
}
// Row/col is 0 based
col --;
}
#if DEBUG
logger.WriteLine ("GetCursorPosition: {0}, {1}", col, row);
logger.Flush ();
#endif
cursorLeft = col;
cursorTop = row;
}