1 /****************************************************************************
2 * Copyright 2018-2023,2024 Thomas E. Dickey *
3 * Copyright 2008-2010,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas Dickey, 2008-on *
32 ****************************************************************************/
34 /* $Id: nc_win32.h,v 1.12 2024/05/04 19:17:03 tom Exp $ */
39 #if defined(_WIN32) || defined(_WIN64)
46 #error TERMIOS must not be defined on Windows
49 /* We no longer support WindowsXP.
50 Minimum requirement is Windows Vista or Server2008,
55 # error WINVER must at least be 0x0600
58 # define WINVER 0x0600
61 #undef _NC_CHECK_MINTTY
63 #define _NC_CHECK_MINTTY
69 #include <sys/time.h> /* for struct timeval */
73 #include <winsock2.h> /* for struct timeval */
76 #include <stdint.h> /* for uint32_t */
82 #include <ncurses_dll.h>
84 #if !HAVE_CLOCK_GETTIME && !HAVE_GETTIMEOFDAY
85 #undef HAVE_GETTIMEOFDAY
86 #define HAVE_GETTIMEOFDAY 2
87 extern NCURSES_EXPORT(int) _nc_gettimeofday(struct timeval *, void *);
91 #define wcwidth(ucs) _nc_wcwidth((wchar_t)(ucs))
92 extern NCURSES_EXPORT(int) _nc_wcwidth(uint32_t);
94 #ifdef EVENTLIST_2nd /* test.priv.h just needs the preceding */
96 extern NCURSES_EXPORT(void) _nc_console_size(int* Lines, int* Cols);
97 extern NCURSES_EXPORT(HANDLE) _nc_console_handle(int fd);
98 extern NCURSES_EXPORT(int) _nc_console_isatty(int fd);
99 extern NCURSES_EXPORT(int) _nc_console_test(int fd);
100 extern NCURSES_EXPORT(int) _nc_console_read(SCREEN *sp,HANDLE hdl,int *buf);
101 extern NCURSES_EXPORT(int) _nc_console_twait(SCREEN *, HANDLE,int,int,int * EVENTLIST_2nd(_nc_eventlist * evl));
102 extern NCURSES_EXPORT(WORD) _nc_console_MapColor(bool fore, int color);
103 extern NCURSES_EXPORT(void) _nc_console_selectActiveHandle(void);
104 extern NCURSES_EXPORT(bool) _nc_console_get_SBI(void);
105 extern NCURSES_EXPORT(void) _nc_console_set_scrollback(bool normal, CONSOLE_SCREEN_BUFFER_INFO * info);
106 extern NCURSES_EXPORT(int) _nc_console_testmouse(SCREEN *,HANDLE,int EVENTLIST_2nd(_nc_eventlist*));
107 extern NCURSES_EXPORT(int) _nc_console_keyok(int keycode,int flag);
108 extern NCURSES_EXPORT(bool) _nc_console_keyExist(int keycode);
109 extern NCURSES_EXPORT(bool) _nc_console_checkinit(bool initFlag, bool assumeTermInfo);
110 extern NCURSES_EXPORT(int) _nc_console_vt_supported(void);
112 #ifdef _NC_CHECK_MINTTY
113 extern NCURSES_EXPORT(int) _nc_console_checkmintty(int fd, LPHANDLE pMinTTY);
116 #undef VALID_TERM_ENV
117 #define MS_TERMINAL "ms-terminal"
118 #define VALID_TERM_ENV(term_env, no_terminal) \
119 (term_env = (NonEmpty(term_env) \
121 : (_nc_console_vt_supported() \
127 * Various Console mode definitions
130 /* Flags to enable virtual Terminal processing */
131 #define VT_FLAG_OUT ENABLE_VIRTUAL_TERMINAL_PROCESSING
132 #define VT_FLAG_IN ENABLE_VIRTUAL_TERMINAL_INPUT
134 /* Default flags for input/output modes */
135 #define CONMODE_IN_DEFAULT (ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT)
136 #define CONMODE_OUT_DEFAULT (ENABLE_PROCESSED_OUTPUT | DISABLE_NEWLINE_AUTO_RETURN | ENABLE_LVB_GRID_WORLDWIDE)
138 /* Flags to reset from RAW/CBREAK */
139 #define CONMODE_NORAW (ENABLE_PROCESSED_INPUT|ENABLE_LINE_INPUT)
140 #define CONMODE_NOCBREAK (ENABLE_LINE_INPUT)
143 #if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
144 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
147 #define CON_NUMPAIRS 64
154 BOOL isTermInfoConsole;
163 WORD pairs[CON_NUMPAIRS];
165 CHAR_INFO *save_screen;
167 SMALL_RECT save_region;
168 CONSOLE_SCREEN_BUFFER_INFO SBI;
169 CONSOLE_SCREEN_BUFFER_INFO save_SBI;
170 CONSOLE_CURSOR_INFO save_CI;
174 extern NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE;
175 #define WINCONSOLE _nc_CONSOLE
177 #define TypeAlloca(type,count)(type*) _alloca(sizeof(type)*(size_t)(count))
179 #endif /* EVENTLIST_2nd */
185 #endif /* _WIN32 || _WIN64 */
187 #endif /* NC_WIN32_H */