@@ -1492,6 +1492,8 @@ handle_focus_event(INPUT_RECORD ir)
14921492 ui_focus_change ((int )g_fJustGotFocus );
14931493}
14941494
1495+ static void ResizeConBuf (HANDLE hConsole , COORD coordScreen );
1496+
14951497/*
14961498 * Wait until console input from keyboard or mouse is available,
14971499 * or the time is up.
@@ -1657,11 +1659,18 @@ WaitForChar(long msec, int ignore_input)
16571659 handle_focus_event (ir );
16581660 else if (ir .EventType == WINDOW_BUFFER_SIZE_EVENT )
16591661 {
1660- /* Only call shell_resized() when the size actually change to
1661- * avoid the screen is cleard. */
1662- if (ir .Event .WindowBufferSizeEvent .dwSize .X != Columns
1663- || ir .Event .WindowBufferSizeEvent .dwSize .Y != Rows )
1662+ COORD dwSize = ir .Event .WindowBufferSizeEvent .dwSize ;
1663+
1664+ // Only call shell_resized() when the size actually change to
1665+ // avoid the screen is cleard.
1666+ if (dwSize .X != Columns || dwSize .Y != Rows )
1667+ {
1668+ CONSOLE_SCREEN_BUFFER_INFO csbi ;
1669+ GetConsoleScreenBufferInfo (g_hConOut , & csbi );
1670+ dwSize .Y = csbi .srWindow .Bottom - csbi .srWindow .Top + 1 ;
1671+ ResizeConBuf (g_hConOut , dwSize );
16641672 shell_resized ();
1673+ }
16651674 }
16661675#ifdef FEAT_MOUSE
16671676 else if (ir .EventType == MOUSE_EVENT
@@ -6327,7 +6336,7 @@ write_chars(
63276336 * character was written, otherwise we get stuck. */
63286337 if (WriteConsoleOutputCharacterW (g_hConOut , unicodebuf , length ,
63296338 coord , & cchwritten ) == 0
6330- || cchwritten == 0 )
6339+ || cchwritten == 0 || cchwritten == ( DWORD ) - 1 )
63316340 cchwritten = 1 ;
63326341 }
63336342 else
@@ -6361,7 +6370,7 @@ write_chars(
63616370 * character was written, otherwise we get stuck. */
63626371 if (WriteConsoleOutputCharacter (g_hConOut , (LPCSTR )pchBuf , cbToWrite ,
63636372 coord , & written ) == 0
6364- || written == 0 )
6373+ || written == 0 || written == ( DWORD ) - 1 )
63656374 written = 1 ;
63666375 }
63676376 else
@@ -7707,7 +7716,7 @@ vtp_flag_init(void)
77077716
77087717}
77097718
7710- #ifndef FEAT_GUI_W32
7719+ #if !defined( FEAT_GUI_W32 ) || defined( PROTO )
77117720
77127721 static void
77137722vtp_init (void )
@@ -7931,3 +7940,28 @@ is_conpty_stable(void)
79317940{
79327941 return conpty_stable ;
79337942}
7943+
7944+ #if !defined(FEAT_GUI_W32 ) || defined(PROTO )
7945+ void
7946+ resize_console_buf (void )
7947+ {
7948+ CONSOLE_SCREEN_BUFFER_INFO csbi ;
7949+ COORD coord ;
7950+ SMALL_RECT newsize ;
7951+
7952+ if (GetConsoleScreenBufferInfo (g_hConOut , & csbi ))
7953+ {
7954+ coord .X = SRWIDTH (csbi .srWindow );
7955+ coord .Y = SRHEIGHT (csbi .srWindow );
7956+ SetConsoleScreenBufferSize (g_hConOut , coord );
7957+
7958+ newsize .Left = 0 ;
7959+ newsize .Top = 0 ;
7960+ newsize .Right = coord .X - 1 ;
7961+ newsize .Bottom = coord .Y - 1 ;
7962+ SetConsoleWindowInfo (g_hConOut , TRUE, & newsize );
7963+
7964+ SetConsoleScreenBufferSize (g_hConOut , coord );
7965+ }
7966+ }
7967+ #endif
0 commit comments