- 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).
svn path=/trunk/; revision=72955
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;
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);
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;
}
}
/* 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 */
hFile = FindFirstFile (path, &file);
/* Count the highest number of columns */
- GetScreenSize(&screenwidth, 0);
+ GetScreenSize(&screenwidth, NULL);
/* For counting columns of output */
count = 0;
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
INT PagePrompt(VOID)
{
+ SHORT iScreenWidth, iCursorY;
INPUT_RECORD ir;
ConOutResPuts(STRING_MISC_HELP1);
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;
}
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;
csbi.dwSize.X,
coPos, &dwWritten);
- WriteConsoleOutputCharacter(hOutput, szInfoLine, iInfoLineLen,
+ WriteConsoleOutputCharacter(hOutput, pszInfoLine, iInfoLineLen,
coPos, &dwWritten);
}