aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/os_win_console.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-03-09 14:57:57 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-03-09 14:57:57 -0700
commitc324271b99eee4c621463f368914d57cd729bd9c (patch)
tree5d979d333a2d5f9c080991d5482fd5916f8579c6 /src/nvim/os/os_win_console.c
parent931bffbda3668ddc609fc1da8f9eb576b170aa52 (diff)
parentade1b12f49c3b3914c74847d791eb90ea90b56b7 (diff)
downloadrneovim-c324271b99eee4c621463f368914d57cd729bd9c.tar.gz
rneovim-c324271b99eee4c621463f368914d57cd729bd9c.tar.bz2
rneovim-c324271b99eee4c621463f368914d57cd729bd9c.zip
Merge remote-tracking branch 'upstream/master' into userreg
Diffstat (limited to 'src/nvim/os/os_win_console.c')
-rw-r--r--src/nvim/os/os_win_console.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c
index 816e81e997..953d291290 100644
--- a/src/nvim/os/os_win_console.c
+++ b/src/nvim/os/os_win_console.c
@@ -1,6 +1,7 @@
#include <string.h>
#include "nvim/globals.h"
+#include "nvim/memory.h"
#include "nvim/os/fs.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
@@ -105,3 +106,40 @@ void os_title_reset(void)
{
SetConsoleTitle(origTitle);
}
+
+#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 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_tty_set_vterm_state(UV_TTY_SUPPORTED);
+ }
+}