aboutsummaryrefslogtreecommitdiff
path: root/ncurses/win32con/win_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/win32con/win_driver.c')
-rw-r--r--ncurses/win32con/win_driver.c97
1 files changed, 52 insertions, 45 deletions
diff --git a/ncurses/win32con/win_driver.c b/ncurses/win32con/win_driver.c
index 72a9cf53525f..2425b3a44ce6 100644
--- a/ncurses/win32con/win_driver.c
+++ b/ncurses/win32con/win_driver.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018,2020 Thomas E. Dickey *
+ * Copyright 2018-2021,2023 Thomas E. Dickey *
* Copyright 2008-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -55,7 +55,9 @@
#define CUR TerminalType(my_term).
-MODULE_ID("$Id: win_driver.c,v 1.66 2020/03/01 00:18:49 tom Exp $")
+#define CONTROL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
+
+MODULE_ID("$Id: win_driver.c,v 1.74 2023/09/16 16:27:44 tom Exp $")
#define TypeAlloca(type,count) (type*) _alloca(sizeof(type) * (size_t) (count))
@@ -82,39 +84,40 @@ static bool okConsoleHandle(TERMINAL_CONTROL_BLOCK *);
#define write_screen WriteConsoleOutput
#define read_screen ReadConsoleOutput
#endif
-
+/* *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 N_INI ((int)array_length(keylist))
#define FKEYS 24
#define MAPSIZE (FKEYS + N_INI)
#define NUMPAIRS 64
-/* A process can only have a single console, so it's safe
+/* A process can only have a single console, so it is safe
to maintain all the information about it in a single
static structure.
*/
@@ -123,7 +126,6 @@ static struct {
BOOL buffered;
BOOL window_only;
BOOL progMode;
- BOOL isMinTTY;
BOOL isTermInfoConsole;
HANDLE out;
HANDLE inp;
@@ -486,7 +488,7 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
Width = screen_columns(sp);
Height = screen_lines(sp);
- nonempty = min(Height, NewScreen(sp)->_maxy + 1);
+ nonempty = Min(Height, NewScreen(sp)->_maxy + 1);
T(("... %dx%d clear cur:%d new:%d",
Height, Width,
@@ -610,6 +612,12 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
returnCode(result);
}
+#ifdef __MING32__
+#define SysISATTY(fd) _isatty(fd)
+#else
+#define SysISATTY(fd) isatty(fd)
+#endif
+
static bool
wcon_CanHandle(TERMINAL_CONTROL_BLOCK * TCB,
const char *tname,
@@ -641,6 +649,8 @@ wcon_CanHandle(TERMINAL_CONTROL_BLOCK * TCB,
}
} else if (tname != 0 && stricmp(tname, "unknown") == 0) {
code = TRUE;
+ } else if (SysISATTY(TCB->term.Filedes)) {
+ code = TRUE;
}
/*
@@ -1476,10 +1486,10 @@ Adjust(int milliseconds, int diff)
FROM_LEFT_4TH_BUTTON_PRESSED | \
RIGHTMOST_BUTTON_PRESSED)
-static int
+static mmask_t
decode_mouse(SCREEN *sp, int mask)
{
- int result = 0;
+ mmask_t result = 0;
(void) sp;
assert(sp && console_initialized);
@@ -1668,14 +1678,14 @@ handle_mouse(SCREEN *sp, MOUSE_EVENT_RECORD mer)
if (sp->_drv_mouse_new_buttons) {
- work.bstate |= (mmask_t) decode_mouse(sp, sp->_drv_mouse_new_buttons);
+ work.bstate |= decode_mouse(sp, sp->_drv_mouse_new_buttons);
} else {
/* cf: BUTTON_PRESSED, BUTTON_RELEASED */
- work.bstate |= (mmask_t) (decode_mouse(sp,
- sp->_drv_mouse_old_buttons)
- >> 1);
+ work.bstate |= (decode_mouse(sp,
+ sp->_drv_mouse_old_buttons)
+ >> 1);
result = TRUE;
}
@@ -1867,7 +1877,7 @@ get_handle(int fd)
#if WINVER >= 0x0600
/* This function tests, whether or not the ncurses application
is running as a descendant of MSYS2/cygwin mintty terminal
- application. mintty doesn't use Windows Console for it's screen
+ application. mintty doesn't use Windows Console for its screen
I/O, so the native Windows _isatty doesn't recognize it as
character device. But we can discover we are at the end of an
Pipe and can query to server side of the pipe, looking whether
@@ -1957,11 +1967,6 @@ _nc_mingw_isatty(int fd)
{
int result = 0;
-#ifdef __MING32__
-#define SysISATTY(fd) _isatty(fd)
-#else
-#define SysISATTY(fd) isatty(fd)
-#endif
if (SysISATTY(fd)) {
result = 1;
} else {
@@ -1974,7 +1979,7 @@ _nc_mingw_isatty(int fd)
/* This is used when running in terminfo mode to discover,
whether or not the "terminal" is actually a Windows
- Console. It's the responsibility of the console to deal
+ Console. It is the responsibility of the console to deal
with the terminal escape sequences that are sent by
terminfo.
*/
@@ -2126,9 +2131,9 @@ _nc_mingw_console_read(
*buf = (int) inp_rec.Event.KeyEvent.uChar.AsciiChar;
vk = inp_rec.Event.KeyEvent.wVirtualKeyCode;
/*
- * There are 24 virtual function-keys, and typically
- * 12 function-keys on a keyboard. Use the shift-modifier
- * to provide the remaining 12 keys.
+ * There are 24 virtual function-keys (defined in winuser.h),
+ * and typically 12 function-keys on a keyboard. Use the
+ * shift-modifier to provide the remaining keys.
*/
if (vk >= VK_F1 && vk <= VK_F12) {
if (inp_rec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) {
@@ -2145,6 +2150,11 @@ _nc_mingw_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;
+ }
}
break;
} else if (inp_rec.EventType == MOUSE_EVENT) {
@@ -2172,9 +2182,6 @@ InitConsole(void)
BOOL b;
START_TRACE();
- if (_nc_mingw_isatty(0)) {
- CON.isMinTTY = TRUE;
- }
for (i = 0; i < (N_INI + FKEYS); i++) {
if (i < N_INI) {
@@ -2213,14 +2220,14 @@ InitConsole(void)
for (i = 0; i < NUMPAIRS; i++)
CON.pairs[i] = a;
- CON.inp = GetStdHandle(STD_INPUT_HANDLE);
- CON.out = GetStdHandle(STD_OUTPUT_HANDLE);
-
b = AllocConsole();
if (!b)
b = AttachConsole(ATTACH_PARENT_PROCESS);
+ CON.inp = GetDirectHandle("CONIN$", FILE_SHARE_READ);
+ CON.out = GetDirectHandle("CONOUT$", FILE_SHARE_WRITE);
+
if (getenv("NCGDB") || getenv("NCURSES_CONSOLE2")) {
T(("... will not buffer console"));
buffered = FALSE;
@@ -2228,7 +2235,7 @@ InitConsole(void)
} else {
T(("... creating console buffer"));
CON.hdl = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
- 0,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL);