/* No parameter: Set the default colors */
if (rest[0] == _T('\0'))
{
- ConSetScreenColor(wDefColor, TRUE);
+ ConSetScreenColor(GetStdHandle(STD_OUTPUT_HANDLE), wDefColor, TRUE);
return 0;
}
* Set the chosen color. Use also the following advanced flag:
* /-F to avoid changing already buffered foreground/background.
*/
- if (ConSetScreenColor(wColor, !_tcsstr(rest, _T("/-F")) && !_tcsstr(rest, _T("/-f"))) == FALSE)
+ if (ConSetScreenColor(GetStdHandle(STD_OUTPUT_HANDLE), wColor,
+ !_tcsstr(rest, _T("/-F")) && !_tcsstr(rest, _T("/-f"))) == FALSE)
{
/* Failed because foreground and background colors were the same */
ConErrResPuts(STRING_COLOR_ERROR1);
#define OUTPUT_BUFFER_SIZE 4096
-
+/* Cache codepage for text streams */
UINT InputCodePage;
UINT OutputCodePage;
/************************** Console PAGER functions ***************************/
-INT ConPrintfVPaging(DWORD nStdHandle, BOOL NewPage, LPTSTR szFormat, va_list arg_ptr)
+BOOL ConPrintfVPaging(DWORD nStdHandle, BOOL NewPage, LPTSTR szFormat, va_list arg_ptr)
{
INT len;
CONSOLE_SCREEN_BUFFER_INFO csbi;
/* Reset LineCount and return if no string has been given */
if (szFormat == NULL)
- return 0;
+ return TRUE;
/* 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 */
ConPrintfV(nStdHandle, szFormat, arg_ptr);
- return 0;
+ return TRUE;
}
/*
if (ScreenLines < 4)
{
ConPrintfV(nStdHandle, szFormat, arg_ptr);
- return 0;
+ return TRUE;
}
len = _vstprintf(szOut, szFormat, arg_ptr);
/* Prompt the user */
if (PagePrompt() != PROMPT_YES)
- {
- return 1;
- }
+ return FALSE;
// TODO: Recalculate 'ScreenLines' in case the user redimensions
// the window during the prompt.
WriteConsole(hOutput, &szOut[from], i-from, &dwWritten, NULL);
- return 0;
+ return TRUE;
}
-INT ConOutPrintfPaging(BOOL NewPage, LPTSTR szFormat, ...)
+BOOL ConOutPrintfPaging(BOOL NewPage, LPTSTR szFormat, ...)
{
- INT iReturn;
+ BOOL bRet;
va_list arg_ptr;
va_start(arg_ptr, szFormat);
- iReturn = ConPrintfVPaging(STD_OUTPUT_HANDLE, NewPage, szFormat, arg_ptr);
+ bRet = ConPrintfVPaging(STD_OUTPUT_HANDLE, NewPage, szFormat, arg_ptr);
va_end(arg_ptr);
- return iReturn;
+ return bRet;
}
VOID ConOutResPaging(BOOL NewPage, UINT resID)
#endif
#ifdef INCLUDE_CMD_COLOR
-BOOL ConSetScreenColor(WORD wColor, BOOL bFill)
+BOOL ConSetScreenColor(HANDLE hOutput, WORD wColor, BOOL bFill)
{
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD coPos;
/* Fill the whole background if needed */
if (bFill)
{
- GetConsoleScreenBufferInfo(hConsole, &csbi);
+ GetConsoleScreenBufferInfo(hOutput, &csbi);
coPos.X = 0;
coPos.Y = 0;
- FillConsoleOutputAttribute(hConsole,
+ FillConsoleOutputAttribute(hOutput,
wColor & 0x00FF,
csbi.dwSize.X * csbi.dwSize.Y,
coPos,
}
/* Set the text attribute */
- SetConsoleTextAttribute(hConsole, wColor & 0x00FF);
+ SetConsoleTextAttribute(hOutput, wColor & 0x00FF);
return TRUE;
}
#endif
ConFormatMessage(STD_ERROR_HANDLE, (MessageId), ##__VA_ARGS__)
-INT ConPrintfVPaging(DWORD nStdHandle, BOOL, LPTSTR, va_list);
-INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
+BOOL ConPrintfVPaging(DWORD nStdHandle, BOOL, LPTSTR, va_list);
+BOOL ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
VOID ConOutResPaging(BOOL NewPage, UINT resID);
SHORT GetCursorX (VOID);
#endif
#ifdef INCLUDE_CMD_COLOR
-BOOL ConSetScreenColor(WORD wColor, BOOL bFill);
+BOOL ConSetScreenColor(HANDLE hOutput, WORD wColor, BOOL bFill);
#endif
// TCHAR cgetchar (VOID);
}
/* Print either with or without paging, depending on /P switch */
-static INT
+static BOOL
DirPrintf(LPDIRSWITCHFLAGS lpFlags, LPTSTR szFormat, ...)
{
- INT iReturn = 0;
+ BOOL Done = TRUE;
va_list arg_ptr;
va_start(arg_ptr, szFormat);
if (lpFlags->bPause)
- iReturn = ConPrintfVPaging(STD_OUTPUT_HANDLE, FALSE, szFormat, arg_ptr);
+ Done = ConPrintfVPaging(STD_OUTPUT_HANDLE, FALSE, szFormat, arg_ptr);
else
ConPrintfV(STD_OUTPUT_HANDLE, szFormat, arg_ptr);
va_end(arg_ptr);
- return iReturn;
+ return Done;
}
if (!lpFlags->bBareFormat && !(lpFlags->bRecursive && (dwCount <= 0)))
{
LoadString(CMD_ModuleHandle, STRING_DIR_HELP7, szMsg, ARRAYSIZE(szMsg));
- if (DirPrintf(lpFlags, szMsg, szTemp))
+ if (!DirPrintf(lpFlags, szMsg, szTemp))
return;
}