diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-12-30 23:54:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-30 23:54:23 +0100 |
commit | 725da1feeb9a1e2c76533ef2df5e86b1b972c78b (patch) | |
tree | 3e4420a8a3f90c05f80c0e3dd7b42c773c0b63c1 /src/nvim/os | |
parent | 92806827a9f22828cdfd3573f6cf2c827808e641 (diff) | |
parent | 5749ecaf228f4a963a4e96ada831f902c73a1e80 (diff) | |
download | rneovim-725da1feeb9a1e2c76533ef2df5e86b1b972c78b.tar.gz rneovim-725da1feeb9a1e2c76533ef2df5e86b1b972c78b.tar.bz2 rneovim-725da1feeb9a1e2c76533ef2df5e86b1b972c78b.zip |
Merge #9401 from justinmk/pr-win-erw7
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/env.c | 25 | ||||
-rw-r--r-- | src/nvim/os/tty.c | 60 | ||||
-rw-r--r-- | src/nvim/os/tty.h | 7 |
3 files changed, 67 insertions, 25 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index eb4ea45ec1..c6794e4be5 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -945,31 +945,6 @@ bool os_setenv_append_path(const char *fname) return false; } -/// Returns true if the terminal can be assumed to silently ignore unknown -/// control codes. -bool os_term_is_nice(void) -{ -#if defined(__APPLE__) || defined(WIN32) - return true; -#else - const char *vte_version = os_getenv("VTE_VERSION"); - if ((vte_version && atoi(vte_version) >= 3900) - || os_getenv("KONSOLE_PROFILE_NAME") - || os_getenv("KONSOLE_DBUS_SESSION")) { - return true; - } - const char *termprg = os_getenv("TERM_PROGRAM"); - if (termprg && striequal(termprg, "iTerm.app")) { - return true; - } - const char *term = os_getenv("TERM"); - if (term && strncmp(term, "rxvt", 4) == 0) { - return true; - } - return false; -#endif -} - /// Returns true if `sh` looks like it resolves to "cmd.exe". bool os_shell_is_cmdexe(const char *sh) FUNC_ATTR_NONNULL_ALL diff --git a/src/nvim/os/tty.c b/src/nvim/os/tty.c new file mode 100644 index 0000000000..bd5b9b4506 --- /dev/null +++ b/src/nvim/os/tty.c @@ -0,0 +1,60 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + +// +// Terminal/console utils +// + +#include "nvim/os/os.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/tty.c.generated.h" +#endif + +#ifdef WIN32 +# if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING) +# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 +# endif +/// Guesses the terminal-type. Calls SetConsoleMode() and uv_set_vterm_state() +/// if appropriate. +/// +/// @param[in,out] term Name of the guessed terminal, statically-allocated +/// @param out_fd stdout file descriptor +void os_tty_guess_term(const char **term, int out_fd) +{ + bool winpty = (os_getenv("NVIM") != NULL); + + if (winpty) { + // Force TERM=win32con when running in winpty. + *term = "win32con"; + uv_set_vterm_state(UV_UNSUPPORTED); + return; + } + + bool conemu_ansi = strequal(os_getenv("ConEmuANSI"), "ON"); + bool vtp = false; + + HANDLE handle = (HANDLE)_get_osfhandle(out_fd); + DWORD dwMode; + if (handle != INVALID_HANDLE_VALUE && GetConsoleMode(handle, &dwMode)) { + dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; + if (SetConsoleMode(handle, dwMode)) { + vtp = true; + } + } + + if (*term == NULL) { + if (vtp) { + *term = "vtpcon"; + } else if (conemu_ansi) { + *term = "conemu"; + } else { + *term = "win32con"; + } + } + + if (conemu_ansi) { + uv_set_vterm_state(UV_SUPPORTED); + } +} +#endif diff --git a/src/nvim/os/tty.h b/src/nvim/os/tty.h new file mode 100644 index 0000000000..d771e63768 --- /dev/null +++ b/src/nvim/os/tty.h @@ -0,0 +1,7 @@ +#ifndef NVIM_OS_TTY_H +#define NVIM_OS_TTY_H + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/tty.h.generated.h" +#endif +#endif // NVIM_OS_TTY_H |