summaryrefslogtreecommitdiff
path: root/ncurses/tinfo/lib_win32con.c
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/tinfo/lib_win32con.c')
-rw-r--r--ncurses/tinfo/lib_win32con.c414
1 files changed, 215 insertions, 199 deletions
diff --git a/ncurses/tinfo/lib_win32con.c b/ncurses/tinfo/lib_win32con.c
index 2d6857aeb4a8..e92841a9eb48 100644
--- a/ncurses/tinfo/lib_win32con.c
+++ b/ncurses/tinfo/lib_win32con.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020-2021,2023 Thomas E. Dickey *
+ * Copyright 2020-2024,2025 Thomas E. Dickey *
* Copyright 1998-2009,2010 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -36,70 +36,65 @@
* TODO - GetMousePos(POINT * result) from ntconio.c
*/
+#define TTY int /* FIXME: TTY originalMode */
#include <curses.priv.h>
+#include <nc_win32.h>
-MODULE_ID("$Id: lib_win32con.c,v 1.14 2023/08/05 20:44:38 tom Exp $")
-
-#ifdef _NC_WINDOWS
-
-#ifdef _NC_MINGW
-#include <wchar.h>
-#else
-#include <tchar.h>
+#ifndef _O_BINARY
+#define _O_BINARY 0 /* FIXME: not defined in MSYS2 base */
#endif
-#include <io.h>
+MODULE_ID("$Id: lib_win32con.c,v 1.50 2025/12/27 21:49:45 tom Exp $")
-#if USE_WIDEC_SUPPORT
-#define write_screen WriteConsoleOutputW
-#define read_screen ReadConsoleOutputW
-#else
-#define write_screen WriteConsoleOutput
-#define read_screen ReadConsoleOutput
-#endif
+#if defined(_NC_WINDOWS)
+
+#define CONTROL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
static bool read_screen_data(void);
#define GenMap(vKey,key) MAKELONG(key, vKey)
+/* *INDENT-OFF* */
static const LONG keylist[] =
{
- GenMap(VK_PRIOR, KEY_PPAGE),
- GenMap(VK_NEXT, KEY_NPAGE),
- GenMap(VK_END, KEY_END),
- GenMap(VK_HOME, KEY_HOME),
- GenMap(VK_LEFT, KEY_LEFT),
- GenMap(VK_UP, KEY_UP),
- GenMap(VK_RIGHT, KEY_RIGHT),
- GenMap(VK_DOWN, KEY_DOWN),
+ GenMap(VK_PRIOR, KEY_PPAGE),
+ GenMap(VK_NEXT, KEY_NPAGE),
+ GenMap(VK_END, KEY_END),
+ GenMap(VK_HOME, KEY_HOME),
+ GenMap(VK_LEFT, KEY_LEFT),
+ GenMap(VK_UP, KEY_UP),
+ GenMap(VK_RIGHT, KEY_RIGHT),
+ GenMap(VK_DOWN, KEY_DOWN),
GenMap(VK_DELETE, KEY_DC),
GenMap(VK_INSERT, KEY_IC)
};
static const LONG ansi_keys[] =
{
- GenMap(VK_PRIOR, 'I'),
- GenMap(VK_NEXT, 'Q'),
- GenMap(VK_END, 'O'),
- GenMap(VK_HOME, 'H'),
- GenMap(VK_LEFT, 'K'),
- GenMap(VK_UP, 'H'),
- GenMap(VK_RIGHT, 'M'),
- GenMap(VK_DOWN, 'P'),
+ GenMap(VK_PRIOR, 'I'),
+ GenMap(VK_NEXT, 'Q'),
+ GenMap(VK_END, 'O'),
+ GenMap(VK_HOME, 'H'),
+ GenMap(VK_LEFT, 'K'),
+ GenMap(VK_UP, 'H'),
+ GenMap(VK_RIGHT, 'M'),
+ GenMap(VK_DOWN, 'P'),
GenMap(VK_DELETE, 'S'),
GenMap(VK_INSERT, 'R')
};
+/* *INDENT-ON* */
#define array_length(a) (sizeof(a)/sizeof(a[0]))
#define N_INI ((int)array_length(keylist))
#define FKEYS 24
#define MAPSIZE (FKEYS + N_INI)
+static bool console_initialized = FALSE;
+
/* A process can only have a single console, so it is safe
to maintain all the information about it in a single
static structure.
*/
NCURSES_EXPORT_VAR(ConsoleInfo) _nc_CONSOLE;
-static bool console_initialized = FALSE;
-#define EnsureInit() (void)(console_initialized ? TRUE : _nc_console_checkinit(TRUE, TRUE))
+#define EnsureInit() (void)(console_initialized ? TRUE : _nc_console_checkinit(USE_NAMED_PIPES))
#define REQUIRED_MAX_V (DWORD)10
#define REQUIRED_MIN_V (DWORD)0
@@ -119,10 +114,10 @@ _nc_console_vt_supported(void)
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
- T(("GetVersionEx returnedMajor=%ld, Minor=%ld, Build=%ld",
- osvi.dwMajorVersion,
- osvi.dwMinorVersion,
- osvi.dwBuildNumber));
+ T(("GetVersionEx returnedMajor=%lu, Minor=%lu, Build=%lu",
+ (unsigned long) osvi.dwMajorVersion,
+ (unsigned long) osvi.dwMinorVersion,
+ (unsigned long) osvi.dwBuildNumber));
if (osvi.dwMajorVersion >= REQUIRED_MAX_V) {
if (osvi.dwMajorVersion == REQUIRED_MAX_V) {
if (((osvi.dwMinorVersion == REQUIRED_MIN_V) &&
@@ -222,13 +217,15 @@ _nc_console_fd2handle(int fd)
T(("lib_win32con:validateHandle %d -> WINCONSOLE.hdl", fd));
} else if (hdl == WINCONSOLE.out) {
T(("lib_win32con:validateHandle %d -> WINCONSOLE.out", fd));
+ } else if (hdl == GetStdHandle(STD_INPUT_HANDLE)) {
+ T(("lib_win32con:validateHandle %d -> STD_INPUT_HANDLE", fd));
+ if (!WINCONSOLE.isTermInfoConsole && WINCONSOLE.progMode) {
+ hdl = WINCONSOLE.inp;
+ }
} else {
T(("lib_win32con:validateHandle %d maps to unknown HANDLE", fd));
hdl = INVALID_HANDLE_VALUE;
}
-#if 1
- assert(hdl != INVALID_HANDLE_VALUE);
-#endif
if (hdl != INVALID_HANDLE_VALUE) {
if (hdl != WINCONSOLE.inp && (!WINCONSOLE.isTermInfoConsole && WINCONSOLE.progMode)) {
if (hdl == WINCONSOLE.out && hdl != WINCONSOLE.hdl) {
@@ -240,6 +237,7 @@ _nc_console_fd2handle(int fd)
return hdl;
}
+#if defined(_NC_WINDOWS) && USE_WINCONMODE
NCURSES_EXPORT(int)
_nc_console_setmode(HANDLE hdl, const TTY * arg)
{
@@ -259,36 +257,20 @@ _nc_console_setmode(HANDLE hdl, const TTY * arg)
T(("lib_win32con:_nc_console_setmode %s", _nc_trace_ttymode(arg)));
if (hdl == WINCONSOLE.inp) {
dwFlag = arg->dwFlagIn | ENABLE_MOUSE_INPUT | VT_FLAG_IN;
- if (WINCONSOLE.isTermInfoConsole)
- dwFlag |= (VT_FLAG_IN);
- else
- dwFlag &= (DWORD) ~ (VT_FLAG_IN);
TRCTTYIN(dwFlag);
SetConsoleMode(hdl, dwFlag);
alt = OutHandle();
dwFlag = arg->dwFlagOut;
- if (WINCONSOLE.isTermInfoConsole)
- dwFlag |= (VT_FLAG_OUT);
- else
- dwFlag |= (VT_FLAG_OUT);
TRCTTYOUT(dwFlag);
SetConsoleMode(alt, dwFlag);
} else {
dwFlag = arg->dwFlagOut;
- if (WINCONSOLE.isTermInfoConsole)
- dwFlag |= (VT_FLAG_OUT);
- else
- dwFlag |= (VT_FLAG_OUT);
TRCTTYOUT(dwFlag);
SetConsoleMode(hdl, dwFlag);
alt = WINCONSOLE.inp;
dwFlag = arg->dwFlagIn | ENABLE_MOUSE_INPUT;
- if (WINCONSOLE.isTermInfoConsole)
- dwFlag |= (VT_FLAG_IN);
- else
- dwFlag &= (DWORD) ~ (VT_FLAG_IN);
TRCTTYIN(dwFlag);
SetConsoleMode(alt, dwFlag);
T(("effective mode set %s", _nc_trace_ttymode(&TRCTTY)));
@@ -330,6 +312,7 @@ _nc_console_getmode(HANDLE hdl, TTY * arg)
T(("lib_win32con:_nc_console_getmode %s", _nc_trace_ttymode(arg)));
return (code);
}
+#endif /* defined(_NC_WINDOWS) && USE_WINCONMODE */
NCURSES_EXPORT(int)
_nc_console_flush(HANDLE hdl)
@@ -404,7 +387,7 @@ save_original_screen(void)
return result;
}
-#if 0
+#if defined(_NC_WINDOWS)
static bool
restore_original_screen(void)
{
@@ -426,7 +409,7 @@ restore_original_screen(void)
bufferCoord,
&save_region)) {
result = TRUE;
- mvcur(-1, -1, LINES - 2, 0);
+ SetConsoleCursorPosition(WINCONSOLE.hdl, WINCONSOLE.save_SBI.dwCursorPosition);
T(("... restore original screen contents ok %dx%d (%d,%d - %d,%d)",
WINCONSOLE.save_size.Y,
WINCONSOLE.save_size.X,
@@ -455,11 +438,13 @@ read_screen_data(void)
want = (size_t) (WINCONSOLE.save_size.X * WINCONSOLE.save_size.Y);
- if ((WINCONSOLE.save_screen = malloc(want * sizeof(CHAR_INFO))) != 0) {
- bufferCoord.X = (SHORT) (WINCONSOLE.window_only ?
- WINCONSOLE.SBI.srWindow.Left : 0);
- bufferCoord.Y = (SHORT) (WINCONSOLE.window_only ?
- WINCONSOLE.SBI.srWindow.Top : 0);
+ if ((WINCONSOLE.save_screen = malloc(want * sizeof(CHAR_INFO))) != NULL) {
+ bufferCoord.X = (SHORT) (WINCONSOLE.window_only
+ ? WINCONSOLE.SBI.srWindow.Left
+ : 0);
+ bufferCoord.Y = (SHORT) (WINCONSOLE.window_only
+ ? WINCONSOLE.SBI.srWindow.Top
+ : 0);
T(("... reading console %s %dx%d into %d,%d - %d,%d at %d,%d",
WINCONSOLE.window_only ? "window" : "buffer",
@@ -617,7 +602,7 @@ tdiff(FILETIME fstart, FILETIME fend)
static int
Adjust(int milliseconds, int diff)
{
- if (milliseconds != INFINITY) {
+ if (milliseconds != NC_INFINITY) {
milliseconds -= diff;
if (milliseconds < 0)
milliseconds = 0;
@@ -632,7 +617,7 @@ Adjust(int milliseconds, int diff)
RIGHTMOST_BUTTON_PRESSED)
static mmask_t
-decode_mouse(SCREEN *sp, int mask)
+decode_mouse(const SCREEN *sp, int mask)
{
mmask_t result = 0;
@@ -668,7 +653,9 @@ decode_mouse(SCREEN *sp, int mask)
return result;
}
-#define AdjustY() (WINCONSOLE.buffered ? 0 : (int) WINCONSOLE.SBI.srWindow.Top)
+#define AdjustY() (WINCONSOLE.buffered \
+ ? 0 \
+ : (int) WINCONSOLE.SBI.srWindow.Top)
static bool
handle_mouse(SCREEN *sp, MOUSE_EVENT_RECORD mer)
@@ -828,7 +815,7 @@ _nc_console_keyExist(int keycode)
NCURSES_EXPORT(int)
_nc_console_twait(
- SCREEN *sp,
+ const SCREEN *sp,
HANDLE hdl,
int mode,
int milliseconds,
@@ -837,7 +824,7 @@ _nc_console_twait(
{
INPUT_RECORD inp_rec;
BOOL b;
- DWORD nRead = 0, rc = (DWORD) (-1);
+ DWORD nRead = 0, rc = WAIT_FAILED;
int code = 0;
FILETIME fstart;
FILETIME fend;
@@ -848,9 +835,10 @@ _nc_console_twait(
(void) evl; /* TODO: implement wgetch-events */
#endif
-#define IGNORE_CTRL_KEYS (SHIFT_PRESSED|LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED| \
- LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)
-#define CONSUME() ReadConsoleInput(hdl, &inp_rec, 1, &nRead)
+#define IGNORE_CTRL_KEYS (SHIFT_PRESSED | \
+ LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED | \
+ LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
+#define CONSUME() read_keycode(hdl, &inp_rec, 1, &nRead)
assert(sp);
@@ -858,7 +846,7 @@ _nc_console_twait(
hdl, milliseconds, mode));
if (milliseconds < 0)
- milliseconds = INFINITY;
+ milliseconds = NC_INFINITY;
memset(&inp_rec, 0, sizeof(inp_rec));
@@ -881,14 +869,13 @@ _nc_console_twait(
T(("twait:err GetNumberOfConsoleInputEvents"));
}
if (isNoDelay && b) {
- T(("twait: Events Available: %ld", nRead));
+ T(("twait: Events Available: %lu", (unsigned long) nRead));
if (nRead == 0) {
code = 0;
goto end;
} else {
DWORD n = 0;
- INPUT_RECORD *pInpRec =
- TypeAlloca(INPUT_RECORD, nRead);
+ MakeArray(pInpRec, INPUT_RECORD, nRead);
if (pInpRec != NULL) {
DWORD i;
BOOL f;
@@ -927,13 +914,13 @@ _nc_console_twait(
switch (inp_rec.EventType) {
case KEY_EVENT:
if (mode & TW_INPUT) {
- WORD vk =
- inp_rec.Event.KeyEvent.wVirtualKeyCode;
- char ch =
- inp_rec.Event.KeyEvent.uChar.AsciiChar;
+ WORD vk = inp_rec.Event.KeyEvent.wVirtualKeyCode;
+ WORD ch = inp_rec.Event.KeyEventChar;
+
T(("twait:event KEY_EVENT"));
T(("twait vk=%d, ch=%d, keydown=%d",
vk, ch, inp_rec.Event.KeyEvent.bKeyDown));
+
if (inp_rec.Event.KeyEvent.bKeyDown) {
T(("twait:event KeyDown"));
if (!WINCONSOLE.isTermInfoConsole &&
@@ -964,7 +951,7 @@ _nc_console_twait(
continue;
/* e.g., FOCUS_EVENT */
default:
- T(("twait:event Tyoe %d", inp_rec.EventType));
+ T(("twait:event Type %d", inp_rec.EventType));
CONSUME();
_nc_console_selectActiveHandle();
continue;
@@ -986,7 +973,7 @@ _nc_console_twait(
end:
TR(TRACE_IEVENT, ("end twait: returned %d (%lu), remaining time %d msec",
- code, GetLastError(), milliseconds));
+ code, (unsigned long) GetLastError(), milliseconds));
if (timeleft)
*timeleft = milliseconds;
@@ -996,7 +983,7 @@ _nc_console_twait(
NCURSES_EXPORT(int)
_nc_console_testmouse(
- SCREEN *sp,
+ const SCREEN *sp,
HANDLE hdl,
int delay
EVENTLIST_2nd(_nc_eventlist * evl))
@@ -1037,7 +1024,7 @@ _nc_console_read(
T((T_CALLED("lib_win32con::_nc_console_read(%p)"), sp));
- while ((b = ReadConsoleInput(hdl, &inp_rec, 1, &nRead))) {
+ while ((b = read_keycode(hdl, &inp_rec, 1, &nRead))) {
if (b && nRead > 0) {
if (rc < 0)
rc = 0;
@@ -1045,7 +1032,7 @@ _nc_console_read(
if (inp_rec.EventType == KEY_EVENT) {
if (!inp_rec.Event.KeyEvent.bKeyDown)
continue;
- *buf = (int) inp_rec.Event.KeyEvent.uChar.AsciiChar;
+ *buf = (int) inp_rec.Event.KeyEventChar;
vk = inp_rec.Event.KeyEvent.wVirtualKeyCode;
/*
* There are 24 virtual function-keys, and typically
@@ -1068,6 +1055,16 @@ _nc_console_read(
ungetch('\0');
*buf = AnsiKey(vk);
}
+ } else if (vk == VK_BACK) {
+ if (!(inp_rec.Event.KeyEvent.dwControlKeyState
+ & (SHIFT_PRESSED | CONTROL_PRESSED))) {
+ *buf = KEY_BACKSPACE;
+ }
+ } else if (vk == VK_TAB) {
+ if ((inp_rec.Event.KeyEvent.dwControlKeyState
+ & (SHIFT_PRESSED | CONTROL_PRESSED))) {
+ *buf = KEY_BTAB;
+ }
}
break;
} else if (inp_rec.EventType == MOUSE_EVENT) {
@@ -1083,6 +1080,7 @@ _nc_console_read(
returnCode(rc);
}
+#if USE_TERM_DRIVER && (USE_NAMED_PIPES || defined(USE_WIN32CON_DRIVER))
/* Our replacement for the systems _isatty to include also
a test for mintty. This is called from the NC_ISATTY macro
defined in curses.priv.h
@@ -1098,7 +1096,7 @@ _nc_console_isatty(int fd)
int result = 0;
T((T_CALLED("lib_win32con::_nc_console_isatty(%d"), fd));
- if (_isatty(fd))
+ if (isatty(fd))
result = 1;
#ifdef _NC_CHECK_MINTTY
else {
@@ -1114,137 +1112,155 @@ _nc_console_isatty(int fd)
#endif
returnCode(result);
}
+#endif /* USE_TERM_DRIVER && (USE_NAMED_PIPES || defined(USE_WIN32CON_DRIVER)) */
+#if USE_WINCONMODE
NCURSES_EXPORT(bool)
-_nc_console_checkinit(bool initFlag, bool assumeTermInfo)
+_nc_console_checkinit(bool assumeTermInfo)
{
bool res = FALSE;
- T((T_CALLED("lib_win32con::_nc_console_checkinit(initFlag=%d, assumeTermInfo=%d)"),
- initFlag, assumeTermInfo));
-
- if (!initFlag) {
- res = console_initialized;
- } else {
- /* initialize once, or not at all */
- if (!console_initialized) {
- int i;
- DWORD num_buttons;
- WORD a;
- BOOL buffered = FALSE;
- BOOL b;
-
- START_TRACE();
- WINCONSOLE.isTermInfoConsole = assumeTermInfo;
-
- WINCONSOLE.map = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
- WINCONSOLE.rmap = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
- WINCONSOLE.ansi_map = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
-
- for (i = 0; i < (N_INI + FKEYS); i++) {
- if (i < N_INI) {
- WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
- (DWORD) keylist[i];
- WINCONSOLE.ansi_map[i] = (DWORD) ansi_keys[i];
- } else {
- WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
- (DWORD) GenMap((VK_F1 + (i - N_INI)),
- (KEY_F(1) + (i - N_INI)));
- WINCONSOLE.ansi_map[i] =
- (DWORD) GenMap((VK_F1 + (i - N_INI)),
- (';' + (i - N_INI)));
- }
- }
- qsort(WINCONSOLE.ansi_map,
- (size_t) (MAPSIZE),
- sizeof(keylist[0]),
- keycompare);
- qsort(WINCONSOLE.map,
- (size_t) (MAPSIZE),
- sizeof(keylist[0]),
- keycompare);
- qsort(WINCONSOLE.rmap,
- (size_t) (MAPSIZE),
- sizeof(keylist[0]),
- rkeycompare);
-
- if (GetNumberOfConsoleMouseButtons(&num_buttons)) {
- WINCONSOLE.numButtons = (int) num_buttons;
+ T((T_CALLED("lib_win32con::_nc_console_checkinit(assumeTermInfo=%d)"),
+ assumeTermInfo));
+
+ /* initialize once, or not at all */
+ if (!console_initialized) {
+ int i;
+ DWORD num_buttons;
+ WORD a;
+ BOOL buffered = FALSE;
+ BOOL b;
+
+ START_TRACE();
+ WINCONSOLE.isTermInfoConsole = assumeTermInfo;
+
+ WINCONSOLE.map = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
+ WINCONSOLE.rmap = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
+ WINCONSOLE.ansi_map = (LPDWORD) malloc(sizeof(DWORD) * MAPSIZE);
+
+ for (i = 0; i < (N_INI + FKEYS); i++) {
+ if (i < N_INI) {
+ WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
+ (DWORD) keylist[i];
+ WINCONSOLE.ansi_map[i] = (DWORD) ansi_keys[i];
} else {
- WINCONSOLE.numButtons = 1;
+ WINCONSOLE.rmap[i] = WINCONSOLE.map[i] =
+ (DWORD) GenMap((VK_F1 + (i - N_INI)),
+ (KEY_F(1) + (i - N_INI)));
+ WINCONSOLE.ansi_map[i] =
+ (DWORD) GenMap((VK_F1 + (i - N_INI)),
+ (';' + (i - N_INI)));
}
+ }
+ qsort(WINCONSOLE.ansi_map,
+ (size_t) (MAPSIZE),
+ sizeof(keylist[0]),
+ keycompare);
+ qsort(WINCONSOLE.map,
+ (size_t) (MAPSIZE),
+ sizeof(keylist[0]),
+ keycompare);
+ qsort(WINCONSOLE.rmap,
+ (size_t) (MAPSIZE),
+ sizeof(keylist[0]),
+ rkeycompare);
+
+ if (GetNumberOfConsoleMouseButtons(&num_buttons)) {
+ WINCONSOLE.numButtons = (int) num_buttons;
+ } else {
+ WINCONSOLE.numButtons = 1;
+ }
- a = _nc_console_MapColor(true, COLOR_WHITE) |
- _nc_console_MapColor(false, COLOR_BLACK);
- for (i = 0; i < CON_NUMPAIRS; i++)
- WINCONSOLE.pairs[i] = a;
+ a = _nc_console_MapColor(true, COLOR_WHITE) |
+ _nc_console_MapColor(false, COLOR_BLACK);
+ for (i = 0; i < CON_NUMPAIRS; i++)
+ WINCONSOLE.pairs[i] = a;
#define SaveConsoleMode(handle, value) \
- GetConsoleMode(WINCONSOLE.handle, &WINCONSOLE.originalMode.value)
+ GetConsoleMode(WINCONSOLE.handle, &WINCONSOLE.originalMode.value)
- if (WINCONSOLE.isTermInfoConsole) {
- WINCONSOLE.inp = GetStdHandle(STD_INPUT_HANDLE);
- WINCONSOLE.out = GetStdHandle(STD_OUTPUT_HANDLE);
- WINCONSOLE.hdl = WINCONSOLE.out;
+ if (WINCONSOLE.isTermInfoConsole) {
+ WINCONSOLE.inp = GetStdHandle(STD_INPUT_HANDLE);
+ WINCONSOLE.out = GetStdHandle(STD_OUTPUT_HANDLE);
+ WINCONSOLE.hdl = WINCONSOLE.out;
+
+ SaveConsoleMode(inp, dwFlagIn);
+ SaveConsoleMode(out, dwFlagOut);
- SaveConsoleMode(inp, dwFlagIn);
- SaveConsoleMode(out, dwFlagOut);
+ } else {
+ b = AllocConsole();
+
+ if (!b)
+ b = AttachConsole(ATTACH_PARENT_PROCESS);
+
+ WINCONSOLE.inp = GetDirectHandle("CONIN$", FILE_SHARE_READ);
+ WINCONSOLE.out = GetDirectHandle("CONOUT$", FILE_SHARE_WRITE);
+ SaveConsoleMode(inp, dwFlagIn);
+ SaveConsoleMode(out, dwFlagOut);
+
+ if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) {
+ WINCONSOLE.hdl = WINCONSOLE.out;
+ buffered = FALSE;
+ T(("... will not buffer console"));
} else {
- b = AllocConsole();
-
- if (!b)
- b = AttachConsole(ATTACH_PARENT_PROCESS);
-
- WINCONSOLE.inp = GetDirectHandle("CONIN$", FILE_SHARE_READ);
- WINCONSOLE.out = GetDirectHandle("CONOUT$", FILE_SHARE_WRITE);
-
- SaveConsoleMode(inp, dwFlagIn);
- SaveConsoleMode(out, dwFlagOut);
-
- if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) {
- WINCONSOLE.hdl = WINCONSOLE.out;
- T(("... will not buffer console"));
- } else {
- T(("... creating console buffer"));
- WINCONSOLE.hdl =
- CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- CONSOLE_TEXTMODE_BUFFER,
- NULL);
- buffered = TRUE;
- }
+ T(("... creating console buffer"));
+ WINCONSOLE.hdl =
+ CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ CONSOLE_TEXTMODE_BUFFER,
+ NULL);
+ buffered = TRUE;
}
+ }
- /* We set binary I/O even when using the console
- driver to cover the situation, that the
- TERM variable is set to #win32con, but actually
- Windows supports virtual terminal processing.
- So if terminfo functions are used in this setup,
- they actually may work.
- */
- _setmode(fileno(stdin), _O_BINARY);
- _setmode(fileno(stdout), _O_BINARY);
-
- if (WINCONSOLE.hdl != INVALID_HANDLE_VALUE) {
- WINCONSOLE.buffered = buffered;
- _nc_console_get_SBI();
- WINCONSOLE.save_SBI = WINCONSOLE.SBI;
- if (!buffered) {
- save_original_screen();
- _nc_console_set_scrollback(FALSE, &WINCONSOLE.SBI);
- }
- GetConsoleCursorInfo(WINCONSOLE.hdl, &WINCONSOLE.save_CI);
- T(("... initial cursor is %svisible, %d%%",
- (WINCONSOLE.save_CI.bVisible ? "" : "not-"),
- (int) WINCONSOLE.save_CI.dwSize));
+ /* We set binary I/O even when using the console
+ driver to cover the situation, that the
+ TERM variable is set to #win32con, but actually
+ Windows supports virtual terminal processing.
+ So if terminfo functions are used in this setup,
+ they actually may work.
+ */
+ _setmode(fileno(stdin), _O_BINARY);
+ _setmode(fileno(stdout), _O_BINARY);
+
+ if (WINCONSOLE.hdl != INVALID_HANDLE_VALUE) {
+ WINCONSOLE.buffered = buffered;
+ _nc_console_get_SBI();
+ WINCONSOLE.save_SBI = WINCONSOLE.SBI;
+ if (!buffered) {
+ save_original_screen();
+ _nc_console_set_scrollback(FALSE, &WINCONSOLE.SBI);
}
+ GetConsoleCursorInfo(WINCONSOLE.hdl, &WINCONSOLE.save_CI);
+ T(("... initial cursor is %svisible, %d%%",
+ (WINCONSOLE.save_CI.bVisible ? "" : "not-"),
+ (int) WINCONSOLE.save_CI.dwSize));
+ }
+
+ WINCONSOLE.initialized = TRUE;
+ console_initialized = TRUE;
+ }
+ res = (WINCONSOLE.hdl != INVALID_HANDLE_VALUE);
+ returnBool(res);
+}
+#endif /* USE_WINCONMODE */
+
+NCURSES_EXPORT(bool)
+_nc_console_restore(void)
+{
+ bool res = FALSE;
- WINCONSOLE.initialized = TRUE;
- console_initialized = TRUE;
+ T((T_CALLED("lib_win32con::_nc_console_restore")));
+ if (WINCONSOLE.hdl != INVALID_HANDLE_VALUE) {
+ res = TRUE;
+ if (!WINCONSOLE.buffered) {
+ _nc_console_set_scrollback(TRUE, &WINCONSOLE.save_SBI);
+ if (!restore_original_screen())
+ res = FALSE;
}
- res = (WINCONSOLE.hdl != INVALID_HANDLE_VALUE);
+ SetConsoleCursorInfo(WINCONSOLE.hdl, &WINCONSOLE.save_CI);
}
returnBool(res);
}