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>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 show_console_contents doesn't know how to write to its window
25 #include "../src/global.h"
28 int cons_saver_pid
= 1;
30 #include "../src/tty.h"
31 #include "../src/util.h"
32 #include "../src/win.h"
33 #include "../src/cons.saver.h"
35 signed char console_flag
= 1;
36 static HANDLE hSaved
, hNew
;
38 void show_console_contents (int starty
, unsigned char begin_line
,
39 unsigned char end_line
)
47 csize
.Y
= end_line
-begin_line
;
49 rect
.Top
= begin_line
;
51 rect
.Bottom
= end_line
;
53 /* -- This code reads characters and attributes */
54 pchar
= malloc (sizeof(CHAR_INFO
) * (end_line
-begin_line
) * COLS
);
55 /* Copy from one console to the curses virtual screen */
56 win32APICALL(ReadConsoleOutput (hSaved
, pchar
, csize
, c0
, &rect
));
58 /* FIXME: this should've work,
59 but refresh() is called after this write :-( */
60 win32APICALL(WriteConsoleOutput (hNew
, pchar
, csize
, c0
, &rect
));
65 void handle_console (unsigned char action
)
67 static SECURITY_ATTRIBUTES sa
;
68 CONSOLE_SCREEN_BUFFER_INFO csbi
;
72 /* Save Standard handle */
73 hSaved
= GetStdHandle (STD_OUTPUT_HANDLE
);
75 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
76 sa
.lpSecurityDescriptor
= NULL
;
77 /* Create a new console buffer */
78 sa
.bInheritHandle
= TRUE
;
79 win32APICALL_HANDLE(hNew
,
80 CreateConsoleScreenBuffer (GENERIC_WRITE
| GENERIC_READ
,
81 FILE_SHARE_READ
| FILE_SHARE_WRITE
, &sa
,
82 CONSOLE_TEXTMODE_BUFFER
, NULL
));
83 win32APICALL(GetConsoleScreenBufferInfo(hSaved
, &csbi
));
84 win32APICALL(SetConsoleScreenBufferSize(hNew
, csbi
.dwSize
));
86 /* that becomes standard handle */
87 win32APICALL(SetConsoleActiveScreenBuffer(hNew
));
88 win32APICALL(SetConsoleMode(hNew
, ENABLE_PROCESSED_INPUT
));
89 win32APICALL(SetStdHandle(STD_OUTPUT_HANDLE
, hNew
));
93 win32APICALL(CloseHandle (hNew
));
97 /* Current = our standard handle */
98 win32APICALL(SetConsoleActiveScreenBuffer (hNew
));
99 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE
, hNew
));
102 case CONSOLE_RESTORE
:
103 /* Put saved (shell) screen buffer */
104 win32APICALL(SetConsoleActiveScreenBuffer (hSaved
));
105 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE
, hSaved
));
108 win32Trace(("Invalid action code %d sent to handle_console", action
));