From: fujieda AT jaist DOT ac DOT jp (Kazuhiro Fujieda) Subject: another fhandler_console bug 22 Jan 1999 04:51:11 -0800 Message-ID: Mime-Version: 1.0 (generated by SEMI MIME-Edit 0.100 - "Shijima") Content-Type: text/plain; charset=US-ASCII To: cygwin32-developers AT cygnus DOT com When an arrow key is pushed repeatedly in bash executed in notty mode on Win9x, the escape sequence correspond to one arrow key is often interleaved with another one's. As a result, part of the sequence (`[D', `[C', and so on) is inserted into the command line instead of the cursor motion. The following patch can solve this problem. --- fhandler_console.cc- Mon Jan 18 15:54:02 1999 +++ fhandler_console.cc Wed Jan 20 20:48:59 1999 @@ -27,19 +27,20 @@ details. */ static void undo_input (HANDLE h, const char *ptr) { - INPUT_RECORD input_rec; DWORD n; + DWORD len = strlen (ptr) * 2; + INPUT_RECORD input_rec[len]; - memset (&input_rec, 0, sizeof (input_rec)); - input_rec.EventType = KEY_EVENT; - while (*ptr) - { - input_rec.Event.KeyEvent.uChar.AsciiChar = *ptr++; - input_rec.Event.KeyEvent.bKeyDown = 1; - WriteConsoleInput (h, &input_rec, 1, &n); - input_rec.Event.KeyEvent.bKeyDown = 0; - WriteConsoleInput (h, &input_rec, 1, &n); + memset (input_rec, 0, sizeof(INPUT_RECORD) * len); + for (DWORD i = 0; i < len; i += 2) + { + input_rec[i].EventType = KEY_EVENT; + input_rec[i].Event.KeyEvent.uChar.AsciiChar = *ptr++; + input_rec[i].Event.KeyEvent.bKeyDown = 1; + input_rec[i + 1] = input_rec[i]; + input_rec[i + 1].Event.KeyEvent.bKeyDown = 0; } + WriteConsoleInput (h, input_rec, len, &n); } static struct @@ -1208,23 +1209,19 @@ fhandler_console::read1 (char *buf, size const char *ptr = get_nonascii_key (input_rec); if (!ptr) continue; - while (*ptr && copied_chars < lenin) - buf[copied_chars++] = *ptr++; - if (*ptr) - undo_input (hndl, ptr); + undo_input (hndl, ptr); + continue; } else /* keep it */ { if (input_rec.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED) { - char tmp[2]; - tmp[0] = tolower (input_rec.Event.KeyEvent.uChar.AsciiChar); - tmp[1] = 0; - buf[copied_chars++] = '\033'; - if (copied_chars < lenin) - buf[copied_chars++] = tmp[0]; - else - undo_input (hndl, tmp); + char tmp[3]; + tmp[0] = '\033'; + tmp[1] = tolower (input_rec.Event.KeyEvent.uChar.AsciiChar); + tmp[2] = 0; + undo_input (hndl, tmp); + continue; } else buf[copied_chars++] = input_rec.Event.KeyEvent.uChar.AsciiChar; ____ | AIST Kazuhiro Fujieda | HOKURIKU School of Information Science o_/ 1990 Japan Advanced Institute of Science and Technology