Author: hbelusca
Date: Mon Oct 10 19:15:07 2016
New Revision: 72955
URL:
http://svn.reactos.org/svn/reactos?rev=72955&view=rev
Log:
[CMD]
- Improve the screen pager so that it looks a bit more like MORE's one: display full
screen pages, where only the last line contains the "press any key..." prompt,
and erase this prompt when a key is pressed and before displaying the other screen page.
- GetScreenSize parameters are pointers (so use NULL instead of 0);
- Use ARRAYSIZE instead of hardcoding buffer number of elements;
- Simplify PrintInfoLine() (use read-only resource string buffer returned by LoadString
instead of a temporary buffer, since we are just interested in the counted string).
Modified:
trunk/reactos/base/shell/cmd/console.c
trunk/reactos/base/shell/cmd/dir.c
trunk/reactos/base/shell/cmd/filecomp.c
trunk/reactos/base/shell/cmd/misc.c
trunk/reactos/base/shell/cmd/prompt.c
Modified: trunk/reactos/base/shell/cmd/console.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.c?r…
==============================================================================
--- trunk/reactos/base/shell/cmd/console.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/console.c [iso-8859-1] Mon Oct 10 19:15:07 2016
@@ -303,13 +303,13 @@
DWORD dwWritten;
HANDLE hOutput = GetStdHandle(nStdHandle);
- /* used to count number of lines since last pause */
+ /* Used to count number of lines since last pause */
static int LineCount = 0;
- /* used to see how big the screen is */
+ /* Used to see how big the screen is */
int ScreenLines = 0;
- /* chars since start of line */
+ /* Chars since start of line */
int CharSL;
int from = 0, i = 0;
@@ -317,22 +317,26 @@
if (NewPage == TRUE)
LineCount = 0;
- /* rest LineCount and return if no string have been given */
+ /* Reset LineCount and return if no string has been given */
if (szFormat == NULL)
return 0;
- /* Get the size of the visual screen that can be printed too */
+ /* Get the size of the visual screen that can be printed to */
if (!IsConsoleHandle(hOutput) || !GetConsoleScreenBufferInfo(hOutput, &csbi))
{
/* We assume it's a file handle */
ConPrintf(szFormat, arg_ptr, nStdHandle);
return 0;
}
- /* Subtract 2 to account for "press any key..." and for the blank line at
the end of PagePrompt() */
- ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top) - 4;
+
+ /*
+ * Get the number of lines currently displayed on screen, minus 1
+ * to account for the "press any key..." prompt from PagePrompt().
+ */
+ ScreenLines = (csbi.srWindow.Bottom - csbi.srWindow.Top);
CharSL = csbi.dwCursorPosition.X;
- /* Make sure they didn't make the screen to small */
+ /* Make sure the user doesn't have the screen too small */
if (ScreenLines < 4)
{
ConPrintf(szFormat, arg_ptr, nStdHandle);
@@ -355,10 +359,15 @@
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
from = i;
+ /* Prompt the user */
if (PagePrompt() != PROMPT_YES)
{
return 1;
}
+
+ // TODO: Recalculate 'ScreenLines' in case the user redimensions
+ // the window during the prompt.
+
/* Reset the number of lines being printed */
LineCount = 0;
}
Modified: trunk/reactos/base/shell/cmd/dir.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=7…
==============================================================================
--- trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] Mon Oct 10 19:15:07 2016
@@ -970,7 +970,7 @@
}
/* Count the highest number of columns */
- GetScreenSize(&iScreenWidth, 0);
+ GetScreenSize(&iScreenWidth, NULL);
iColumns = (USHORT)(iScreenWidth / iLongestName);
/* Check if there is enough space for spaces between names */
Modified: trunk/reactos/base/shell/cmd/filecomp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/filecomp.c?…
==============================================================================
--- trunk/reactos/base/shell/cmd/filecomp.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/filecomp.c [iso-8859-1] Mon Oct 10 19:15:07 2016
@@ -290,7 +290,7 @@
hFile = FindFirstFile (path, &file);
/* Count the highest number of columns */
- GetScreenSize(&screenwidth, 0);
+ GetScreenSize(&screenwidth, NULL);
/* For counting columns of output */
count = 0;
Modified: trunk/reactos/base/shell/cmd/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/misc.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] Mon Oct 10 19:15:07 2016
@@ -148,7 +148,7 @@
if (!bCtrlBreak)
return FALSE;
- LoadString(CMD_ModuleHandle, STRING_COPY_OPTION, options, 4);
+ LoadString(CMD_ModuleHandle, STRING_COPY_OPTION, options,
ARRAYSIZE(options));
/* we need to be sure the string arrives on the screen! */
do
@@ -536,6 +536,7 @@
INT PagePrompt(VOID)
{
+ SHORT iScreenWidth, iCursorY;
INPUT_RECORD ir;
ConOutResPuts(STRING_MISC_HELP1);
@@ -554,10 +555,24 @@
AddBreakHandler();
ConInEnable();
+ /*
+ * Get the screen width, erase the full line where the cursor is,
+ * and move the cursor back to the beginning of the line.
+ */
+ GetScreenSize(&iScreenWidth, NULL);
+ iCursorY = GetCursorY();
+ SetCursorXY(0, iCursorY);
+ while (iScreenWidth-- > 0) // Or call FillConsoleOutputCharacter ?
+ ConOutChar(_T(' '));
+ SetCursorXY(0, iCursorY);
+
if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
(ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED))))
{
+ /* We break, output a newline */
+ ConOutChar(_T('\n'));
+
bCtrlBreak = TRUE;
return PROMPT_BREAK;
}
Modified: trunk/reactos/base/shell/cmd/prompt.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/prompt.c?re…
==============================================================================
--- trunk/reactos/base/shell/cmd/prompt.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/prompt.c [iso-8859-1] Mon Oct 10 19:15:07 2016
@@ -78,14 +78,16 @@
COORD coPos;
DWORD dwWritten;
- TCHAR szInfoLine[80 + 1]; // The info line is 80 characters long (without NULL
character)
+ PTSTR pszInfoLine = NULL;
INT iInfoLineLen;
/* Return directly if the output handle is not a console handle */
if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
return;
- iInfoLineLen = LoadString(CMD_ModuleHandle, STRING_CMD_INFOLINE, szInfoLine,
ARRAYSIZE(szInfoLine));
+ iInfoLineLen = LoadString(CMD_ModuleHandle, STRING_CMD_INFOLINE,
(PTSTR)&pszInfoLine, 0);
+ if (!pszInfoLine || iInfoLineLen == 0)
+ return;
/* Display the localized information line */
coPos.X = 0;
@@ -97,7 +99,7 @@
csbi.dwSize.X,
coPos, &dwWritten);
- WriteConsoleOutputCharacter(hOutput, szInfoLine, iInfoLineLen,
+ WriteConsoleOutputCharacter(hOutput, pszInfoLine, iInfoLineLen,
coPos, &dwWritten);
}