Patch 8.2.0848
Problem:    MS-Windows: the Windows terminal code has some flaws.
Solution:   Do not redraw the right edge of the screen.  Remove the background
            color trick.  Flush the screen output buffer often.  (Nobuhiro
            Takasaki, #5546)
Files:      src/os_win32.c, src/proto/os_win32.pro, src/term.c


*** ../vim-8.2.0847/src/os_win32.c      2020-05-18 20:16:56.617319687 +0200
--- src/os_win32.c      2020-05-30 17:41:51.112819617 +0200
***************
*** 195,204 ****
  static int vtp_working = 0;
  static void vtp_init();
  static void vtp_exit();
- static int vtp_printf(char *format, ...);
  static void vtp_sgr_bulk(int arg);
  static void vtp_sgr_bulks(int argc, int *argv);
  
  static guicolor_T save_console_bg_rgb;
  static guicolor_T save_console_fg_rgb;
  static guicolor_T store_console_bg_rgb;
--- 195,206 ----
  static int vtp_working = 0;
  static void vtp_init();
  static void vtp_exit();
  static void vtp_sgr_bulk(int arg);
  static void vtp_sgr_bulks(int argc, int *argv);
  
+ static int wt_working = 0;
+ static void wt_init();
+ 
  static guicolor_T save_console_bg_rgb;
  static guicolor_T save_console_fg_rgb;
  static guicolor_T store_console_bg_rgb;
***************
*** 214,221 ****
--- 216,225 ----
  
  # ifdef FEAT_TERMGUICOLORS
  #  define USE_VTP             (vtp_working && is_term_win32() && (p_tgc || 
(!p_tgc && t_colors >= 256)))
+ #  define USE_WT              (wt_working)
  # else
  #  define USE_VTP             0
+ #  define USE_WT              0
  # endif
  
  static void set_console_color_rgb(void);
***************
*** 236,241 ****
--- 240,251 ----
  
  static BOOL win8_or_later = FALSE;
  
+ # if defined(__GNUC__) && !defined(__MINGW32__)  && !defined(__CYGWIN__)
+ #  define UChar UnicodeChar
+ # else
+ #  define UChar uChar.UnicodeChar
+ # endif
+ 
  #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
  // Dynamic loading for portability
  typedef struct _DYN_CONSOLE_SCREEN_BUFFER_INFOEX
***************
*** 286,291 ****
--- 296,325 ----
  }
  
  #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL)
+     static BOOL
+ is_ambiwidth_event(
+     INPUT_RECORD *ir)
+ {
+     return ir->EventType == KEY_EVENT
+               && ir->Event.KeyEvent.bKeyDown
+               && ir->Event.KeyEvent.wRepeatCount == 1
+               && ir->Event.KeyEvent.wVirtualKeyCode == 0x12
+               && ir->Event.KeyEvent.wVirtualScanCode == 0x38
+               && ir->Event.KeyEvent.UChar == 0
+               && ir->Event.KeyEvent.dwControlKeyState == 2;
+ }
+ 
+     static void
+ make_ambiwidth_event(
+     INPUT_RECORD *down,
+     INPUT_RECORD *up)
+ {
+     down->Event.KeyEvent.wVirtualKeyCode = 0;
+     down->Event.KeyEvent.wVirtualScanCode = 0;
+     down->Event.KeyEvent.UChar = up->Event.KeyEvent.UChar;
+     down->Event.KeyEvent.dwControlKeyState = 0;
+ }
+ 
  /*
   * Version of ReadConsoleInput() that works with IME.
   * Works around problems on Windows 8.
***************
*** 322,331 ****
  
      if (s_dwMax == 0)
      {
!       if (nLength == -1)
            return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
!       if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents))
!           return FALSE;
        s_dwIndex = 0;
        s_dwMax = dwEvents;
        if (dwEvents == 0)
--- 356,367 ----
  
      if (s_dwMax == 0)
      {
!       if (!USE_WT && nLength == -1)
            return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
!       GetNumberOfConsoleInputEvents(hInput, &dwEvents);
!       if (dwEvents == 0 && nLength == -1)
!           return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
!       ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents);
        s_dwIndex = 0;
        s_dwMax = dwEvents;
        if (dwEvents == 0)
***************
*** 334,339 ****
--- 370,379 ----
            return TRUE;
        }
  
+       for (i = s_dwIndex; i < (int)s_dwMax - 1; ++i)
+           if (is_ambiwidth_event(&s_irCache[i]))
+               make_ambiwidth_event(&s_irCache[i], &s_irCache[i + 1]);
+ 
        if (s_dwMax > 1)
        {
            head = 0;
***************
*** 937,948 ****
  };
  
  
- # if defined(__GNUC__) && !defined(__MINGW32__)  && !defined(__CYGWIN__)
- #  define UChar UnicodeChar
- # else
- #  define UChar uChar.UnicodeChar
- # endif
- 
  /*
   * The return code indicates key code size.
   */
