Merge #9401 from justinmk/pr-win-erw7

This commit is contained in:
Justin M. Keyes
2018-12-30 23:54:23 +01:00
committed by GitHub
11 changed files with 838 additions and 60 deletions

View File

@@ -955,13 +955,6 @@ void set_init_2(bool headless)
p_window = Rows - 1;
}
set_number_default("window", Rows - 1);
#if 0
// This bodges around problems that should be fixed in the TUI layer.
if (!headless && !os_term_is_nice()) {
set_string_option_direct((char_u *)"guicursor", -1, (char_u *)"",
OPT_GLOBAL, SID_NONE);
}
#endif
parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor'
(void)parse_printoptions(); // parse 'printoptions' default value
}

View File

@@ -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

60
src/nvim/os/tty.c Normal file
View File

@@ -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

7
src/nvim/os/tty.h Normal file
View File

@@ -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

View File

@@ -105,6 +105,22 @@ static unibi_term *terminfo_builtin(const char *term, char **termname)
*termname = xstrdup("builtin_vte");
return unibi_from_mem((const char *)vte_256colour_terminfo,
sizeof vte_256colour_terminfo);
} else if (terminfo_is_term_family(term, "cygwin")) {
*termname = xstrdup("builtin_cygwin");
return unibi_from_mem((const char *)cygwin_terminfo,
sizeof cygwin_terminfo);
} else if (terminfo_is_term_family(term, "win32con")) {
*termname = xstrdup("builtin_win32con");
return unibi_from_mem((const char *)win32con_terminfo,
sizeof win32con_terminfo);
} else if (terminfo_is_term_family(term, "conemu")) {
*termname = xstrdup("builtin_conemu");
return unibi_from_mem((const char *)conemu_terminfo,
sizeof conemu_terminfo);
} else if (terminfo_is_term_family(term, "vtpcon")) {
*termname = xstrdup("builtin_vtpcon");
return unibi_from_mem((const char *)vtpcon_terminfo,
sizeof vtpcon_terminfo);
} else {
*termname = xstrdup("builtin_ansi");
return unibi_from_mem((const char *)ansi_terminfo,

File diff suppressed because one or more lines are too long

View File

@@ -31,6 +31,7 @@
#include "nvim/event/signal.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/tty.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/ui_bridge.h"
@@ -94,6 +95,7 @@ typedef struct {
bool can_change_scroll_region;
bool can_set_lr_margin;
bool can_set_left_right_margin;
bool can_scroll;
bool can_erase_chars;
bool immediate_wrap_after_last_column;
bool bce;
@@ -211,8 +213,13 @@ static void terminfo_start(UI *ui)
data->out_fd = 1;
data->out_isatty = os_isatty(data->out_fd);
// Set up unibilium/terminfo.
const char *term = os_getenv("TERM");
#ifdef WIN32
os_tty_guess_term(&term, data->out_fd);
os_setenv("TERM", term, 1);
#endif
// Set up unibilium/terminfo.
data->ut = unibi_from_env();
char *termname = NULL;
if (!term || !data->ut) {
@@ -246,9 +253,16 @@ static void terminfo_start(UI *ui)
data->can_set_left_right_margin =
!!unibi_get_str(data->ut, unibi_set_left_margin_parm)
&& !!unibi_get_str(data->ut, unibi_set_right_margin_parm);
data->can_scroll =
!!unibi_get_str(data->ut, unibi_delete_line)
&& !!unibi_get_str(data->ut, unibi_parm_delete_line)
&& !!unibi_get_str(data->ut, unibi_insert_line)
&& !!unibi_get_str(data->ut, unibi_parm_insert_line);
data->can_erase_chars = !!unibi_get_str(data->ut, unibi_erase_chars);
data->immediate_wrap_after_last_column =
terminfo_is_term_family(term, "cygwin")
terminfo_is_term_family(term, "conemu")
|| terminfo_is_term_family(term, "cygwin")
|| terminfo_is_term_family(term, "win32con")
|| terminfo_is_term_family(term, "interix");
data->bce = unibi_get_bool(data->ut, unibi_back_color_erase);
data->normlen = unibi_pre_fmt_str(data, unibi_cursor_normal,
@@ -1044,11 +1058,12 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer startrow, Integer endrow,
ugrid_scroll(grid, top, bot, left, right, (int)rows);
bool can_scroll = data->scroll_region_is_full_screen
|| (data->can_change_scroll_region
&& ((left == 0 && right == ui->width - 1)
|| data->can_set_lr_margin
|| data->can_set_left_right_margin));
bool can_scroll = data->can_scroll
&& (data->scroll_region_is_full_screen
|| (data->can_change_scroll_region
&& ((left == 0 && right == ui->width - 1)
|| data->can_set_lr_margin
|| data->can_set_left_right_margin)));
if (can_scroll) {
// Change terminal scroll region and move cursor to the top
@@ -1499,6 +1514,7 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
bool mate_pretending_xterm = xterm && colorterm
&& strstr(colorterm, "mate-terminal");
bool true_xterm = xterm && !!xterm_version && !bsdvt;
bool cygwin = terminfo_is_term_family(term, "cygwin");
char *fix_normal = (char *)unibi_get_str(ut, unibi_cursor_normal);
if (fix_normal) {
@@ -1687,6 +1703,7 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
|| iterm || iterm_pretending_xterm
|| teraterm // per TeraTerm "Supported Control Functions" doco
|| alacritty // https://github.com/jwilm/alacritty/pull/608
|| cygwin
// Some linux-type terminals implement the xterm extension.
// Example: console-terminal-emulator from the nosh toolset.
|| (linuxvt