mirror of
https://github.com/neovim/neovim.git
synced 2025-12-09 08:02:38 +00:00
Merge pull request #11803 from erw7/virtual-terminal-input
[RDY] win/TUI: Use virtual terminal input if available
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
#include "nvim/rbuffer.h"
|
||||
#include "nvim/macros.h"
|
||||
#include "nvim/event/stream.h"
|
||||
#ifdef WIN32
|
||||
# include "nvim/os/os_win_console.h"
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "event/stream.c.generated.h"
|
||||
@@ -62,6 +65,11 @@ void stream_init(Loop *loop, Stream *stream, int fd, uv_stream_t *uvstream)
|
||||
if (type == UV_TTY) {
|
||||
uv_tty_init(&loop->uv, &stream->uv.tty, fd, 0);
|
||||
uv_tty_set_mode(&stream->uv.tty, UV_TTY_MODE_RAW);
|
||||
DWORD dwMode;
|
||||
if (GetConsoleMode(stream->uv.tty.handle, &dwMode)) {
|
||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
||||
SetConsoleMode(stream->uv.tty.handle, dwMode);
|
||||
}
|
||||
stream->uvstream = STRUCT_CAST(uv_stream_t, &stream->uv.tty);
|
||||
} else {
|
||||
#endif
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/os/input.h"
|
||||
#include "nvim/os/os_win_console.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "os/os_win_console.c.generated.h"
|
||||
#endif
|
||||
|
||||
|
||||
int os_get_conin_fd(void)
|
||||
{
|
||||
const HANDLE conin_handle = CreateFile("CONIN$",
|
||||
@@ -40,3 +46,29 @@ void os_replace_stdout_and_stderr_to_conout(void)
|
||||
const int conerr_fd = _open_osfhandle((intptr_t)conout_handle, 0);
|
||||
assert(conerr_fd == STDERR_FILENO);
|
||||
}
|
||||
|
||||
void os_set_vtp(bool enable)
|
||||
{
|
||||
static TriState is_legacy = kNone;
|
||||
if (is_legacy == kNone) {
|
||||
uv_tty_vtermstate_t state;
|
||||
uv_tty_get_vterm_state(&state);
|
||||
is_legacy = (state == UV_TTY_UNSUPPORTED) ? kTrue : kFalse;
|
||||
}
|
||||
if (!is_legacy && !os_has_vti()) {
|
||||
uv_tty_set_vterm_state(enable ? UV_TTY_SUPPORTED : UV_TTY_UNSUPPORTED);
|
||||
}
|
||||
}
|
||||
|
||||
static bool os_has_vti(void)
|
||||
{
|
||||
static TriState has_vti = kNone;
|
||||
if (has_vti == kNone) {
|
||||
HANDLE handle = (HANDLE)_get_osfhandle(input_global_fd());
|
||||
DWORD dwMode;
|
||||
if (handle != INVALID_HANDLE_VALUE && GetConsoleMode(handle, &dwMode)) {
|
||||
has_vti = !!(dwMode & ENABLE_VIRTUAL_TERMINAL_INPUT) ? kTrue : kFalse;
|
||||
}
|
||||
}
|
||||
return has_vti == kTrue;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,8 @@
|
||||
# include "os/os_win_console.h.generated.h"
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||
# define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
|
||||
#endif
|
||||
|
||||
#endif // NVIM_OS_OS_WIN_CONSOLE_H
|
||||
|
||||
@@ -28,7 +28,7 @@ void os_tty_guess_term(const char **term, int out_fd)
|
||||
if (winpty) {
|
||||
// Force TERM=win32con when running in winpty.
|
||||
*term = "win32con";
|
||||
uv_set_vterm_state(UV_UNSUPPORTED);
|
||||
uv_tty_set_vterm_state(UV_TTY_UNSUPPORTED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void os_tty_guess_term(const char **term, int out_fd)
|
||||
}
|
||||
|
||||
if (conemu_ansi) {
|
||||
uv_set_vterm_state(UV_SUPPORTED);
|
||||
uv_tty_set_vterm_state(UV_TTY_SUPPORTED);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/signal.h"
|
||||
#include "nvim/os/tty.h"
|
||||
#ifdef WIN32
|
||||
# include "nvim/os/os_win_console.h"
|
||||
#endif
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/ui_bridge.h"
|
||||
@@ -1015,8 +1018,22 @@ static void tui_mouse_on(UI *ui)
|
||||
{
|
||||
TUIData *data = ui->data;
|
||||
if (!data->mouse_enabled) {
|
||||
#ifdef WIN32
|
||||
// Windows versions with vtp(ENABLE_VIRTUAL_TERMINAL_PROCESSING) and
|
||||
// no vti(ENABLE_VIRTUAL_TERMINAL_INPUT) will need to use mouse traking of
|
||||
// libuv. For this reason, vtp (vterm) state of libuv is temporarily
|
||||
// disabled because the control sequence needs to be processed by libuv
|
||||
// instead of Windows vtp.
|
||||
// ref. https://docs.microsoft.com/en-us/windows/console/setconsolemode
|
||||
flush_buf(ui);
|
||||
os_set_vtp(false);
|
||||
#endif
|
||||
unibi_out_ext(ui, data->unibi_ext.enable_mouse);
|
||||
data->mouse_enabled = true;
|
||||
#ifdef WIN32
|
||||
flush_buf(ui);
|
||||
os_set_vtp(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1024,8 +1041,22 @@ static void tui_mouse_off(UI *ui)
|
||||
{
|
||||
TUIData *data = ui->data;
|
||||
if (data->mouse_enabled) {
|
||||
#ifdef WIN32
|
||||
// Windows versions with vtp(ENABLE_VIRTUAL_TERMINAL_PROCESSING) and
|
||||
// no vti(ENABLE_VIRTUAL_TERMINAL_INPUT) will need to use mouse traking of
|
||||
// libuv. For this reason, vtp (vterm) state of libuv is temporarily
|
||||
// disabled because the control sequence needs to be processed by libuv
|
||||
// instead of Windows vtp.
|
||||
// ref. https://docs.microsoft.com/en-us/windows/console/setconsolemode
|
||||
flush_buf(ui);
|
||||
os_set_vtp(false);
|
||||
#endif
|
||||
unibi_out_ext(ui, data->unibi_ext.disable_mouse);
|
||||
data->mouse_enabled = false;
|
||||
#ifdef WIN32
|
||||
flush_buf(ui);
|
||||
os_set_vtp(true);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
third-party/CMakeLists.txt
vendored
9
third-party/CMakeLists.txt
vendored
@@ -135,12 +135,11 @@ include(ExternalProject)
|
||||
|
||||
if(WIN32)
|
||||
# "nvim" branch of https://github.com/neovim/libuv
|
||||
set(LIBUV_URL https://github.com/neovim/libuv/archive/d5ff3004d26b9bb863b76247399a9c72a0ff184c.tar.gz)
|
||||
set(LIBUV_SHA256 0f5dfd92269713ed275273966ed73578fc68db669c509b01210cd58c1cf6361d)
|
||||
set(LIBUV_URL https://github.com/neovim/libuv/archive/b899d12b0d56d217f31222da83f8c398355b69ef.tar.gz)
|
||||
set(LIBUV_SHA256 eb7e37b824887e1b31a4e31d1d9bad4c03d8b98532d9cce5f67a3b70495a4b2a)
|
||||
else()
|
||||
# blueyed/nvim-fixes (for *BSD build fixes).
|
||||
set(LIBUV_URL https://github.com/blueyed/libuv/archive/2af4cf2.tar.gz)
|
||||
set(LIBUV_SHA256 SKIP)
|
||||
set(LIBUV_URL https://github.com/libuv/libuv/archive/v1.34.2.tar.gz)
|
||||
set(LIBUV_SHA256 0d9d38558b45c006c1ea4e8529bae64caf8becda570295ea74e3696362aeb7f2)
|
||||
endif()
|
||||
|
||||
set(MSGPACK_URL https://github.com/msgpack/msgpack-c/releases/download/cpp-3.0.0/msgpack-3.0.0.tar.gz)
|
||||
|
||||
Reference in New Issue
Block a user