From c8e861357533943469f18e078308c77dede773b3 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 26 Jul 2016 08:31:57 -0700 Subject: Console: integrate end-of-line hack with cursor positioning. The previous work for simulating the beyond-right-edge of screen cursor position is incomplete without integrating this into the cursor positioning routines. By making the cursor routines aware of the eat_newline flag, we allow cursor movements to work correctly with regard to this simulated position. * winsup/cygwin/fhandler_console.cc (fhandler_console::cursor_set): If the X position is beyond the right edge of the screen, then set the cursor to the start of the following line, rather than clipping to the right edge, set the eat_newline flag, indicating that the the true position is actually one character beyond the previous line. In all other cases, clear the eat_newline flag. (fhandler_console::cursor_rel): Do not apply the delta vector to the raw Win32 cursor position; call cursor_get and apply it to the virtual cursor position which takes into account the eat_newline flag. (fhandler_console::cursor_get): Take into account the eat_newline flag. If it is set, then report an adjusted position that is one column beyond the end of the previous line. --- winsup/cygwin/fhandler_console.cc | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 0d3d234d9..5fe448051 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -1311,8 +1311,14 @@ fhandler_console::cursor_set (bool rel_to_top, int x, int y) else if (rel_to_top) y += con.b.srWindow.Top; - if (x > con.dwWinSize.X) - x = con.dwWinSize.X - 1; + con.eat_newline = false; + + if (x >= con.dwWinSize.X) + { + y++; + x = 0; + con.eat_newline = true; + } else if (x < 0) x = 0; @@ -1322,11 +1328,12 @@ fhandler_console::cursor_set (bool rel_to_top, int x, int y) } void __reg3 -fhandler_console::cursor_rel (int x, int y) +fhandler_console::cursor_rel (int xdelta, int ydelta) { - con.fillin (get_output_handle ()); - x += con.b.dwCursorPosition.X; - y += con.b.dwCursorPosition.Y; + int x, y; + cursor_get(&x, &y); + x += xdelta; + y += ydelta; cursor_set (false, x, y); } @@ -1334,8 +1341,16 @@ void __reg3 fhandler_console::cursor_get (int *x, int *y) { con.fillin (get_output_handle ()); - *y = con.b.dwCursorPosition.Y; - *x = con.b.dwCursorPosition.X; + if (!con.eat_newline) + { + *y = con.b.dwCursorPosition.Y; + *x = con.b.dwCursorPosition.X; + } + else + { + *y = con.b.dwCursorPosition.Y - 1; + *x = con.dwWinSize.X; + } } /* VT100 line drawing graphics mode maps `abcdefghijklmnopqrstuvwxyz{|}~ to -- cgit v1.2.3