--- 977,982 ----
***************
*** 2689,2694 ****
--- 2723,2729 ----
  
      vtp_flag_init();
      vtp_init();
+     wt_init();
  }
  
  /*
***************
*** 5781,5786 ****
--- 5816,5834 ----
            clear_chars(coord, source.Right - source.Left + 1);
        }
      }
+ 
+     if (USE_WT)
+     {
+       COORD coord;
+       int i;
+ 
+       coord.X = source.Left;
+       for (i = source.Top; i < dest.Y; ++i)
+       {
+           coord.Y = i;
+           clear_chars(coord, source.Right - source.Left + 1);
+       }
+     }
  }
  
  
***************
*** 5837,5842 ****
--- 5885,5903 ----
            clear_chars(coord, source.Right - source.Left + 1);
        }
      }
+ 
+     if (USE_WT)
+     {
+       COORD coord;
+       int i;
+ 
+       coord.X = source.Left;
+       for (i = nb; i <= source.Bottom; ++i)
+       {
+           coord.Y = i;
+           clear_chars(coord, source.Right - source.Left + 1);
+       }
+     }
  }
  
  
***************
*** 7587,7593 ****
      restore_console_color_rgb();
  }
  
!     static int
  vtp_printf(
      char *format,
      ...)
--- 7648,7654 ----
      restore_console_color_rgb();
  }
  
!     int
  vtp_printf(
      char *format,
      ...)
***************
*** 7760,7765 ****
--- 7821,7838 ----
      }
  }
  
+     static void
+ wt_init(void)
+ {
+     wt_working = (mch_getenv("WT_SESSION") != NULL);
+ }
+ 
+     int
+ use_wt(void)
+ {
+     return USE_WT;
+ }
+ 
  # ifdef FEAT_TERMGUICOLORS
      static int
  ctermtoxterm(
***************
*** 7785,7790 ****
--- 7858,7870 ----
  
      get_default_console_color(&ctermfg, &ctermbg, &fg, &bg);
  
+     if (USE_WT)
+     {
+       term_fg_rgb_color(fg);
+       term_bg_rgb_color(bg);
+       return;
+     }
+ 
      fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
      bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
  
***************
*** 7858,7863 ****
--- 7938,7946 ----
  # ifdef FEAT_TERMGUICOLORS
      DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
  
+     if (USE_WT)
+       return;
+ 
      csbi.cbSize = sizeof(csbi);
      if (has_csbiex)
        pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
*** ../vim-8.2.0847/src/proto/os_win32.pro      2020-05-17 14:06:07.317201551 
+0200
--- src/proto/os_win32.pro      2020-05-30 17:41:51.112819617 +0200
***************
*** 71,76 ****
--- 71,78 ----
  void set_alist_count(void);
  void fix_arg_enc(void);
  int mch_setenv(char *var, char *value, int x);
+ int vtp_printf(char *format, ...);
+ int use_wt(void);
  void get_default_console_color(int *cterm_fg, int *cterm_bg, guicolor_T 
*gui_fg, guicolor_T *gui_bg);
  void control_console_color_rgb(void);
  int use_vtp(void);
*** ../vim-8.2.0847/src/term.c  2020-05-24 17:23:41.834154785 +0200
--- src/term.c  2020-05-30 17:41:51.112819617 +0200
***************
*** 2956,2962 ****
  
      vim_snprintf(buf, MAX_COLOR_STR_LEN,
                                  (char *)s, RED(rgb), GREEN(rgb), BLUE(rgb));
!     OUT_STR(buf);
  }
  
      void
--- 2956,2971 ----
  
      vim_snprintf(buf, MAX_COLOR_STR_LEN,
                                  (char *)s, RED(rgb), GREEN(rgb), BLUE(rgb));
! #ifdef FEAT_VTP
!     if (use_wt())
!     {
!       out_flush();
!       buf[1] = '[';
!       vtp_printf(buf);
!     }
!     else
! #endif
!       OUT_STR(buf);
  }
  
      void
*** ../vim-8.2.0847/src/version.c       2020-05-30 17:05:57.032692393 +0200
--- src/version.c       2020-05-30 17:48:57.627230629 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     848,
  /**/

-- 
I noticed my daughter's Disney-net password on a sticky note:
"MickeyMinnieGoofyPluto".  I asked her why it was so long.
"Because they say it has to have at least four characters."

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202005301549.04UFnpdQ373182%40masaka.moolenaar.net.

Raspunde prin e-mail lui