Repository: neovim/neovim
File: src/nvim/tui/tui.c (C)

Code before:
  tui->overflow = false;
  tui->set_cursor_color_as_str = false;
  tui->cursor_has_color = false;
  tui->did_set_grapheme_cluster_mode = false;
  tui->showing_mode = SHAPE_IDX_N;
  tui->unibi_ext.set_cursor_color = -1;
  tui->unibi_ext.reset_cursor_color = -1;
  tui->unibi_ext.enter_strikethrough_mode = -1;
  tui->unibi_ext.enter_altfont_mode = -1;
  tui->unibi_ext.enable_focus_reporting = -1;
  tui->unibi_ext.disable_focus_reporting = -1;
  tui->unibi_ext.resize_screen = -1;
  tui->unibi_ext.reset_scroll_region = -1;
  tui->unibi_ext.set_cursor_style = -1;
  tui->unibi_ext.reset_cursor_style = -1;
  tui->unibi_ext.set_underline_style = -1;
  tui->unibi_ext.set_underline_color = -1;
  tui->unibi_ext.sync = -1;
  tui->out_fd = STDOUT_FILENO;
  tui->out_isatty = os_isatty(tui->out_fd);
  tui->input.tui_data = tui;

#ifdef MSWIN
  const char* guessed_term = NULL;
  os_tty_guess_term(&guessed_term, tui->out_fd);
  os_setenv("TERM", guessed_term, 1);
#endif
  char *term = os_getenv("TERM");

  // Set up unibilium/terminfo.
  if (term) {
    tui->ut = unibi_from_term(term);
    if (tui->ut) {
      if (!tui->term) {
        tui->term = xstrdup(term);
      }
    }
  }
  if (!tui->ut) {
    tui->ut = terminfo_from_builtin(term, &tui->term);
  }

  // None of the following work over SSH; see :help TERM .
  char *colorterm = os_getenv("COLORTERM");
  char *termprg = os_getenv("TERM_PROGRAM");
  char *vte_version_env = os_getenv("VTE_VERSION");
  char *konsolev_env = os_getenv("KONSOLE_VERSION");
  char *term_program_version_env = os_getenv("TERM_PROGRAM_VERSION");

  int vtev = vte_version_env ? (int)strtol(vte_version_env, NULL, 10) : 0;
  bool iterm_env = termprg && strstr(termprg, "iTerm.app");

Review comment (suggestion):
This isn't right. If `TERM` environment variable is set, the guessed value from `os_tty_guess_term()` should not override it.

Code after:
  tui->overflow = false;
  tui->set_cursor_color_as_str = false;
  tui->cursor_has_color = false;
  tui->did_set_grapheme_cluster_mode = false;
  tui->showing_mode = SHAPE_IDX_N;
  tui->unibi_ext.set_cursor_color = -1;
  tui->unibi_ext.reset_cursor_color = -1;
  tui->unibi_ext.enter_strikethrough_mode = -1;
  tui->unibi_ext.enter_altfont_mode = -1;
  tui->unibi_ext.enable_focus_reporting = -1;
  tui->unibi_ext.disable_focus_reporting = -1;
  tui->unibi_ext.resize_screen = -1;
  tui->unibi_ext.reset_scroll_region = -1;
  tui->unibi_ext.set_cursor_style = -1;
  tui->unibi_ext.reset_cursor_style = -1;
  tui->unibi_ext.set_underline_style = -1;
  tui->unibi_ext.set_underline_color = -1;
  tui->unibi_ext.sync = -1;
  tui->out_fd = STDOUT_FILENO;
  tui->out_isatty = os_isatty(tui->out_fd);
  tui->input.tui_data = tui;

  char *term = os_getenv("TERM");
#ifdef MSWIN
  const char *guessed_term = NULL;
  os_tty_guess_term(&guessed_term, tui->out_fd);
  if (term == NULL && guessed_term != NULL) {
    term = xstrdup(guessed_term);
    os_setenv("TERM", guessed_term, 1);
  }
#endif

  // Set up unibilium/terminfo.
  if (term) {
    tui->ut = unibi_from_term(term);
    if (tui->ut) {
      if (!tui->term) {
        tui->term = xstrdup(term);
      }
    }
  }
  if (!tui->ut) {
    tui->ut = terminfo_from_builtin(term, &tui->term);
  }

  // None of the following work over SSH; see :help TERM .
  char *colorterm = os_getenv("COLORTERM");
  char *termprg = os_getenv("TERM_PROGRAM");
  char *vte_version_env = os_getenv("VTE_VERSION");
  char *konsolev_env = os_getenv("KONSOLE_VERSION");
  char *term_program_version_env = os_getenv("TERM_PROGRAM_VERSION");