[CONUTILS:PAGER][MORE] Fix the default paging region.

- The column extent should cover the whole width of the console screenbuffer.
  On the contrary, the line extent covers only the number of lines that
  cover the current displayed console window.

- Since the console can be resized while the pager is prompting, we need
  to actually recalculate in the prompt routine the default number of
  lines for a screen.

- Reset s_nNextLineNo when paging a new file.
This commit is contained in:
Hermès Bélusca-Maïto 2021-06-27 15:58:25 +02:00
parent f74a3f6e29
commit ff445ca184
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 21 additions and 4 deletions

View file

@ -172,6 +172,14 @@ PagePrompt(PCON_PAGER Pager, DWORD Done, DWORD Total)
if (!*StrLines) if (!*StrLines)
K32LoadStringW(NULL, IDS_CONTINUE_LINES, StrLines, ARRAYSIZE(StrLines)); K32LoadStringW(NULL, IDS_CONTINUE_LINES, StrLines, ARRAYSIZE(StrLines));
/*
* Check whether the pager is prompting, but we have actually finished
* to display a given file, or no data is present in STDIN anymore.
* In this case, skip the prompt altogether. The only exception is when
* we are displaying other files.
*/
// TODO: Implement!
Restart: Restart:
nLines = 0; nLines = 0;
@ -323,6 +331,11 @@ Restart:
dwMode |= ENABLE_PROCESSED_INPUT; dwMode |= ENABLE_PROCESSED_INPUT;
SetConsoleMode(hInput, dwMode); SetConsoleMode(hInput, dwMode);
/* Refresh the screen information, as the console may have been
* redimensioned. Update also the default number of lines to scroll. */
ConGetScreenInfo(Pager->Screen, &csbi);
Pager->ScrollRows = csbi.srWindow.Bottom - csbi.srWindow.Top;
/* /*
* Erase the full line where the cursor is, and move * Erase the full line where the cursor is, and move
* the cursor back to the beginning of the line. * the cursor back to the beginning of the line.
@ -357,6 +370,7 @@ Restart:
{ {
s_dwFlags |= FLAG_PLUSn; s_dwFlags |= FLAG_PLUSn;
s_nNextLineNo = Pager->lineno + nLines; s_nNextLineNo = Pager->lineno + nLines;
/* Use the default Pager->ScrollRows value */
return TRUE; return TRUE;
} }
default: default:
@ -412,6 +426,7 @@ Restart:
/* Clear the screen */ /* Clear the screen */
ConClearScreen(Pager->Screen); ConClearScreen(Pager->Screen);
} }
/* Use the default Pager->ScrollRows value */
return TRUE; return TRUE;
} }
@ -444,6 +459,7 @@ Restart:
else else
{ {
/* Extended features are unavailable: display one page */ /* Extended features are unavailable: display one page */
/* Use the default Pager->ScrollRows value */
return TRUE; return TRUE;
} }
} }
@ -1075,6 +1091,7 @@ int wmain(int argc, WCHAR* argv[])
SetFilePointer(hFile, SkipBytes, NULL, FILE_BEGIN); SetFilePointer(hFile, SkipBytes, NULL, FILE_BEGIN);
/* Reset state for paging */ /* Reset state for paging */
s_nNextLineNo = 0;
s_bPrevLineIsBlank = FALSE; s_bPrevLineIsBlank = FALSE;
s_fPrompt = PROMPT_PERCENT; s_fPrompt = PROMPT_PERCENT;
s_bDoNextFile = FALSE; s_bDoNextFile = FALSE;

View file

@ -312,7 +312,7 @@ ConWritePaging(
if (bIsConsole) if (bIsConsole)
{ {
/* Calculate the console screen extent */ /* Calculate the console screen extent */
Pager->PageColumns = csbi.srWindow.Right - csbi.srWindow.Left + 1; Pager->PageColumns = csbi.dwSize.X;
Pager->PageRows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; Pager->PageRows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
} }
else else
@ -324,14 +324,14 @@ ConWritePaging(
if (StartPaging) if (StartPaging)
{ {
if (bIsConsole) if (bIsConsole && (Pager->PageRows >= 2))
{ {
/* Reset to display one page by default */ /* Reset to display one page by default */
Pager->ScrollRows = Pager->PageRows - 1; Pager->ScrollRows = Pager->PageRows - 1;
} }
else else
{ {
/* File output: all lines are displayed at once; reset to a default value */ /* File output, or single line: all lines are displayed at once; reset to a default value */
Pager->ScrollRows = 0; Pager->ScrollRows = 0;
} }
} }
@ -371,7 +371,7 @@ ConWritePaging(
* in case the user has redimensioned it during the prompt. */ * in case the user has redimensioned it during the prompt. */
if (bIsConsole && ConGetScreenInfo(Pager->Screen, &csbi)) if (bIsConsole && ConGetScreenInfo(Pager->Screen, &csbi))
{ {
Pager->PageColumns = csbi.srWindow.Right - csbi.srWindow.Left + 1; Pager->PageColumns = csbi.dwSize.X;
Pager->PageRows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; Pager->PageRows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
} }
} }