mirror of
https://github.com/reactos/reactos.git
synced 2025-05-31 06:58:10 +00:00
[CMD]: Little refactoring to lay out the way to using the CONUTILS library in CMD.
- Move the code used to beep, clear screen, and color the screen into console.c ; - Rename SetScreenColor into ConSetScreenColor, and invert its second parameter (bNoFill -> bFill); its default behaviour is to fill all the screen. svn path=/trunk/; revision=76000
This commit is contained in:
parent
3c9f2e199f
commit
c1596e7b3a
6 changed files with 93 additions and 57 deletions
|
@ -41,8 +41,8 @@ INT cmd_beep(LPTSTR param)
|
|||
if (bc == NULL)
|
||||
return 1;
|
||||
#endif
|
||||
MessageBeep (-1);
|
||||
|
||||
ConRingBell(GetStdHandle(STD_OUTPUT_HANDLE));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,34 +32,13 @@
|
|||
|
||||
INT cmd_cls(LPTSTR param)
|
||||
{
|
||||
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
DWORD dwWritten;
|
||||
|
||||
if (!_tcsncmp(param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE, STRING_CLS_HELP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||
{
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute(hOutput, csbi.wAttributes,
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos, &dwWritten);
|
||||
FillConsoleOutputCharacter(hOutput, _T(' '),
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos, &dwWritten);
|
||||
SetConsoleCursorPosition(hOutput, coPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConOutChar(_T('\f'));
|
||||
}
|
||||
|
||||
ConClearScreen(GetStdHandle(STD_OUTPUT_HANDLE));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1956,7 +1956,7 @@ Initialize(VOID)
|
|||
}
|
||||
|
||||
if (wDefColor != 0)
|
||||
SetScreenColor(wDefColor, FALSE);
|
||||
ConSetScreenColor(wDefColor, TRUE);
|
||||
#endif
|
||||
|
||||
if (!*ptr)
|
||||
|
|
|
@ -143,7 +143,6 @@ VOID PrintCommandList (VOID);
|
|||
LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
|
||||
|
||||
/* Prototypes for COLOR.C */
|
||||
BOOL SetScreenColor(WORD wColor, BOOL bNoFill);
|
||||
INT CommandColor(LPTSTR);
|
||||
|
||||
VOID ConInDummy (VOID);
|
||||
|
@ -179,6 +178,19 @@ VOID ConOutResPrintf (UINT resID, ...);
|
|||
VOID ConErrResPrintf (UINT resID, ...);
|
||||
VOID ConOutResPaging(BOOL NewPage, UINT resID);
|
||||
|
||||
#ifdef INCLUDE_CMD_BEEP
|
||||
VOID ConRingBell(HANDLE hOutput);
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_CLS
|
||||
VOID ConClearScreen(HANDLE hOutput);
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_COLOR
|
||||
BOOL ConSetScreenColor(WORD wColor, BOOL bFill);
|
||||
#endif
|
||||
|
||||
|
||||
/* Prototypes for COPY.C */
|
||||
INT cmd_copy (LPTSTR);
|
||||
|
||||
|
|
|
@ -24,36 +24,6 @@
|
|||
|
||||
#ifdef INCLUDE_CMD_COLOR
|
||||
|
||||
BOOL SetScreenColor(WORD wColor, BOOL bNoFill)
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
|
||||
/* Foreground and Background colors can't be the same */
|
||||
if ((wColor & 0x0F) == (wColor & 0xF0) >> 4)
|
||||
return FALSE;
|
||||
|
||||
/* Fill the whole background if needed */
|
||||
if (bNoFill != TRUE)
|
||||
{
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute(hConsole,
|
||||
wColor & 0x00FF,
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos,
|
||||
&dwWritten);
|
||||
}
|
||||
|
||||
/* Set the text attribute */
|
||||
SetConsoleTextAttribute(hConsole, wColor & 0x00FF);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* color
|
||||
*
|
||||
|
@ -76,7 +46,7 @@ INT CommandColor(LPTSTR rest)
|
|||
/* No parameter: Set the default colors */
|
||||
if (rest[0] == _T('\0'))
|
||||
{
|
||||
SetScreenColor(wDefColor, FALSE);
|
||||
ConSetScreenColor(wDefColor, TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -117,7 +87,7 @@ INT CommandColor(LPTSTR rest)
|
|||
* Set the chosen color. Use also the following advanced flag:
|
||||
* /-F to avoid changing already buffered foreground/background.
|
||||
*/
|
||||
if (SetScreenColor(wColor, (_tcsstr(rest, _T("/-F")) || _tcsstr(rest, _T("/-f")))) == FALSE)
|
||||
if (ConSetScreenColor(wColor, !_tcsstr(rest, _T("/-F")) && !_tcsstr(rest, _T("/-f"))) == FALSE)
|
||||
{
|
||||
/* Failed because foreground and background colors were the same */
|
||||
ConErrResPuts(STRING_COLOR_ERROR1);
|
||||
|
|
|
@ -566,4 +566,79 @@ VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
|
|||
if (maxy) *maxy = csbi.dwSize.Y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef INCLUDE_CMD_BEEP
|
||||
VOID ConRingBell(HANDLE hOutput)
|
||||
{
|
||||
#if 0
|
||||
/* Emit an error beep sound */
|
||||
if (IsConsoleHandle(hOutput))
|
||||
Beep(800, 200);
|
||||
else if (IsTTYHandle(hOutput))
|
||||
ConOutPuts(_T("\a")); // BEL character 0x07
|
||||
else
|
||||
#endif
|
||||
MessageBeep(-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_CLS
|
||||
VOID ConClearScreen(HANDLE hOutput)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
DWORD dwWritten;
|
||||
|
||||
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||
{
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute(hOutput, csbi.wAttributes,
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos, &dwWritten);
|
||||
FillConsoleOutputCharacter(hOutput, _T(' '),
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos, &dwWritten);
|
||||
SetConsoleCursorPosition(hOutput, coPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConOutChar(_T('\f'));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_COLOR
|
||||
BOOL ConSetScreenColor(WORD wColor, BOOL bFill)
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD dwWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
|
||||
/* Foreground and Background colors can't be the same */
|
||||
if ((wColor & 0x0F) == (wColor & 0xF0) >> 4)
|
||||
return FALSE;
|
||||
|
||||
/* Fill the whole background if needed */
|
||||
if (bFill)
|
||||
{
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute(hConsole,
|
||||
wColor & 0x00FF,
|
||||
csbi.dwSize.X * csbi.dwSize.Y,
|
||||
coPos,
|
||||
&dwWritten);
|
||||
}
|
||||
|
||||
/* Set the text attribute */
|
||||
SetConsoleTextAttribute(hConsole, wColor & 0x00FF);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Reference in a new issue