cons_nt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Client interface for General purpose Win32 console save/restore server
  2. Having the same interface as its Linux counterpart:
  3. Copyright (C) 1994 Janne Kukonlehto <jtklehto@stekt.oulu.fi>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. Note:
  16. show_console_contents doesn't know how to write to its window
  17. the rest works fine.
  18. */
  19. #include <config.h>
  20. #include <windows.h>
  21. #include "trace_nt.h"
  22. int cons_saver_pid = 1;
  23. #include "../src/tty.h"
  24. #include "../src/util.h"
  25. #include "../src/win.h"
  26. #include "../src/cons.saver.h"
  27. signed char console_flag = 1;
  28. static HANDLE hSaved, hNew;
  29. void show_console_contents (int starty, unsigned char begin_line,
  30. unsigned char end_line)
  31. {
  32. COORD c0 = { 0, 0 };
  33. COORD csize;
  34. SMALL_RECT rect;
  35. CHAR_INFO *pchar;
  36. csize.X = COLS;
  37. csize.Y = end_line-begin_line;
  38. rect.Left = 0;
  39. rect.Top = begin_line;
  40. rect.Right = COLS;
  41. rect.Bottom = end_line;
  42. /* -- This code reads characters and attributes */
  43. pchar = malloc (sizeof(CHAR_INFO) * (end_line-begin_line) * COLS);
  44. /* Copy from one console to the curses virtual screen */
  45. win32APICALL(ReadConsoleOutput (hSaved, pchar, csize, c0, &rect));
  46. /* FIXME: this should've work,
  47. but refresh() is called after this write :-( */
  48. win32APICALL(WriteConsoleOutput (hNew, pchar, csize, c0, &rect));
  49. free (pchar);
  50. }
  51. void handle_console (unsigned char action)
  52. {
  53. static SECURITY_ATTRIBUTES sa;
  54. CONSOLE_SCREEN_BUFFER_INFO csbi;
  55. switch (action){
  56. case CONSOLE_INIT:
  57. /* Save Standard handle */
  58. hSaved = GetStdHandle (STD_OUTPUT_HANDLE);
  59. sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  60. sa.lpSecurityDescriptor = NULL;
  61. /* Create a new console buffer */
  62. sa.bInheritHandle = TRUE;
  63. win32APICALL_HANDLE(hNew,
  64. CreateConsoleScreenBuffer (GENERIC_WRITE | GENERIC_READ,
  65. FILE_SHARE_READ | FILE_SHARE_WRITE, &sa,
  66. CONSOLE_TEXTMODE_BUFFER, NULL));
  67. win32APICALL(GetConsoleScreenBufferInfo(hSaved, &csbi));
  68. win32APICALL(SetConsoleScreenBufferSize(hNew, csbi.dwSize));
  69. /* that becomes standard handle */
  70. win32APICALL(SetConsoleActiveScreenBuffer(hNew));
  71. win32APICALL(SetConsoleMode(hNew, ENABLE_PROCESSED_INPUT));
  72. win32APICALL(SetStdHandle(STD_OUTPUT_HANDLE, hNew));
  73. break;
  74. case CONSOLE_DONE:
  75. win32APICALL(CloseHandle (hNew));
  76. break;
  77. case CONSOLE_SAVE:
  78. /* Current = our standard handle */
  79. win32APICALL(SetConsoleActiveScreenBuffer (hNew));
  80. win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE, hNew));
  81. break;
  82. case CONSOLE_RESTORE:
  83. /* Put saved (shell) screen buffer */
  84. win32APICALL(SetConsoleActiveScreenBuffer (hSaved));
  85. win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE, hSaved));
  86. break;
  87. default:
  88. win32Trace(("Invalid action code %d sent to handle_console", action));
  89. }
  90. }