diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f0715cc8b..173caf081 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,24 @@ +2014-03-09 Christopher Faylor + + * fhandler.h (fhandler_console::dwBufferSize): Delete. + (fhandler_console::dwCursorPosition): Ditto. + (fhandler_console::wAttributes): Ditto. + (fhandler_console::b): New field encompassing previously disparate + screen buffer info. + (fhandler_console::save_bufsize): Rename from savebufsiz + (fhandler_console::save_buf): Rename sfrom savebuf. + (fhandler_console::save_cursor): New field. + (fhandler_console::save_restore): New function. + (fhandler_console::con): Rename from dev_state. + (fhandler_console::focus_aware): Accommodate name change. + * fhandler_console.cc: Use 'b' field of dev_console throughout instead + of disparate names. Accommodate dev_state -> con rename. + (dev_state:save_restore): New function. Attempt to save the entire + screen buffer rather than just the visible part. Clear the buffer when + saving, like Linux. + (fhandler_console::char_command): Use con.save_restore() for + Save/restore screen sequence. + 2014-03-09 Christopher Faylor * sigproc.cc (_cygtls::remove_wq): Reset thread_ev inside of lock. Set diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index f908ddb50..6d9a1b7e7 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1287,23 +1287,22 @@ class dev_console /* saved cursor coordinates */ int savex, savey; - /* saved screen */ - COORD savebufsiz; - PCHAR_INFO savebuf; struct { - short Top, Bottom; + short Top; + short Bottom; } scroll_region; - SHORT winTop; - SHORT winBottom; + CONSOLE_SCREEN_BUFFER_INFOEX b; COORD dwWinSize; - COORD dwBufferSize; - COORD dwCursorPosition; - WORD wAttributes; COORD dwEnd; + /* saved screen */ + COORD save_bufsize; + PCHAR_INFO save_buf; + COORD save_cursor; + COORD dwLastCursorPosition; COORD dwMousePosition; /* scroll-adjusted coord of mouse event */ COORD dwLastMousePosition; /* scroll-adjusted coord of previous mouse event */ @@ -1330,6 +1329,7 @@ class dev_console bool __reg3 scroll_window (HANDLE, int, int, int, int); void __reg3 scroll_buffer (HANDLE, int, int, int, int, int, int); void __reg3 clear_screen (HANDLE, int, int, int, int); + void __reg3 save_restore (HANDLE, char); friend class fhandler_console; }; @@ -1341,7 +1341,7 @@ public: struct console_state { tty_min tty_min_state; - dev_console dev_state; + dev_console con; }; private: static const unsigned MAX_WRITE_CHARS; @@ -1413,7 +1413,7 @@ private: int ioctl (unsigned int cmd, void *); int init (HANDLE, DWORD, mode_t); bool mouse_aware (MOUSE_EVENT_RECORD& mouse_event); - bool focus_aware () {return shared_console_info->dev_state.use_focus;} + bool focus_aware () {return shared_console_info->con.use_focus;} select_record *select_read (select_stuff *); select_record *select_write (select_stuff *); diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index a1b1752c8..10cbd9763 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -42,9 +42,9 @@ details. */ #define ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) #define CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) -#define dev_state (shared_console_info->dev_state) -#define srTop (dev_state.winTop + dev_state.scroll_region.Top) -#define srBottom ((dev_state.scroll_region.Bottom < 0) ? dev_state.winBottom : dev_state.winTop + dev_state.scroll_region.Bottom) +#define con (shared_console_info->con) +#define srTop (con.b.srWindow.Top + con.scroll_region.Top) +#define srBottom ((con.scroll_region.Bottom < 0) ? con.b.srWindow.Bottom : con.b.srWindow.Top + con.scroll_region.Bottom) const char *get_nonascii_key (INPUT_RECORD&, char *); @@ -172,16 +172,16 @@ fhandler_console::setup () { if (set_unit ()) { - dev_state.scroll_region.Bottom = -1; - dev_state.dwLastCursorPosition.X = -1; - dev_state.dwLastCursorPosition.Y = -1; - dev_state.dwLastMousePosition.X = -1; - dev_state.dwLastMousePosition.Y = -1; - dev_state.dwLastButtonState = 0; /* none pressed */ - dev_state.last_button_code = 3; /* released */ - dev_state.underline_color = FOREGROUND_GREEN | FOREGROUND_BLUE; - dev_state.dim_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; - dev_state.meta_mask = LEFT_ALT_PRESSED; + con.scroll_region.Bottom = -1; + con.dwLastCursorPosition.X = -1; + con.dwLastCursorPosition.Y = -1; + con.dwLastMousePosition.X = -1; + con.dwLastMousePosition.Y = -1; + con.dwLastButtonState = 0; /* none pressed */ + con.last_button_code = 3; /* released */ + con.underline_color = FOREGROUND_GREEN | FOREGROUND_BLUE; + con.dim_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + con.meta_mask = LEFT_ALT_PRESSED; /* Set the mask that determines if an input keystroke is modified by META. We set this based on the keyboard layout language loaded for the current thread. The left key always generates @@ -192,9 +192,9 @@ fhandler_console::setup () these keyboards right (called AltGr) is used to produce the shell symbols and should not be interpreted as META. */ if (PRIMARYLANGID (LOWORD (GetKeyboardLayout (0))) == LANG_ENGLISH) - dev_state.meta_mask |= RIGHT_ALT_PRESSED; - dev_state.set_default_attr (); - dev_state.backspace_keycode = CERASE; + con.meta_mask |= RIGHT_ALT_PRESSED; + con.set_default_attr (); + con.backspace_keycode = CERASE; shared_console_info->tty_min_state.is_console = true; } } @@ -238,39 +238,35 @@ dev_console::str_to_con (mbtowc_p f_mbtowc, const char *charset, bool fhandler_console::set_raw_win32_keyboard_mode (bool new_mode) { - bool old_mode = dev_state.raw_win32_keyboard_mode; - dev_state.raw_win32_keyboard_mode = new_mode; - syscall_printf ("raw keyboard mode %sabled", dev_state.raw_win32_keyboard_mode ? "en" : "dis"); + bool old_mode = con.raw_win32_keyboard_mode; + con.raw_win32_keyboard_mode = new_mode; + syscall_printf ("raw keyboard mode %sabled", con.raw_win32_keyboard_mode ? "en" : "dis"); return old_mode; }; void fhandler_console::set_cursor_maybe () { - CONSOLE_SCREEN_BUFFER_INFO now; - - if (!GetConsoleScreenBufferInfo (get_output_handle (), &now)) - return; - - if (dev_state.dwLastCursorPosition.X != now.dwCursorPosition.X || - dev_state.dwLastCursorPosition.Y != now.dwCursorPosition.Y) + con.fillin (get_output_handle ()); + if (con.dwLastCursorPosition.X != con.b.dwCursorPosition.X || + con.dwLastCursorPosition.Y != con.b.dwCursorPosition.Y) { - SetConsoleCursorPosition (get_output_handle (), now.dwCursorPosition); - dev_state.dwLastCursorPosition = now.dwCursorPosition; + SetConsoleCursorPosition (get_output_handle (), con.b.dwCursorPosition); + con.dwLastCursorPosition = con.b.dwCursorPosition; } } void fhandler_console::send_winch_maybe () { - SHORT y = dev_state.dwWinSize.Y; - SHORT x = dev_state.dwWinSize.X; - dev_state.fillin (get_output_handle ()); + SHORT y = con.dwWinSize.Y; + SHORT x = con.dwWinSize.X; + con.fillin (get_output_handle ()); - if (y != dev_state.dwWinSize.Y || x != dev_state.dwWinSize.X) + if (y != con.dwWinSize.Y || x != con.dwWinSize.X) { - dev_state.scroll_region.Top = 0; - dev_state.scroll_region.Bottom = -1; + con.scroll_region.Top = 0; + con.scroll_region.Bottom = -1; get_ttyp ()->kill_pgrp (SIGWINCH); } } @@ -279,7 +275,7 @@ fhandler_console::send_winch_maybe () bool fhandler_console::mouse_aware (MOUSE_EVENT_RECORD& mouse_event) { - if (!dev_state.use_mouse) + if (!con.use_mouse) return 0; /* Adjust mouse position by window scroll buffer offset @@ -289,17 +285,17 @@ fhandler_console::mouse_aware (MOUSE_EVENT_RECORD& mouse_event) /* Cannot adjust position by window scroll buffer offset */ return 0; - dev_state.dwMousePosition.X = mouse_event.dwMousePosition.X - now.srWindow.Left; - dev_state.dwMousePosition.Y = mouse_event.dwMousePosition.Y - now.srWindow.Top; + con.dwMousePosition.X = mouse_event.dwMousePosition.X - now.srWindow.Left; + con.dwMousePosition.Y = mouse_event.dwMousePosition.Y - now.srWindow.Top; return ((mouse_event.dwEventFlags == 0 || mouse_event.dwEventFlags == DOUBLE_CLICK) - && mouse_event.dwButtonState != dev_state.dwLastButtonState) + && mouse_event.dwButtonState != con.dwLastButtonState) || mouse_event.dwEventFlags == MOUSE_WHEELED || (mouse_event.dwEventFlags == MOUSE_MOVED - && (dev_state.dwMousePosition.X != dev_state.dwLastMousePosition.X - || dev_state.dwMousePosition.Y != dev_state.dwLastMousePosition.Y) - && ((dev_state.use_mouse >= 2 && mouse_event.dwButtonState) - || dev_state.use_mouse >= 3)); + && (con.dwMousePosition.X != con.dwLastMousePosition.X + || con.dwMousePosition.Y != con.dwLastMousePosition.Y) + && ((con.use_mouse >= 2 && mouse_event.dwButtonState) + || con.use_mouse >= 3)); } void __reg3 @@ -371,7 +367,7 @@ fhandler_console::read (void *pv, size_t& buflen) #define virtual_key_code (input_rec.Event.KeyEvent.wVirtualKeyCode) #define control_key_state (input_rec.Event.KeyEvent.dwControlKeyState) - dev_state.nModifiers = 0; + con.nModifiers = 0; #ifdef DEBUGGING /* allow manual switching to/from raw mode via ctrl-alt-scrolllock */ @@ -380,12 +376,12 @@ fhandler_console::read (void *pv, size_t& buflen) ((control_key_state & (LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) == (LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) ) { - set_raw_win32_keyboard_mode (!dev_state.raw_win32_keyboard_mode); + set_raw_win32_keyboard_mode (!con.raw_win32_keyboard_mode); continue; } #endif - if (dev_state.raw_win32_keyboard_mode) + if (con.raw_win32_keyboard_mode) { __small_sprintf (tmp, "\033{%u;%u;%u;%u;%u;%luK", input_rec.Event.KeyEvent.bKeyDown, @@ -418,22 +414,22 @@ fhandler_console::read (void *pv, size_t& buflen) continue; if (control_key_state & SHIFT_PRESSED) - dev_state.nModifiers |= 1; + con.nModifiers |= 1; if (control_key_state & RIGHT_ALT_PRESSED) - dev_state.nModifiers |= 2; + con.nModifiers |= 2; if (control_key_state & CTRL_PRESSED) - dev_state.nModifiers |= 4; + con.nModifiers |= 4; if (control_key_state & LEFT_ALT_PRESSED) - dev_state.nModifiers |= 8; + con.nModifiers |= 8; /* Allow Backspace to emit ^? and escape sequences. */ if (input_rec.Event.KeyEvent.wVirtualKeyCode == VK_BACK) { - char c = dev_state.backspace_keycode; + char c = con.backspace_keycode; nread = 0; if (control_key_state & ALT_PRESSED) { - if (dev_state.metabit) + if (con.metabit) c |= 0x80; else tmp[nread++] = '\e'; @@ -454,14 +450,14 @@ fhandler_console::read (void *pv, size_t& buflen) toadd = get_nonascii_key (input_rec, tmp); if (!toadd) { - dev_state.nModifiers = 0; + con.nModifiers = 0; continue; } nread = strlen (toadd); } else { - nread = dev_state.con_to_str (tmp + 1, 59, wch); + nread = con.con_to_str (tmp + 1, 59, wch); /* Determine if the keystroke is modified by META. The tricky part is to distinguish whether the right Alt key should be recognized as Alt, or as AltGr. */ @@ -485,7 +481,7 @@ fhandler_console::read (void *pv, size_t& buflen) else toadd = tmp + 1; } - else if (dev_state.metabit) + else if (con.metabit) { tmp[1] |= 0x80; toadd = tmp + 1; @@ -496,7 +492,7 @@ fhandler_console::read (void *pv, size_t& buflen) tmp[1] = cyg_tolower (tmp[1]); toadd = tmp; nread++; - dev_state.nModifiers &= ~4; + con.nModifiers &= ~4; } } #undef ich @@ -550,34 +546,34 @@ fhandler_console::read (void *pv, size_t& buflen) if (mouse_event.dwEventFlags == MOUSE_MOVED) { - b = dev_state.last_button_code; + b = con.last_button_code; } - else if (mouse_event.dwButtonState < dev_state.dwLastButtonState && !dev_state.ext_mouse_mode6) + else if (mouse_event.dwButtonState < con.dwLastButtonState && !con.ext_mouse_mode6) { b = 3; strcpy (sz, "btn up"); } - else if ((mouse_event.dwButtonState & 1) != (dev_state.dwLastButtonState & 1)) + else if ((mouse_event.dwButtonState & 1) != (con.dwLastButtonState & 1)) { b = 0; strcpy (sz, "btn1 down"); } - else if ((mouse_event.dwButtonState & 2) != (dev_state.dwLastButtonState & 2)) + else if ((mouse_event.dwButtonState & 2) != (con.dwLastButtonState & 2)) { b = 2; strcpy (sz, "btn2 down"); } - else if ((mouse_event.dwButtonState & 4) != (dev_state.dwLastButtonState & 4)) + else if ((mouse_event.dwButtonState & 4) != (con.dwLastButtonState & 4)) { b = 1; strcpy (sz, "btn3 down"); } - if (dev_state.ext_mouse_mode6 /* distinguish release */ - && mouse_event.dwButtonState < dev_state.dwLastButtonState) + if (con.ext_mouse_mode6 /* distinguish release */ + && mouse_event.dwButtonState < con.dwLastButtonState) mode6_term = 'm'; - dev_state.last_button_code = b; + con.last_button_code = b; if (mouse_event.dwEventFlags == MOUSE_MOVED) { @@ -587,46 +583,46 @@ fhandler_console::read (void *pv, size_t& buflen) else { /* Remember the modified button state */ - dev_state.dwLastButtonState = mouse_event.dwButtonState; + con.dwLastButtonState = mouse_event.dwButtonState; } } /* Remember mouse position */ - dev_state.dwLastMousePosition.X = dev_state.dwMousePosition.X; - dev_state.dwLastMousePosition.Y = dev_state.dwMousePosition.Y; + con.dwLastMousePosition.X = con.dwMousePosition.X; + con.dwLastMousePosition.Y = con.dwMousePosition.Y; /* Remember the modifiers */ - dev_state.nModifiers = 0; + con.nModifiers = 0; if (mouse_event.dwControlKeyState & SHIFT_PRESSED) - dev_state.nModifiers |= 0x4; + con.nModifiers |= 0x4; if (mouse_event.dwControlKeyState & ALT_PRESSED) - dev_state.nModifiers |= 0x8; + con.nModifiers |= 0x8; if (mouse_event.dwControlKeyState & CTRL_PRESSED) - dev_state.nModifiers |= 0x10; + con.nModifiers |= 0x10; /* Indicate the modifiers */ - b |= dev_state.nModifiers; + b |= con.nModifiers; /* We can now create the code. */ - if (dev_state.ext_mouse_mode6) + if (con.ext_mouse_mode6) { __small_sprintf (tmp, "\033[<%d;%d;%d%c", b, - dev_state.dwMousePosition.X + 1, - dev_state.dwMousePosition.Y + 1, + con.dwMousePosition.X + 1, + con.dwMousePosition.Y + 1, mode6_term); nread = strlen (tmp); } - else if (dev_state.ext_mouse_mode15) + else if (con.ext_mouse_mode15) { __small_sprintf (tmp, "\033[%d;%d;%dM", b + 32, - dev_state.dwMousePosition.X + 1, - dev_state.dwMousePosition.Y + 1); + con.dwMousePosition.X + 1, + con.dwMousePosition.Y + 1); nread = strlen (tmp); } - else if (dev_state.ext_mouse_mode5) + else if (con.ext_mouse_mode5) { - unsigned int xcode = dev_state.dwMousePosition.X + ' ' + 1; - unsigned int ycode = dev_state.dwMousePosition.Y + ' ' + 1; + unsigned int xcode = con.dwMousePosition.X + ' ' + 1; + unsigned int ycode = con.dwMousePosition.Y + ' ' + 1; __small_sprintf (tmp, "\033[M%c", b + ' '); nread = 4; @@ -653,8 +649,8 @@ fhandler_console::read (void *pv, size_t& buflen) } else { - unsigned int xcode = dev_state.dwMousePosition.X + ' ' + 1; - unsigned int ycode = dev_state.dwMousePosition.Y + ' ' + 1; + unsigned int xcode = con.dwMousePosition.X + ' ' + 1; + unsigned int ycode = con.dwMousePosition.Y + ' ' + 1; if (xcode >= 256) xcode = 0; if (ycode >= 256) @@ -664,8 +660,8 @@ fhandler_console::read (void *pv, size_t& buflen) nread = 6; /* tmp may contain NUL bytes */ } syscall_printf ("mouse: %s at (%d,%d)", sz, - dev_state.dwMousePosition.X, - dev_state.dwMousePosition.Y); + con.dwMousePosition.X, + con.dwMousePosition.Y); toadd = tmp; } @@ -673,7 +669,7 @@ fhandler_console::read (void *pv, size_t& buflen) break; case FOCUS_EVENT: - if (dev_state.use_focus) + if (con.use_focus) { if (input_rec.Event.FocusEvent.bSetFocus) __small_sprintf (tmp, "\033[I"); @@ -736,28 +732,25 @@ bool dev_console::fillin (HANDLE h) { bool ret; - CONSOLE_SCREEN_BUFFER_INFO linfo; - if ((ret = GetConsoleScreenBufferInfo (h, &linfo))) + b.cbSize = sizeof (b); + if ((ret = GetConsoleScreenBufferInfoEx (h, &b))) { - winTop = linfo.srWindow.Top; - winBottom = linfo.srWindow.Bottom; - dwWinSize.Y = 1 + linfo.srWindow.Bottom - linfo.srWindow.Top; - dwWinSize.X = 1 + linfo.srWindow.Right - linfo.srWindow.Left; - if (dwBufferSize.Y != linfo.dwSize.Y || dwBufferSize.X != linfo.dwSize.X) + dwWinSize.Y = 1 + b.srWindow.Bottom - b.srWindow.Top; + dwWinSize.X = 1 + b.srWindow.Right - b.srWindow.Left; + if (b.dwSize.Y != b.dwSize.Y || b.dwSize.X != b.dwSize.X) dwEnd.X = dwEnd.Y = 0; - dwBufferSize = linfo.dwSize; - dwCursorPosition = linfo.dwCursorPosition; - if (dwCursorPosition.Y > dwEnd.Y - || (dwCursorPosition.Y >= dwEnd.Y && dwCursorPosition.X > dwEnd.X)) - dwEnd = dwCursorPosition; - wAttributes = linfo.wAttributes; + if (b.dwCursorPosition.Y > dwEnd.Y + || (b.dwCursorPosition.Y >= dwEnd.Y && b.dwCursorPosition.X > dwEnd.X)) + dwEnd = b.dwCursorPosition; } else { + memset (&b, 0, sizeof (b)); dwWinSize.Y = 25; dwWinSize.X = 80; - winBottom = 24; + b.srWindow.Bottom = 24; + b.srWindow.Right = 79; } return ret; @@ -780,36 +773,36 @@ dev_console::scroll_buffer (HANDLE h, int x1, int y1, int x2, int y2, int xn, in fillin (h); sr1.Left = x1 >= 0 ? x1 : dwWinSize.X - 1; - sr1.Top = y1 >= 0 ? y1 : winBottom; + sr1.Top = y1 >= 0 ? y1 : b.srWindow.Bottom; sr1.Right = x2 >= 0 ? x2 : dwWinSize.X - 1; - sr1.Bottom = y2 >= 0 ? y2 : winBottom; - sr2.Top = winTop + scroll_region.Top; + sr1.Bottom = y2 >= 0 ? y2 : b.srWindow.Bottom; + sr2.Top = b.srWindow.Top + scroll_region.Top; sr2.Left = 0; - sr2.Bottom = (scroll_region.Bottom < 0) ? winBottom : winTop + scroll_region.Bottom; + sr2.Bottom = (scroll_region.Bottom < 0) ? b.srWindow.Bottom : b.srWindow.Top + scroll_region.Bottom; sr2.Right = dwWinSize.X - 1; if (sr1.Bottom > sr2.Bottom && sr1.Top <= sr2.Bottom) sr1.Bottom = sr2.Bottom; dest.X = xn >= 0 ? xn : dwWinSize.X - 1; - dest.Y = yn >= 0 ? yn : winBottom; + dest.Y = yn >= 0 ? yn : b.srWindow.Bottom; ScrollConsoleScreenBuffer (h, &sr1, &sr2, dest, &fill); } inline void fhandler_console::scroll_buffer (int x1, int y1, int x2, int y2, int xn, int yn) { - dev_state.scroll_buffer (get_output_handle (), x1, y1, x2, y2, xn, yn); + con.scroll_buffer (get_output_handle (), x1, y1, x2, y2, xn, yn); } inline void fhandler_console::scroll_buffer_screen (int x1, int y1, int x2, int y2, int xn, int yn) { if (y1 >= 0) - y1 += dev_state.winTop; + y1 += con.b.srWindow.Top; if (y2 >= 0) - y1 += dev_state.winTop; + y1 += con.b.srWindow.Top; if (yn >= 0) - yn += dev_state.winTop; - dev_state.scroll_buffer (get_output_handle (), x1, y1, x2, y2, xn, yn); + yn += con.b.srWindow.Top; + con.scroll_buffer (get_output_handle (), x1, y1, x2, y2, xn, yn); } int @@ -860,12 +853,12 @@ fhandler_console::open (int flags, mode_t) } set_output_handle (h); - if (dev_state.fillin (get_output_handle ())) + if (con.fillin (get_output_handle ())) { - dev_state.current_win32_attr = dev_state.wAttributes; - if (!dev_state.default_color) - dev_state.default_color = dev_state.wAttributes; - dev_state.set_default_attr (); + con.current_win32_attr = con.b.wAttributes; + if (!con.default_color) + con.default_color = con.b.wAttributes; + con.set_default_attr (); } get_ttyp ()->rstcons (false); @@ -912,13 +905,13 @@ fhandler_console::ioctl (unsigned int cmd, void *arg) case TIOCGWINSZ: int st; - st = dev_state.fillin (get_output_handle ()); + st = con.fillin (get_output_handle ()); if (st) { /* *not* the buffer size, the actual screen size... */ /* based on Left Top Right Bottom of srWindow */ - ((struct winsize *) arg)->ws_row = dev_state.dwWinSize.Y; - ((struct winsize *) arg)->ws_col = dev_state.dwWinSize.X; + ((struct winsize *) arg)->ws_row = con.dwWinSize.Y; + ((struct winsize *) arg)->ws_col = con.dwWinSize.X; syscall_printf ("WINSZ: (row=%d,col=%d)", ((struct winsize *) arg)->ws_row, ((struct winsize *) arg)->ws_col); @@ -935,13 +928,13 @@ fhandler_console::ioctl (unsigned int cmd, void *arg) bg_check (SIGTTOU); return 0; case KDGKBMETA: - *(int *) arg = (dev_state.metabit) ? K_METABIT : K_ESCPREFIX; + *(int *) arg = (con.metabit) ? K_METABIT : K_ESCPREFIX; return 0; case KDSKBMETA: if ((intptr_t) arg == K_METABIT) - dev_state.metabit = TRUE; + con.metabit = TRUE; else if ((intptr_t) arg == K_ESCPREFIX) - dev_state.metabit = FALSE; + con.metabit = FALSE; else { set_errno (EINVAL); @@ -951,7 +944,7 @@ fhandler_console::ioctl (unsigned int cmd, void *arg) case TIOCLINUX: if (*(unsigned char *) arg == 6) { - *(unsigned char *) arg = (unsigned char) dev_state.nModifiers; + *(unsigned char *) arg = (unsigned char) con.nModifiers; return 0; } set_errno (EINVAL); @@ -1196,8 +1189,8 @@ dev_console::set_cl_x (cltype x) if (x == cl_disp_end) return dwWinSize.X - 1; if (x == cl_buf_end) - return dwBufferSize.X - 1; - return dwCursorPosition.X; + return b.dwSize.X - 1; + return b.dwCursorPosition.X; } int @@ -1206,37 +1199,37 @@ dev_console::set_cl_y (cltype y) if (y == cl_buf_beg) return 0; if (y == cl_disp_beg) - return winTop; + return b.srWindow.Top; if (y == cl_disp_end) - return winBottom; + return b.srWindow.Bottom; if (y == cl_buf_end) - return dwBufferSize.Y - 1; - return dwCursorPosition.Y; + return b.dwSize.Y - 1; + return b.dwCursorPosition.Y; } bool dev_console::scroll_window (HANDLE h, int x1, int y1, int x2, int y2) { - if (savebuf || x1 != 0 || x2 != dwWinSize.X - 1 || y1 != winTop - || y2 != winBottom || dwBufferSize.Y <= dwWinSize.Y) + if (save_buf || x1 != 0 || x2 != dwWinSize.X - 1 || y1 != b.srWindow.Top + || y2 != b.srWindow.Bottom || b.dwSize.Y <= dwWinSize.Y) return false; SMALL_RECT sr; - int toscroll = 2 + dwEnd.Y - winTop; - int shrink = 1 + toscroll + winBottom - dwBufferSize.Y; + int toscroll = 2 + dwEnd.Y - b.srWindow.Top; + int shrink = 1 + toscroll + b.srWindow.Bottom - b.dwSize.Y; sr.Left = sr.Right = dwEnd.X = 0; /* Can't increment dwEnd yet since we may not have space in the buffer. */ SetConsoleCursorPosition (h, dwEnd); if (shrink > 0) { - COORD c = dwBufferSize; + COORD c = b.dwSize; c.Y = dwEnd.Y - shrink; SetConsoleScreenBufferSize (h, c); - SetConsoleScreenBufferSize (h, dwBufferSize); + SetConsoleScreenBufferSize (h, b.dwSize); dwEnd.Y = 0; fillin (h); - toscroll = 2 + dwEnd.Y - winTop; + toscroll = 2 + dwEnd.Y - b.srWindow.Top; } sr.Top = sr.Bottom = toscroll; @@ -1258,17 +1251,17 @@ void __reg3 fhandler_console::clear_screen (cltype xc1, cltype yc1, cltype xc2, cltype yc2) { HANDLE h = get_output_handle (); - dev_state.fillin (h); + con.fillin (h); - int x1 = dev_state.set_cl_x (xc1); - int y1 = dev_state.set_cl_y (yc1); - int x2 = dev_state.set_cl_x (xc2); - int y2 = dev_state.set_cl_y (yc2); + int x1 = con.set_cl_x (xc1); + int y1 = con.set_cl_y (yc1); + int x2 = con.set_cl_x (xc2); + int y2 = con.set_cl_y (yc2); /* Detect special case - scroll the screen if we have a buffer in order to preserve the buffer. */ - if (!dev_state.scroll_window (h, x1, y1, x2, y2)) - dev_state.clear_screen (h, x1, y1, x2, y2); + if (!con.scroll_window (h, x1, y1, x2, y2)) + con.clear_screen (h, x1, y1, x2, y2); } void __reg3 @@ -1278,9 +1271,9 @@ dev_console::clear_screen (HANDLE h, int x1, int y1, int x2, int y2) DWORD done; int num; - num = abs (y1 - y2) * dwBufferSize.X + abs (x1 - x2) + 1; + num = abs (y1 - y2) * b.dwSize.X + abs (x1 - x2) + 1; - if ((y2 * dwBufferSize.X + x2) > (y1 * dwBufferSize.X + x1)) + if ((y2 * b.dwSize.X + x2) > (y1 * b.dwSize.X + x1)) { tlc.X = x1; tlc.Y = y1; @@ -1299,26 +1292,26 @@ fhandler_console::cursor_set (bool rel_to_top, int x, int y) { COORD pos; - dev_state.fillin (get_output_handle ()); + con.fillin (get_output_handle ()); #if 0 - /* Setting y to the current winBottom here is the reason that the window + /* Setting y to the current b.srWindow.Bottom here is the reason that the window isn't scrolled back to the current cursor position like it's done in any other terminal. Rather, the curser is forced to the bottom of the currently scrolled region. This breaks the console buffer content if output is generated while the user had the window scrolled back. This behaviour is very old, it has no matching ChangeLog entry. Just disable for now but keep the code in for future reference. */ - if (y > dev_state.winBottom) - y = dev_state.winBottom; + if (y > con.b.srWindow.Bottom) + y = con.b.srWindow.Bottom; else #endif if (y < 0) y = 0; else if (rel_to_top) - y += dev_state.winTop; + y += con.b.srWindow.Top; - if (x > dev_state.dwWinSize.X) - x = dev_state.dwWinSize.X - 1; + if (x > con.dwWinSize.X) + x = con.dwWinSize.X - 1; else if (x < 0) x = 0; @@ -1330,18 +1323,18 @@ fhandler_console::cursor_set (bool rel_to_top, int x, int y) void __reg3 fhandler_console::cursor_rel (int x, int y) { - dev_state.fillin (get_output_handle ()); - x += dev_state.dwCursorPosition.X; - y += dev_state.dwCursorPosition.Y; + con.fillin (get_output_handle ()); + x += con.b.dwCursorPosition.X; + y += con.b.dwCursorPosition.Y; cursor_set (false, x, y); } void __reg3 fhandler_console::cursor_get (int *x, int *y) { - dev_state.fillin (get_output_handle ()); - *y = dev_state.dwCursorPosition.Y; - *x = dev_state.dwCursorPosition.X; + con.fillin (get_output_handle ()); + *y = con.b.dwCursorPosition.Y; + *x = con.b.dwCursorPosition.X; } /* VT100 line drawing graphics mode maps `abcdefghijklmnopqrstuvwxyz{|}~ to @@ -1383,9 +1376,9 @@ static const wchar_t __vt100_conv[31] = { inline bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done) { - if (dev_state.iso_2022_G1 - ? dev_state.vt100_graphics_mode_G1 - : dev_state.vt100_graphics_mode_G0) + if (con.iso_2022_G1 + ? con.vt100_graphics_mode_G1 + : con.vt100_graphics_mode_G0) for (DWORD i = 0; i < len; i ++) if (buf[i] >= (unsigned char) '`' && buf[i] <= (unsigned char) '~') buf[i] = __vt100_conv[buf[i] - (unsigned char) '`']; @@ -1434,7 +1427,7 @@ delta (SHORT first, SHORT second) needed until it succeeds in reading the entire screen buffer. */ static BOOL ReadConsoleOutputWrapper (HANDLE h, PCHAR_INFO buf, COORD bufsiz, - SMALL_RECT& region) + SMALL_RECT region) { COORD coord = {}; SHORT width = delta (region.Left, region.Right); @@ -1458,6 +1451,63 @@ ReadConsoleOutputWrapper (HANDLE h, PCHAR_INFO buf, COORD bufsiz, return success; } +void +dev_console::save_restore (HANDLE h, char c) +{ + if (c == 'h') /* save */ + { + fillin (h); + save_bufsize = b.dwSize; /* Assume starting from 0/0 */ + + if (save_buf) + cfree (save_buf); + size_t screen_size = sizeof (CHAR_INFO) * save_bufsize.X * save_bufsize.Y; + save_buf = (PCHAR_INFO) cmalloc_abort (HEAP_1_BUF, screen_size); + + save_cursor = b.dwCursorPosition; /* Remember where we were. */ + + SMALL_RECT now = {}; /* Read the whole buffer */ + now.Bottom = b.dwSize.Y - 1; + now.Right = b.dwSize.X - 1; + if (!ReadConsoleOutputWrapper (h, save_buf, save_bufsize, now)) + debug_printf ("ReadConsoleOutputWrapper(h, ...) failed during save, %E"); + + /* Position at top of buffer */ + COORD cob = {}; + if (!SetConsoleCursorPosition (h, cob)) + debug_printf ("SetConsoleCursorInfo(%p, ...) failed during save, %E", h); + + /* Clear entire buffer */ + clear_screen (h, 0, 0, now.Right, now.Bottom); + b.dwCursorPosition.X = b.dwCursorPosition.Y = dwEnd.X = dwEnd.Y = 0; + } + else if (save_buf) + { + /* Restore original buffer size, just in case. */ + if (!SetConsoleScreenBufferSize (h, save_bufsize)) + debug_printf ("SetConsoleScreenBufferSize(h, ...) failed during restore, %E", h); + + /* Position where we were previously */ + if (!SetConsoleCursorPosition (h, save_cursor)) + debug_printf ("SetConsoleCursorInfo(%p, ...) failed during restore, %E", h); + + /* Get back correct version of buffer information */ + dwEnd.X = dwEnd.Y = 0; + fillin (h); + COORD cob = {}; + SMALL_RECT now = {}; + now.Bottom = b.dwSize.Y - 1; + now.Right = b.dwSize.X - 1; + /* Restore whole buffer */ + BOOL res = WriteConsoleOutputW (h, save_buf, save_bufsize, cob, &now); + if (!res) + debug_printf ("WriteConsoleOutputW failed, %E"); + + cfree (save_buf); + save_buf = NULL; + } +} + #define BAK 1 #define ESC 2 #define NOR 0 @@ -1519,112 +1569,112 @@ fhandler_console::char_command (char c) switch (c) { case 'm': /* Set Graphics Rendition */ - for (int i = 0; i <= dev_state.nargs; i++) - switch (dev_state.args[i]) + for (int i = 0; i <= con.nargs; i++) + switch (con.args[i]) { case 0: /* normal color */ - dev_state.set_default_attr (); + con.set_default_attr (); break; case 1: /* bold */ - dev_state.intensity = INTENSITY_BOLD; + con.intensity = INTENSITY_BOLD; break; case 2: /* dim */ - dev_state.intensity = INTENSITY_DIM; + con.intensity = INTENSITY_DIM; break; case 4: /* underlined */ - dev_state.underline = 1; + con.underline = 1; break; case 5: /* blink mode */ - dev_state.blink = true; + con.blink = true; break; case 7: /* reverse */ - dev_state.reverse = true; + con.reverse = true; break; case 8: /* invisible */ - dev_state.intensity = INTENSITY_INVISIBLE; + con.intensity = INTENSITY_INVISIBLE; break; case 10: /* end alternate charset */ - dev_state.alternate_charset_active = false; + con.alternate_charset_active = false; break; case 11: /* start alternate charset */ - dev_state.alternate_charset_active = true; + con.alternate_charset_active = true; break; case 22: case 28: - dev_state.intensity = INTENSITY_NORMAL; + con.intensity = INTENSITY_NORMAL; break; case 24: - dev_state.underline = false; + con.underline = false; break; case 25: - dev_state.blink = false; + con.blink = false; break; case 27: - dev_state.reverse = false; + con.reverse = false; break; case 30: /* BLACK foreground */ - dev_state.fg = 0; + con.fg = 0; break; case 31: /* RED foreground */ - dev_state.fg = FOREGROUND_RED; + con.fg = FOREGROUND_RED; break; case 32: /* GREEN foreground */ - dev_state.fg = FOREGROUND_GREEN; + con.fg = FOREGROUND_GREEN; break; case 33: /* YELLOW foreground */ - dev_state.fg = FOREGROUND_RED | FOREGROUND_GREEN; + con.fg = FOREGROUND_RED | FOREGROUND_GREEN; break; case 34: /* BLUE foreground */ - dev_state.fg = FOREGROUND_BLUE; + con.fg = FOREGROUND_BLUE; break; case 35: /* MAGENTA foreground */ - dev_state.fg = FOREGROUND_RED | FOREGROUND_BLUE; + con.fg = FOREGROUND_RED | FOREGROUND_BLUE; break; case 36: /* CYAN foreground */ - dev_state.fg = FOREGROUND_BLUE | FOREGROUND_GREEN; + con.fg = FOREGROUND_BLUE | FOREGROUND_GREEN; break; case 37: /* WHITE foreg */ - dev_state.fg = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; + con.fg = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; break; case 39: - dev_state.fg = dev_state.default_color & FOREGROUND_ATTR_MASK; + con.fg = con.default_color & FOREGROUND_ATTR_MASK; break; case 40: /* BLACK background */ - dev_state.bg = 0; + con.bg = 0; break; case 41: /* RED background */ - dev_state.bg = BACKGROUND_RED; + con.bg = BACKGROUND_RED; break; case 42: /* GREEN background */ - dev_state.bg = BACKGROUND_GREEN; + con.bg = BACKGROUND_GREEN; break; case 43: /* YELLOW background */ - dev_state.bg = BACKGROUND_RED | BACKGROUND_GREEN; + con.bg = BACKGROUND_RED | BACKGROUND_GREEN; break; case 44: /* BLUE background */ - dev_state.bg = BACKGROUND_BLUE; + con.bg = BACKGROUND_BLUE; break; case 45: /* MAGENTA background */ - dev_state.bg = BACKGROUND_RED | BACKGROUND_BLUE; + con.bg = BACKGROUND_RED | BACKGROUND_BLUE; break; case 46: /* CYAN background */ - dev_state.bg = BACKGROUND_BLUE | BACKGROUND_GREEN; + con.bg = BACKGROUND_BLUE | BACKGROUND_GREEN; break; case 47: /* WHITE background */ - dev_state.bg = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED; + con.bg = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED; break; case 49: - dev_state.bg = dev_state.default_color & BACKGROUND_ATTR_MASK; + con.bg = con.default_color & BACKGROUND_ATTR_MASK; break; } - dev_state.set_color (get_output_handle ()); + con.set_color (get_output_handle ()); break; case 'q': /* Set cursor style (DECSCUSR) */ - if (dev_state.saw_space) + if (con.saw_space) { CONSOLE_CURSOR_INFO console_cursor_info; GetConsoleCursorInfo (get_output_handle (), & console_cursor_info); - switch (dev_state.args[0]) + switch (con.args[0]) { case 0: /* blinking block */ case 1: /* blinking block (default) */ @@ -1638,7 +1688,7 @@ fhandler_console::char_command (char c) SetConsoleCursorInfo (get_output_handle (), & console_cursor_info); break; default: /* use value as percentage */ - console_cursor_info.dwSize = dev_state.args[0]; + console_cursor_info.dwSize = con.args[0]; SetConsoleCursorInfo (get_output_handle (), & console_cursor_info); break; } @@ -1646,18 +1696,18 @@ fhandler_console::char_command (char c) break; case 'h': case 'l': - if (!dev_state.saw_question_mark) + if (!con.saw_question_mark) { - switch (dev_state.args[0]) + switch (con.args[0]) { case 4: /* Insert mode */ - dev_state.insert_mode = (c == 'h') ? true : false; - syscall_printf ("insert mode %sabled", dev_state.insert_mode ? "en" : "dis"); + con.insert_mode = (c == 'h') ? true : false; + syscall_printf ("insert mode %sabled", con.insert_mode ? "en" : "dis"); break; } break; } - switch (dev_state.args[0]) + switch (con.args[0]) { case 25: /* Show/Hide Cursor (DECTCEM) */ { @@ -1671,84 +1721,39 @@ fhandler_console::char_command (char c) break; } case 47: /* Save/Restore screen */ - if (c == 'h') /* save */ - { - CONSOLE_SCREEN_BUFFER_INFO now; - - if (!GetConsoleScreenBufferInfo (get_output_handle (), &now)) - break; - - /* Assume starting from 0/0 */ - dev_state.savebufsiz.X = 1 + now.srWindow.Right; - dev_state.savebufsiz.Y = 1 + now.srWindow.Bottom; - - if (dev_state.savebuf) - cfree (dev_state.savebuf); - size_t screen_size = sizeof (CHAR_INFO) * dev_state.savebufsiz.X * dev_state.savebufsiz.Y; - dev_state.savebuf = (PCHAR_INFO) cmalloc_abort (HEAP_1_BUF, screen_size); - - BOOL res = ReadConsoleOutputWrapper (get_output_handle (), - dev_state.savebuf, - dev_state.savebufsiz, - now.srWindow); - if (!res) - debug_printf ("ReadConsoleOutputWrapper failed, %E"); - } - else /* restore */ - { - if (!dev_state.savebuf) - break; - - CONSOLE_SCREEN_BUFFER_INFO now; - COORD cob = { 0, 0 }; - - if (!GetConsoleScreenBufferInfo (get_output_handle (), &now)) - { - debug_printf ("GetConsoleScreenBufferInfo(%y, %y), %E", get_output_handle (), &now); - break; - } - - BOOL res = WriteConsoleOutputW (get_output_handle (), dev_state.savebuf, - dev_state.savebufsiz, cob, &now.srWindow); - if (!res) - debug_printf ("WriteConsoleOutputW failed, %E"); - - cfree (dev_state.savebuf); - dev_state.savebuf = NULL; - dev_state.savebufsiz.X = dev_state.savebufsiz.Y = 0; - } + con.save_restore (get_output_handle (), c); break; case 67: /* DECBKM ("DEC Backarrow Key Mode") */ - dev_state.backspace_keycode = (c == 'h' ? CTRL('H') : CERASE); + con.backspace_keycode = (c == 'h' ? CTRL('H') : CERASE); break; case 1000: /* Mouse tracking */ - dev_state.use_mouse = (c == 'h') ? 1 : 0; + con.use_mouse = (c == 'h') ? 1 : 0; break; case 1002: /* Mouse button event tracking */ - dev_state.use_mouse = (c == 'h') ? 2 : 0; + con.use_mouse = (c == 'h') ? 2 : 0; break; case 1003: /* Mouse any event tracking */ - dev_state.use_mouse = (c == 'h') ? 3 : 0; + con.use_mouse = (c == 'h') ? 3 : 0; break; case 1004: /* Focus in/out event reporting */ - dev_state.use_focus = (c == 'h') ? true : false; + con.use_focus = (c == 'h') ? true : false; break; case 1005: /* Extended mouse mode */ - dev_state.ext_mouse_mode5 = c == 'h'; + con.ext_mouse_mode5 = c == 'h'; break; case 1006: /* SGR extended mouse mode */ - dev_state.ext_mouse_mode6 = c == 'h'; + con.ext_mouse_mode6 = c == 'h'; break; case 1015: /* Urxvt extended mouse mode */ - dev_state.ext_mouse_mode15 = c == 'h'; + con.ext_mouse_mode15 = c == 'h'; break; case 2000: /* Raw keyboard mode */ @@ -1756,12 +1761,12 @@ fhandler_console::char_command (char c) break; default: /* Ignore */ - syscall_printf ("unknown h/l command: %d", dev_state.args[0]); + syscall_printf ("unknown h/l command: %d", con.args[0]); break; } break; case 'J': - switch (dev_state.args[0]) + switch (con.args[0]) { case 0: /* Clear to end of screen */ clear_screen (cl_curr_pos, cl_curr_pos, cl_disp_end, cl_disp_end); @@ -1780,19 +1785,19 @@ fhandler_console::char_command (char c) break; case 'A': - cursor_rel (0, -(dev_state.args[0] ?: 1)); + cursor_rel (0, -(con.args[0] ?: 1)); break; case 'B': - cursor_rel (0, dev_state.args[0] ?: 1); + cursor_rel (0, con.args[0] ?: 1); break; case 'C': - cursor_rel (dev_state.args[0] ?: 1, 0); + cursor_rel (con.args[0] ?: 1, 0); break; case 'D': - cursor_rel (-(dev_state.args[0] ?: 1),0); + cursor_rel (-(con.args[0] ?: 1),0); break; case 'K': - switch (dev_state.args[0]) + switch (con.args[0]) { case 0: /* Clear to end of line */ clear_screen (cl_curr_pos, cl_curr_pos, cl_disp_end, cl_curr_pos); @@ -1809,59 +1814,59 @@ fhandler_console::char_command (char c) break; case 'H': case 'f': - cursor_set (true, (dev_state.args[1] ?: 1) - 1, - (dev_state.args[0] ?: 1) - 1); + cursor_set (true, (con.args[1] ?: 1) - 1, + (con.args[0] ?: 1) - 1); break; case 'G': /* hpa - position cursor at column n - 1 */ cursor_get (&x, &y); - cursor_set (false, (dev_state.args[0] ? dev_state.args[0] - 1 : 0), y); + cursor_set (false, (con.args[0] ? con.args[0] - 1 : 0), y); break; case 'd': /* vpa - position cursor at line n */ cursor_get (&x, &y); - cursor_set (true, x, (dev_state.args[0] ? dev_state.args[0] - 1 : 0)); + cursor_set (true, x, (con.args[0] ? con.args[0] - 1 : 0)); break; case 's': /* Save cursor position */ - cursor_get (&dev_state.savex, &dev_state.savey); - dev_state.savey -= dev_state.winTop; + cursor_get (&con.savex, &con.savey); + con.savey -= con.b.srWindow.Top; break; case 'u': /* Restore cursor position */ - cursor_set (true, dev_state.savex, dev_state.savey); + cursor_set (true, con.savex, con.savey); break; case 'I': /* TAB */ cursor_get (&x, &y); cursor_set (false, 8 * (x / 8 + 1), y); break; case 'L': /* AL - insert blank lines */ - n = dev_state.args[0] ?: 1; + n = con.args[0] ?: 1; cursor_get (&x, &y); scroll_buffer (0, y, -1, -1, 0, y + n); break; case 'M': /* DL - delete lines */ - n = dev_state.args[0] ?: 1; + n = con.args[0] ?: 1; cursor_get (&x, &y); scroll_buffer (0, y + n, -1, -1, 0, y); break; case '@': /* IC - insert chars */ - n = dev_state.args[0] ?: 1; + n = con.args[0] ?: 1; cursor_get (&x, &y); scroll_buffer (x, y, -1, y, x + n, y); break; case 'P': /* DC - delete chars */ - n = dev_state.args[0] ?: 1; + n = con.args[0] ?: 1; cursor_get (&x, &y); scroll_buffer (x + n, y, -1, y, x, y); break; case 'S': /* SF - Scroll forward */ - n = dev_state.args[0] ?: 1; + n = con.args[0] ?: 1; scroll_buffer_screen (0, n, -1, -1, 0, 0); break; case 'T': /* SR - Scroll down */ - dev_state.fillin (get_output_handle ()); - n = dev_state.winTop + dev_state.args[0] ?: 1; + con.fillin (get_output_handle ()); + n = con.b.srWindow.Top + con.args[0] ?: 1; scroll_buffer_screen (0, 0, -1, -1, 0, n); break; case 'X': /* ec - erase chars */ - n = dev_state.args[0] ?: 1; + n = con.args[0] ?: 1; cursor_get (&x, &y); scroll_buffer (x + n, y, -1, y, x, y); scroll_buffer (x, y, -1, y, x + n, y); @@ -1871,16 +1876,16 @@ fhandler_console::char_command (char c) cursor_set (false, ((8 * (x / 8 + 1)) - 8), y); break; case 'b': /* Repeat char #1 #2 times */ - if (dev_state.insert_mode) + if (con.insert_mode) { cursor_get (&x, &y); - scroll_buffer (x, y, -1, y, x + dev_state.args[1], y); + scroll_buffer (x, y, -1, y, x + con.args[1], y); } - while (dev_state.args[1]--) - WriteFile (get_output_handle (), &dev_state.args[0], 1, (DWORD *) &x, 0); + while (con.args[1]--) + WriteFile (get_output_handle (), &con.args[0], 1, (DWORD *) &x, 0); break; case 'c': /* u9 - Terminal enquire string */ - if (dev_state.saw_greater_than_sign) + if (con.saw_greater_than_sign) /* Generate Secondary Device Attribute report, using 67 = ASCII 'C' to indicate Cygwin (convention used by Rxvt, Urxvt, Screen, Mintty), and cygwin version for terminal version. */ @@ -1893,12 +1898,12 @@ fhandler_console::char_command (char c) puts_readahead (buf); break; case 'n': - switch (dev_state.args[0]) + switch (con.args[0]) { case 6: /* u7 - Cursor position request */ cursor_get (&x, &y); - y -= dev_state.winTop; - /* x -= dev_state.winLeft; // not available yet */ + y -= con.b.srWindow.Top; + /* x -= con.b.srWindow.Left; // not available yet */ __small_sprintf (buf, "\033[%d;%dR", y + 1, x + 1); puts_readahead (buf); break; @@ -1907,8 +1912,8 @@ fhandler_console::char_command (char c) } break; case 'r': /* Set Scroll region */ - dev_state.scroll_region.Top = dev_state.args[0] ? dev_state.args[0] - 1 : 0; - dev_state.scroll_region.Bottom = dev_state.args[1] ? dev_state.args[1] - 1 : -1; + con.scroll_region.Top = con.args[0] ? con.args[0] - 1 : 0; + con.scroll_region.Bottom = con.args[1] ? con.args[1] - 1 : -1; cursor_set (true, 0, 0); break; case 'g': /* TAB set/clear */ @@ -1940,7 +1945,7 @@ fhandler_console::write_normal (const unsigned char *src, const unsigned char *found = src; size_t ret; mbstate_t ps; - UINT cp = dev_state.get_console_cp (); + UINT cp = con.get_console_cp (); const char *charset; mbtowc_p f_mbtowc; @@ -1990,7 +1995,7 @@ fhandler_console::write_normal (const unsigned char *src, /* Valid multibyte sequence? Process. */ if (nfound) { - buf_len = dev_state.str_to_con (f_mbtowc, charset, write_buf, + buf_len = con.str_to_con (f_mbtowc, charset, write_buf, (const char *) trunc_buf.buf, nfound - trunc_buf.buf); if (!write_console (write_buf, buf_len, done)) @@ -2036,7 +2041,7 @@ do_print: if (found != src) { DWORD len = found - src; - buf_len = dev_state.str_to_con (f_mbtowc, charset, write_buf, + buf_len = con.str_to_con (f_mbtowc, charset, write_buf, (const char *) src, len); if (!buf_len) { @@ -2046,7 +2051,7 @@ do_print: return 0; } - if (dev_state.insert_mode) + if (con.insert_mode) { int x, y; cursor_get (&x, &y); @@ -2071,22 +2076,22 @@ do_print: switch (base_chars[*found]) { case SO: /* Shift Out: Invoke G1 character set (ISO 2022) */ - dev_state.iso_2022_G1 = true; + con.iso_2022_G1 = true; break; case SI: /* Shift In: Invoke G0 character set (ISO 2022) */ - dev_state.iso_2022_G1 = false; + con.iso_2022_G1 = false; break; case BEL: beep (); break; case ESC: - dev_state.state = gotesc; + con.state = gotesc; break; case DWN: cursor_get (&x, &y); if (y >= srBottom) { - if (y >= dev_state.winBottom && !dev_state.scroll_region.Top) + if (y >= con.b.srWindow.Bottom && !con.scroll_region.Top) WriteConsoleW (get_output_handle (), L"\n", 1, &done, 0); else { @@ -2162,8 +2167,8 @@ fhandler_console::write (const void *vsrc, size_t len) while (src < end) { - paranoid_printf ("char %0c state is %d", *src, dev_state.state); - switch (dev_state.state) + paranoid_printf ("char %0c state is %d", *src, con.state); + switch (con.state) { case normal: src = write_normal (src, end); @@ -2173,112 +2178,112 @@ fhandler_console::write (const void *vsrc, size_t len) case gotesc: if (*src == '[') /* CSI Control Sequence Introducer */ { - dev_state.state = gotsquare; - dev_state.saw_question_mark = false; - dev_state.saw_greater_than_sign = false; - dev_state.saw_space = false; - for (dev_state.nargs = 0; dev_state.nargs < MAXARGS; dev_state.nargs++) - dev_state.args[dev_state.nargs] = 0; - dev_state.nargs = 0; + con.state = gotsquare; + con.saw_question_mark = false; + con.saw_greater_than_sign = false; + con.saw_space = false; + for (con.nargs = 0; con.nargs < MAXARGS; con.nargs++) + con.args[con.nargs] = 0; + con.nargs = 0; } else if (*src == ']') /* OSC Operating System Command */ { - dev_state.rarg = 0; - dev_state.my_title_buf[0] = '\0'; - dev_state.state = gotrsquare; + con.rarg = 0; + con.my_title_buf[0] = '\0'; + con.state = gotrsquare; } else if (*src == '(') /* Designate G0 character set */ { - dev_state.state = gotparen; + con.state = gotparen; } else if (*src == ')') /* Designate G1 character set */ { - dev_state.state = gotrparen; + con.state = gotrparen; } else if (*src == 'M') /* Reverse Index (scroll down) */ { - dev_state.fillin (get_output_handle ()); + con.fillin (get_output_handle ()); scroll_buffer_screen (0, 0, -1, -1, 0, 1); - dev_state.state = normal; + con.state = normal; } else if (*src == 'c') /* RIS Full Reset */ { - dev_state.set_default_attr (); - dev_state.vt100_graphics_mode_G0 = false; - dev_state.vt100_graphics_mode_G1 = false; - dev_state.iso_2022_G1 = false; + con.set_default_attr (); + con.vt100_graphics_mode_G0 = false; + con.vt100_graphics_mode_G1 = false; + con.iso_2022_G1 = false; cursor_set (false, 0, 0); clear_screen (cl_buf_beg, cl_buf_beg, cl_buf_end, cl_buf_end); - dev_state.state = normal; + con.state = normal; } else if (*src == '8') /* DECRC Restore cursor position */ { - cursor_set (true, dev_state.savex, dev_state.savey); - dev_state.state = normal; + cursor_set (true, con.savex, con.savey); + con.state = normal; } else if (*src == '7') /* DECSC Save cursor position */ { - cursor_get (&dev_state.savex, &dev_state.savey); - dev_state.savey -= dev_state.winTop; - dev_state.state = normal; + cursor_get (&con.savex, &con.savey); + con.savey -= con.b.srWindow.Top; + con.state = normal; } else if (*src == 'R') /* ? */ - dev_state.state = normal; + con.state = normal; else { - dev_state.state = normal; + con.state = normal; } src++; break; case gotarg1: if (isdigit (*src)) { - dev_state.args[dev_state.nargs] = dev_state.args[dev_state.nargs] * 10 + *src - '0'; + con.args[con.nargs] = con.args[con.nargs] * 10 + *src - '0'; src++; } else if (*src == ';') { src++; - dev_state.nargs++; - if (dev_state.nargs >= MAXARGS) - dev_state.nargs--; + con.nargs++; + if (con.nargs >= MAXARGS) + con.nargs--; } else if (*src == ' ') { src++; - dev_state.saw_space = true; - dev_state.state = gotcommand; + con.saw_space = true; + con.state = gotcommand; } else - dev_state.state = gotcommand; + con.state = gotcommand; break; case gotcommand: char_command (*src++); - dev_state.state = normal; + con.state = normal; break; case gotrsquare: if (isdigit (*src)) - dev_state.rarg = dev_state.rarg * 10 + (*src - '0'); - else if (*src == ';' && (dev_state.rarg == 2 || dev_state.rarg == 0)) - dev_state.state = gettitle; + con.rarg = con.rarg * 10 + (*src - '0'); + else if (*src == ';' && (con.rarg == 2 || con.rarg == 0)) + con.state = gettitle; else - dev_state.state = eattitle; + con.state = eattitle; src++; break; case eattitle: case gettitle: { - int n = strlen (dev_state.my_title_buf); + int n = strlen (con.my_title_buf); if (*src < ' ') { - if (*src == '\007' && dev_state.state == gettitle) - set_console_title (dev_state.my_title_buf); - dev_state.state = normal; + if (*src == '\007' && con.state == gettitle) + set_console_title (con.my_title_buf); + con.state = normal; } else if (n < TITLESIZE) { - dev_state.my_title_buf[n++] = *src; - dev_state.my_title_buf[n] = '\0'; + con.my_title_buf[n++] = *src; + con.my_title_buf[n] = '\0'; } src++; break; @@ -2286,38 +2291,38 @@ fhandler_console::write (const void *vsrc, size_t len) case gotsquare: if (*src == ';') { - dev_state.state = gotarg1; - dev_state.nargs++; + con.state = gotarg1; + con.nargs++; src++; } else if (isalpha (*src)) - dev_state.state = gotcommand; + con.state = gotcommand; else if (*src != '@' && !isalpha (*src) && !isdigit (*src)) { if (*src == '?') - dev_state.saw_question_mark = true; + con.saw_question_mark = true; else if (*src == '>') - dev_state.saw_greater_than_sign = true; + con.saw_greater_than_sign = true; /* ignore any extra chars between [ and first arg or command */ src++; } else - dev_state.state = gotarg1; + con.state = gotarg1; break; case gotparen: /* Designate G0 Character Set (ISO 2022) */ if (*src == '0') - dev_state.vt100_graphics_mode_G0 = true; + con.vt100_graphics_mode_G0 = true; else - dev_state.vt100_graphics_mode_G0 = false; - dev_state.state = normal; + con.vt100_graphics_mode_G0 = false; + con.state = normal; src++; break; case gotrparen: /* Designate G1 Character Set (ISO 2022) */ if (*src == '0') - dev_state.vt100_graphics_mode_G1 = true; + con.vt100_graphics_mode_G1 = true; else - dev_state.vt100_graphics_mode_G1 = false; - dev_state.state = normal; + con.vt100_graphics_mode_G1 = false; + con.state = normal; src++; break; }