diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index da6119dfb..7b7be7783 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -2722,10 +2722,21 @@ fhandler_pty_slave::fixup_after_fork (HANDLE parent) const char *term = getenv ("TERM"); if (term && strcmp (term, "dumb") && !strstr (term, "emacs")) { - /* FIXME: Clearing sequence may not be "^[[H^[[J" - depending on the terminal type. */ DWORD n; - WriteFile (get_output_handle_cyg (), "\033[H\033[J", 6, &n, NULL); + WriteFile (get_output_handle_cyg (), "\033[6n", 4, &n, NULL); + struct termios ti, ti_new; + tcgetattr (&ti); + ti_new = ti; + ti_new.c_lflag &= (~ICANON | ECHO); + tcsetattr (TCSANOW, &ti_new); + char buf[32]; + ReadFile (get_handle_cyg (), buf, sizeof(buf), &n, NULL); + tcsetattr (TCSANOW, &ti); + buf[n] = '\0'; + int rows, cols; + sscanf (buf, "\033[%d;%dR", &rows, &cols); + COORD dwCursorPosition = {(SHORT)(cols-1), (SHORT)(rows-1)}; + SetConsoleCursorPosition (get_output_handle (), dwCursorPosition); } get_ttyp ()->need_clear_screen = false; }