From 503d7af1556786c7cbdc01b2aafa1f9d8339c5a3 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Sat, 7 Apr 2018 11:55:47 -0400 Subject: [PATCH] Improved Windows console resizing, when reducing the vertical size. After Ulf Magnusson. (See GitHub issue #26.) --- wincon/pdcscrn.c | 59 ++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/wincon/pdcscrn.c b/wincon/pdcscrn.c index daef0e38..093f9588 100644 --- a/wincon/pdcscrn.c +++ b/wincon/pdcscrn.c @@ -525,34 +525,43 @@ int PDC_resize_screen(int nlines, int ncols) SMALL_RECT rect; COORD size, max; - if (nlines || ncols) + bool prog_resize = nlines || ncols; + + if (!prog_resize) { - if (nlines < 2 || ncols < 2) - return ERR; - - max = GetLargestConsoleWindowSize(pdc_con_out); - - rect.Left = rect.Top = 0; - rect.Right = ncols - 1; - - if (rect.Right > max.X) - rect.Right = max.X; - - rect.Bottom = nlines - 1; - - if (rect.Bottom > max.Y) - rect.Bottom = max.Y; - - size.X = rect.Right + 1; - size.Y = rect.Bottom + 1; - - _fit_console_window(pdc_con_out, &rect); - SetConsoleScreenBufferSize(pdc_con_out, size); - _fit_console_window(pdc_con_out, &rect); - SetConsoleScreenBufferSize(pdc_con_out, size); - SetConsoleActiveScreenBuffer(pdc_con_out); + nlines = PDC_get_rows(); + ncols = PDC_get_columns(); } + if (nlines < 2 || ncols < 2) + return ERR; + + max = GetLargestConsoleWindowSize(pdc_con_out); + + rect.Left = rect.Top = 0; + rect.Right = ncols - 1; + + if (rect.Right > max.X) + rect.Right = max.X; + + rect.Bottom = nlines - 1; + + if (rect.Bottom > max.Y) + rect.Bottom = max.Y; + + size.X = rect.Right + 1; + size.Y = rect.Bottom + 1; + + _fit_console_window(pdc_con_out, &rect); + SetConsoleScreenBufferSize(pdc_con_out, size); + + if (prog_resize) + { + _fit_console_window(pdc_con_out, &rect); + SetConsoleScreenBufferSize(pdc_con_out, size); + } + SetConsoleActiveScreenBuffer(pdc_con_out); + PDC_flushinp(); SP->resized = FALSE;