diff --git a/reactos/base/shell/cmd/console.c b/reactos/base/shell/cmd/console.c index ac4706dec82..29f9550ff1e 100644 --- a/reactos/base/shell/cmd/console.c +++ b/reactos/base/shell/cmd/console.c @@ -303,13 +303,13 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa 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 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa 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 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa 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; } diff --git a/reactos/base/shell/cmd/dir.c b/reactos/base/shell/cmd/dir.c index 7897e056a5f..037887d06b2 100644 --- a/reactos/base/shell/cmd/dir.c +++ b/reactos/base/shell/cmd/dir.c @@ -970,7 +970,7 @@ DirPrintWideList(PDIRFINDINFO ptrFiles[], /* [IN] Files' Info */ } /* 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 */ diff --git a/reactos/base/shell/cmd/filecomp.c b/reactos/base/shell/cmd/filecomp.c index f6e56fccf67..7cbf771d900 100644 --- a/reactos/base/shell/cmd/filecomp.c +++ b/reactos/base/shell/cmd/filecomp.c @@ -290,7 +290,7 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount) hFile = FindFirstFile (path, &file); /* Count the highest number of columns */ - GetScreenSize(&screenwidth, 0); + GetScreenSize(&screenwidth, NULL); /* For counting columns of output */ count = 0; diff --git a/reactos/base/shell/cmd/misc.c b/reactos/base/shell/cmd/misc.c index c7bf1dd886a..f2986c48921 100644 --- a/reactos/base/shell/cmd/misc.c +++ b/reactos/base/shell/cmd/misc.c @@ -148,7 +148,7 @@ BOOL CheckCtrlBreak (INT mode) 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 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength) INT PagePrompt(VOID) { + SHORT iScreenWidth, iCursorY; INPUT_RECORD ir; ConOutResPuts(STRING_MISC_HELP1); @@ -554,10 +555,24 @@ INT PagePrompt(VOID) 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; } diff --git a/reactos/base/shell/cmd/prompt.c b/reactos/base/shell/cmd/prompt.c index ce3fc3d051c..f89817a2b2e 100644 --- a/reactos/base/shell/cmd/prompt.c +++ b/reactos/base/shell/cmd/prompt.c @@ -78,14 +78,16 @@ VOID PrintInfoLine(VOID) 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 @@ VOID PrintInfoLine(VOID) csbi.dwSize.X, coPos, &dwWritten); - WriteConsoleOutputCharacter(hOutput, szInfoLine, iInfoLineLen, + WriteConsoleOutputCharacter(hOutput, pszInfoLine, iInfoLineLen, coPos, &dwWritten); }