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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 show_console_contents doesn't know how to write to its window
25 #error This file is for Win32 operating systems.
29 #include "util.debug.h"
31 int cons_saver_pid
= 1;
36 #include "cons.saver.h"
38 signed char console_flag
= 1;
39 static HANDLE hSaved
, hNew
;
41 void show_console_contents (int starty
, unsigned char begin_line
, unsigned char end_line
)
50 csize
.Y
= end_line
-begin_line
;
52 rect
.Top
= begin_line
;
54 rect
.Bottom
= end_line
;
56 // -- This code reads characters and attributes
57 pchar
= malloc (sizeof(CHAR_INFO
) * (end_line
-begin_line
) * COLS
);
58 // Copy from one console to the curses virtual screen
59 win32APICALL(ReadConsoleOutput (hSaved
, pchar
, csize
, c0
, &rect
));
61 // FIXME: this should've work, but refresh() is called after this write :-(
62 win32APICALL(WriteConsoleOutput (hNew
, pchar
, csize
, c0
, &rect
));
65 // Here we read only characters so that we can printw to stdscr.
66 // pchar = malloc (sizeof(TCHAR) * (end_line-begin_line) * COLS);
68 // Copy from one console to the curses virtual screen
69 // ReadConsoleOutputCharacter (hSaved, pchar, (end_line-begin_line) * COLS, c0, &dw);
71 // mvprintw(0, begin_line, "%.*s", (end_line-begin_line) * COLS, pchar);
73 //#error show_console_contents not written for S-Lang
80 void handle_console (unsigned char action
)
82 static SECURITY_ATTRIBUTES sa
;
84 CONSOLE_SCREEN_BUFFER_INFO csbi
;
88 case CONSOLE_INIT
: // Init
89 hSaved
= GetStdHandle (STD_OUTPUT_HANDLE
); // Save Standard handle
91 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
92 sa
.lpSecurityDescriptor
= NULL
;
93 sa
.bInheritHandle
= TRUE
; // Create a new console buffer
94 win32APICALL_HANDLE(hNew
, /* = */ CreateConsoleScreenBuffer (GENERIC_WRITE
| GENERIC_READ
,
95 FILE_SHARE_READ
| FILE_SHARE_WRITE
, &sa
,
96 CONSOLE_TEXTMODE_BUFFER
, NULL
));
97 win32APICALL(GetConsoleScreenBufferInfo(hSaved
, &csbi
)); // ... with same size
98 win32APICALL(SetConsoleScreenBufferSize(hNew
, csbi
.dwSize
));
100 win32APICALL(SetConsoleActiveScreenBuffer(hNew
)); // ... that becomes standard handle
101 win32APICALL(SetConsoleMode(hNew
, ENABLE_PROCESSED_INPUT
));
102 win32APICALL(SetStdHandle(STD_OUTPUT_HANDLE
, hNew
));
105 case CONSOLE_DONE
: // Clean Up
106 win32APICALL(CloseHandle (hNew
));
109 case CONSOLE_SAVE
: // Save
110 win32APICALL(SetConsoleActiveScreenBuffer (hNew
)); // Current = our standard handle
111 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE
, hNew
));
114 case CONSOLE_RESTORE
: // Restore
115 win32APICALL(SetConsoleActiveScreenBuffer (hSaved
)); // Put saved (shell) screen buffer
116 win32APICALL(SetStdHandle (STD_OUTPUT_HANDLE
, hSaved
));
119 win32Trace(("Invalid action code %d received in handle_console", action
));