mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 18:35:41 +00:00
[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). svn path=/trunk/; revision=72955
This commit is contained in:
parent
8fbd67bc4a
commit
b408826a0b
5 changed files with 40 additions and 14 deletions
|
@ -303,13 +303,13 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
HANDLE hOutput = GetStdHandle(nStdHandle);
|
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;
|
static int LineCount = 0;
|
||||||
|
|
||||||
/* used to see how big the screen is */
|
/* Used to see how big the screen is */
|
||||||
int ScreenLines = 0;
|
int ScreenLines = 0;
|
||||||
|
|
||||||
/* chars since start of line */
|
/* Chars since start of line */
|
||||||
int CharSL;
|
int CharSL;
|
||||||
|
|
||||||
int from = 0, i = 0;
|
int from = 0, i = 0;
|
||||||
|
@ -317,22 +317,26 @@ INT ConPrintfPaging(BOOL NewPage, LPTSTR szFormat, va_list arg_ptr, DWORD nStdHa
|
||||||
if (NewPage == TRUE)
|
if (NewPage == TRUE)
|
||||||
LineCount = 0;
|
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)
|
if (szFormat == NULL)
|
||||||
return 0;
|
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))
|
if (!IsConsoleHandle(hOutput) || !GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||||
{
|
{
|
||||||
/* We assume it's a file handle */
|
/* We assume it's a file handle */
|
||||||
ConPrintf(szFormat, arg_ptr, nStdHandle);
|
ConPrintf(szFormat, arg_ptr, nStdHandle);
|
||||||
return 0;
|
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;
|
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)
|
if (ScreenLines < 4)
|
||||||
{
|
{
|
||||||
ConPrintf(szFormat, arg_ptr, nStdHandle);
|
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);
|
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
|
||||||
from = i;
|
from = i;
|
||||||
|
|
||||||
|
/* Prompt the user */
|
||||||
if (PagePrompt() != PROMPT_YES)
|
if (PagePrompt() != PROMPT_YES)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Recalculate 'ScreenLines' in case the user redimensions
|
||||||
|
// the window during the prompt.
|
||||||
|
|
||||||
/* Reset the number of lines being printed */
|
/* Reset the number of lines being printed */
|
||||||
LineCount = 0;
|
LineCount = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -970,7 +970,7 @@ DirPrintWideList(PDIRFINDINFO ptrFiles[], /* [IN] Files' Info */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count the highest number of columns */
|
/* Count the highest number of columns */
|
||||||
GetScreenSize(&iScreenWidth, 0);
|
GetScreenSize(&iScreenWidth, NULL);
|
||||||
iColumns = (USHORT)(iScreenWidth / iLongestName);
|
iColumns = (USHORT)(iScreenWidth / iLongestName);
|
||||||
|
|
||||||
/* Check if there is enough space for spaces between names */
|
/* Check if there is enough space for spaces between names */
|
||||||
|
|
|
@ -290,7 +290,7 @@ BOOL ShowCompletionMatches (LPTSTR str, INT charcount)
|
||||||
hFile = FindFirstFile (path, &file);
|
hFile = FindFirstFile (path, &file);
|
||||||
|
|
||||||
/* Count the highest number of columns */
|
/* Count the highest number of columns */
|
||||||
GetScreenSize(&screenwidth, 0);
|
GetScreenSize(&screenwidth, NULL);
|
||||||
|
|
||||||
/* For counting columns of output */
|
/* For counting columns of output */
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
|
@ -148,7 +148,7 @@ BOOL CheckCtrlBreak (INT mode)
|
||||||
if (!bCtrlBreak)
|
if (!bCtrlBreak)
|
||||||
return FALSE;
|
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! */
|
/* we need to be sure the string arrives on the screen! */
|
||||||
do
|
do
|
||||||
|
@ -536,6 +536,7 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
|
||||||
|
|
||||||
INT PagePrompt(VOID)
|
INT PagePrompt(VOID)
|
||||||
{
|
{
|
||||||
|
SHORT iScreenWidth, iCursorY;
|
||||||
INPUT_RECORD ir;
|
INPUT_RECORD ir;
|
||||||
|
|
||||||
ConOutResPuts(STRING_MISC_HELP1);
|
ConOutResPuts(STRING_MISC_HELP1);
|
||||||
|
@ -554,10 +555,24 @@ INT PagePrompt(VOID)
|
||||||
AddBreakHandler();
|
AddBreakHandler();
|
||||||
ConInEnable();
|
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) ||
|
if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
|
||||||
((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
|
((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
|
||||||
(ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
|
(ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
|
||||||
{
|
{
|
||||||
|
/* We break, output a newline */
|
||||||
|
ConOutChar(_T('\n'));
|
||||||
|
|
||||||
bCtrlBreak = TRUE;
|
bCtrlBreak = TRUE;
|
||||||
return PROMPT_BREAK;
|
return PROMPT_BREAK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,14 +78,16 @@ VOID PrintInfoLine(VOID)
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
|
|
||||||
TCHAR szInfoLine[80 + 1]; // The info line is 80 characters long (without NULL character)
|
PTSTR pszInfoLine = NULL;
|
||||||
INT iInfoLineLen;
|
INT iInfoLineLen;
|
||||||
|
|
||||||
/* Return directly if the output handle is not a console handle */
|
/* Return directly if the output handle is not a console handle */
|
||||||
if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
|
if (!GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||||
return;
|
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 */
|
/* Display the localized information line */
|
||||||
coPos.X = 0;
|
coPos.X = 0;
|
||||||
|
@ -97,7 +99,7 @@ VOID PrintInfoLine(VOID)
|
||||||
csbi.dwSize.X,
|
csbi.dwSize.X,
|
||||||
coPos, &dwWritten);
|
coPos, &dwWritten);
|
||||||
|
|
||||||
WriteConsoleOutputCharacter(hOutput, szInfoLine, iInfoLineLen,
|
WriteConsoleOutputCharacter(hOutput, pszInfoLine, iInfoLineLen,
|
||||||
coPos, &dwWritten);
|
coPos, &dwWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue