https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ff445ca184abf213083a4…
commit ff445ca184abf213083a45b2ae49ffa662d8c028
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jun 27 15:58:25 2021 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Jun 28 21:26:31 2021 +0200
[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.
---
base/applications/cmdutils/more/more.c | 17 +++++++++++++++++
sdk/lib/conutils/pager.c | 8 ++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/base/applications/cmdutils/more/more.c
b/base/applications/cmdutils/more/more.c
index f9179138ee1..5b868f0b5dc 100644
--- a/base/applications/cmdutils/more/more.c
+++ b/base/applications/cmdutils/more/more.c
@@ -172,6 +172,14 @@ PagePrompt(PCON_PAGER Pager, DWORD Done, DWORD Total)
if (!*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:
nLines = 0;
@@ -323,6 +331,11 @@ Restart:
dwMode |= ENABLE_PROCESSED_INPUT;
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
* the cursor back to the beginning of the line.
@@ -357,6 +370,7 @@ Restart:
{
s_dwFlags |= FLAG_PLUSn;
s_nNextLineNo = Pager->lineno + nLines;
+ /* Use the default Pager->ScrollRows value */
return TRUE;
}
default:
@@ -412,6 +426,7 @@ Restart:
/* Clear the screen */
ConClearScreen(Pager->Screen);
}
+ /* Use the default Pager->ScrollRows value */
return TRUE;
}
@@ -444,6 +459,7 @@ Restart:
else
{
/* Extended features are unavailable: display one page */
+ /* Use the default Pager->ScrollRows value */
return TRUE;
}
}
@@ -1075,6 +1091,7 @@ int wmain(int argc, WCHAR* argv[])
SetFilePointer(hFile, SkipBytes, NULL, FILE_BEGIN);
/* Reset state for paging */
+ s_nNextLineNo = 0;
s_bPrevLineIsBlank = FALSE;
s_fPrompt = PROMPT_PERCENT;
s_bDoNextFile = FALSE;
diff --git a/sdk/lib/conutils/pager.c b/sdk/lib/conutils/pager.c
index ced3bd4e0cb..db7e17eb883 100644
--- a/sdk/lib/conutils/pager.c
+++ b/sdk/lib/conutils/pager.c
@@ -312,7 +312,7 @@ ConWritePaging(
if (bIsConsole)
{
/* 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;
}
else
@@ -324,14 +324,14 @@ ConWritePaging(
if (StartPaging)
{
- if (bIsConsole)
+ if (bIsConsole && (Pager->PageRows >= 2))
{
/* Reset to display one page by default */
Pager->ScrollRows = Pager->PageRows - 1;
}
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;
}
}
@@ -371,7 +371,7 @@ ConWritePaging(
* in case the user has redimensioned it during the prompt. */
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;
}
}